Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pagination): add new pagination component #106

Merged
merged 34 commits into from
Dec 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
18761f3
feat(pagination): implement basics based on flowbite (wip)
bence444 Dec 11, 2024
e6482df
feat(pagination): implement basics based on flowbite (wip)
bence444 Dec 11, 2024
cc20b83
feat(pagination): move button design to its own directive
bence444 Dec 12, 2024
6d48101
Merge branch 'pagination' of https://github.com/bence444/flowbite-ang…
bence444 Dec 12, 2024
9f2ca65
feat(pagination): implement basics based on flowbite (wip)
bence444 Dec 11, 2024
1bd73bd
feat(pagination): move button design to its own directive
bence444 Dec 12, 2024
6a77a41
feat(pagination): implement basics based on flowbite (wip)
bence444 Dec 11, 2024
b2c05d5
Merge branch 'pagination' of https://github.com/bence444/flowbite-ang…
bence444 Dec 19, 2024
a43f5cb
fix: merge conflict
bence444 Dec 19, 2024
1aa9da0
feat(pagination): add icons, style active button, jsdoc comments
bence444 Dec 19, 2024
cbaf247
docs(pagination): add NgDoc documentation
bence444 Dec 19, 2024
620f320
fix(pagination): remove duplicated provider registrations
bence444 Dec 19, 2024
2c083bf
fix(pagination): remove unused pageChange output
bence444 Dec 19, 2024
ea541d2
fix(pagination): fix demo component selector
bence444 Dec 19, 2024
a47e774
fix(pagination): correct first visible page
bence444 Dec 20, 2024
1ceabbe
feat(utils): add double chevron icon from `https://flowbite.com/icons/`
bence444 Dec 20, 2024
c92b724
feat(paginator): add customizable icons, size variables
bence444 Dec 20, 2024
15376cb
feat(pagination): add property providers
bence444 Dec 20, 2024
523363e
Merge branch 'main' into pagination
MGREMY Dec 28, 2024
3edf1c4
feat(pagination): remove directive & use flowbite-button
MGREMY Dec 29, 2024
e524102
Merge pull request #1 from MGREMY/pagination
bence444 Dec 30, 2024
cb31e76
chore(pagination): code style updates
bence444 Dec 30, 2024
338e5f3
chore(pagination): use `model` instead of `input`
bence444 Dec 30, 2024
970b79d
refactor(pagination): remove `nav` element, use root and rootClass
bence444 Dec 30, 2024
b914355
chore(pagination): code style
bence444 Dec 30, 2024
c983fca
feat(utils): add left/double left chevron icon
bence444 Dec 30, 2024
434bfa4
feat(pagination): use left sided icons instead of `rotate-180`
bence444 Dec 30, 2024
783c3ed
Merge branch 'main' into pagination
bence444 Dec 30, 2024
0ec0dfa
fix(pagination): place label before icon in next/last button
bence444 Dec 30, 2024
87b1887
refactor(pagination): update post update post comment
MGREMY Dec 30, 2024
021058b
refactor(pagination): fix doc attribute
MGREMY Dec 30, 2024
3947513
Merge pull request #2 from MGREMY/pagination
bence444 Dec 31, 2024
bd238c4
feat(pagination): possibility to use `totalPages` or `totalItems`
bence444 Dec 31, 2024
e8860f1
refactor(pagination): use `Array.from` instead of for loop
bence444 Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(pagination): possibility to use totalPages or totalItems
  • Loading branch information
bence444 committed Dec 31, 2024
commit bd238c4e6917396570141480e259888d26c62c8c
32 changes: 27 additions & 5 deletions libs/flowbite-angular/pagination/pagination.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,12 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {

/**
* Value of the total items
*
* @required
*/
public readonly totalItems = model.required<number>();
public readonly totalItems = model<number>();
/**
* Value of the total pages
*/
public readonly totalPages = model<number>();
/**
* Value of the current page
*
Expand Down Expand Up @@ -406,10 +408,26 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {
});

/**
* Value of the maximum pages calculated from `totalItems`
* Value of the maximum pages. If `totalPages` is given, it will be
* equal to that; otherwise, it is calculated from `totalItems`.
*/
public readonly maxPages = computed(() => {
return Math.max(Math.ceil(this.totalItems() / this.pageSize()), 1);
if (this.totalPages() !== undefined) {
/**
* Note that if we return just `this.totalPages()`, the type of the computed
* will be `Signal<number | undefined>`, even though there is a check.
* So instead of that, we return `this.totalPages()!` to ensure
* the type is always `Signal<number>`.
*/
return this.totalPages()!;
}

/**
* The same applies here, except there is no need to check for undefined,
* because if `totalPages` is undefined, `totalItems` must have
* a valid number value. We check it in the init function.
*/
return Math.max(Math.ceil(this.totalItems()! / this.pageSize()), 1);
});

/**
Expand Down Expand Up @@ -455,6 +473,10 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {
}

public override init(): void {
if (this.totalPages() === undefined && this.totalItems() === undefined) {
throw new Error('Either `totalPages` or `totalItems` must have a value');
}

this.iconRegistry.addRawSvgIconInNamepsace(
'flowbite-angular',
'chevron-left',
Expand Down