@@ -31,6 +31,10 @@ import {
3131} from '@angular/core' ;
3232import { DomSanitizer } from '@angular/platform-browser' ;
3333
34+ export const FLOWBITE_PAGINATION_CURRENT_PAGE_DEFAULT_VALUE = new InjectionToken < number > (
35+ 'FLOWBITE_PAGINATION_CURRENT_PAGE_DEFAULT_VALUE'
36+ ) ;
37+
3438export const FLOWBITE_PAGINATION_CUSTOM_STYLE_DEFAULT_VALUE = new InjectionToken <
3539 DeepPartial < PaginationTheme >
3640> ( 'FLOWBITE_PAGINATION_CUSTOM_STYLE_DEFAULT_VALUE' ) ;
@@ -59,17 +63,17 @@ export const FLOWBITE_PAGINATION_PAGE_SIZE_DEFAULT_VALUE = new InjectionToken<nu
5963 'FLOWBITE_PAGINATION_PAGE_SIZE_DEFAULT_VALUE'
6064) ;
6165
62- export const FLOWBITE_PAGINATION_FIRSTLAST_DEFAULT_VALUE = new InjectionToken < boolean > (
63- 'FLOWBITE_PAGINATION_FIRSTLAST_DEFAULT_VALUE '
66+ export const FLOWBITE_PAGINATION_HAS_FIRST_LAST_DEFAULT_VALUE = new InjectionToken < boolean > (
67+ 'FLOWBITE_PAGINATION_HAS_FIRST_LAST_DEFAULT_VALUE '
6468) ;
6569
66- export const FLOWBITE_PAGINATION_PREVNEXT_DEFAULT_VALUE = new InjectionToken < boolean > (
67- 'FLOWBITE_PAGINATION_PREVNEXT_DEFAULT_VALUE '
70+ export const FLOWBITE_PAGINATION_HAS_PREV_NEXT_DEFAULT_VALUE = new InjectionToken < boolean > (
71+ 'FLOWBITE_PAGINATION_HAS_PREV_NEXT_DEFAULT_VALUE '
6872) ;
6973
70- export const FLOWBITE_PAGINATION_NAVIGATION_DEFAULT_VALUE = new InjectionToken <
74+ export const FLOWBITE_PAGINATION_NAVIGATION_MODE_DEFAULT_VALUE = new InjectionToken <
7175 keyof PaginationNavigation
72- > ( 'FLOWBITE_PAGINATION_NAVIGATION_DEFAULT_VALUE ' ) ;
76+ > ( 'FLOWBITE_PAGINATION_NAVIGATION_MODE_DEFAULT_VALUE ' ) ;
7377
7478export const FLOWBITE_PAGINATION_SIZE_DEFAULT_VALUE = new InjectionToken < keyof PaginationSizes > (
7579 'FLOWBITE_PAGINATION_SIZE_DEFAULT_VALUE'
@@ -80,6 +84,10 @@ export const FLOWBITE_PAGINATION_BUTTON_PROPERTIES_DEFAULT_VALUE = new Injection
8084> ( 'FLOWBITE_PAGINATION_BUTTON_PROPERTIES_DEFAULT_VALUE' ) ;
8185
8286export const paginationDefaultValueProvider = makeEnvironmentProviders ( [
87+ {
88+ provide : FLOWBITE_PAGINATION_CURRENT_PAGE_DEFAULT_VALUE ,
89+ useValue : 1 ,
90+ } ,
8391 {
8492 provide : FLOWBITE_PAGINATION_CUSTOM_STYLE_DEFAULT_VALUE ,
8593 useValue : { } ,
@@ -109,15 +117,15 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
109117 useValue : 25 ,
110118 } ,
111119 {
112- provide : FLOWBITE_PAGINATION_FIRSTLAST_DEFAULT_VALUE ,
120+ provide : FLOWBITE_PAGINATION_HAS_FIRST_LAST_DEFAULT_VALUE ,
113121 useValue : true ,
114122 } ,
115123 {
116- provide : FLOWBITE_PAGINATION_PREVNEXT_DEFAULT_VALUE ,
124+ provide : FLOWBITE_PAGINATION_HAS_PREV_NEXT_DEFAULT_VALUE ,
117125 useValue : true ,
118126 } ,
119127 {
120- provide : FLOWBITE_PAGINATION_NAVIGATION_DEFAULT_VALUE ,
128+ provide : FLOWBITE_PAGINATION_NAVIGATION_MODE_DEFAULT_VALUE ,
121129 useValue : 'icon' ,
122130 } ,
123131 {
@@ -150,7 +158,7 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
150158 standalone : true ,
151159 imports : [ IconComponent , NgTemplateOutlet , ButtonComponent ] ,
152160 template : `
153- @if (firstLast ()) {
161+ @if (hasFirstLast ()) {
154162 <flowbite-button
155163 type="button"
156164 data-active="false"
@@ -159,7 +167,7 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
159167 [fill]="buttonProperties().fill!"
160168 [size]="size()"
161169 [customStyle]="buttonProperties().customStyle!">
162- @if (['icon', 'both'].includes(navigation ())) {
170+ @if (['icon', 'both'].includes(navigationMode ())) {
163171 @if (firstIcon()) {
164172 <ng-container [ngTemplateOutlet]="firstIcon()!" />
165173 } @else {
@@ -168,13 +176,13 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
168176 [class]="contentClasses().iconClass" />
169177 }
170178 }
171- @if (['text', 'both'].includes(navigation ())) {
179+ @if (['text', 'both'].includes(navigationMode ())) {
172180 <span>First</span>
173181 }
174182 </flowbite-button>
175183 }
176184
177- @if (prevNext ()) {
185+ @if (hasPrevNext ()) {
178186 <flowbite-button
179187 type="button"
180188 data-active="false"
@@ -183,7 +191,7 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
183191 [fill]="buttonProperties().fill!"
184192 [size]="size()"
185193 [customStyle]="buttonProperties().customStyle!">
186- @if (['icon', 'both'].includes(navigation ())) {
194+ @if (['icon', 'both'].includes(navigationMode ())) {
187195 @if (previousIcon()) {
188196 <ng-container [ngTemplateOutlet]="previousIcon()!" />
189197 } @else {
@@ -192,7 +200,7 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
192200 [class]="contentClasses().iconClass" />
193201 }
194202 }
195- @if (['text', 'both'].includes(navigation ())) {
203+ @if (['text', 'both'].includes(navigationMode ())) {
196204 <span>Previous</span>
197205 }
198206 </flowbite-button>
@@ -202,7 +210,7 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
202210 <flowbite-button
203211 type="button"
204212 [attr.data-active]="page === currentPage()"
205- (click)="changePage (page)"
213+ (click)="goToPage (page)"
206214 [color]="buttonProperties().color!"
207215 [fill]="buttonProperties().fill!"
208216 [size]="size()"
@@ -211,7 +219,7 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
211219 </flowbite-button>
212220 }
213221
214- @if (prevNext ()) {
222+ @if (hasPrevNext ()) {
215223 <flowbite-button
216224 type="button"
217225 data-active="false"
@@ -220,10 +228,10 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
220228 [fill]="buttonProperties().fill!"
221229 [size]="size()"
222230 [customStyle]="buttonProperties().customStyle!">
223- @if (['text', 'both'].includes(navigation ())) {
231+ @if (['text', 'both'].includes(navigationMode ())) {
224232 <span>Next</span>
225233 }
226- @if (['icon', 'both'].includes(navigation ())) {
234+ @if (['icon', 'both'].includes(navigationMode ())) {
227235 @if (lastIcon()) {
228236 <ng-container [ngTemplateOutlet]="lastIcon()!" />
229237 } @else {
@@ -235,7 +243,7 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
235243 </flowbite-button>
236244 }
237245
238- @if (firstLast ()) {
246+ @if (hasFirstLast ()) {
239247 <flowbite-button
240248 type="button"
241249 data-active="false"
@@ -244,10 +252,10 @@ export const paginationDefaultValueProvider = makeEnvironmentProviders([
244252 [fill]="buttonProperties().fill!"
245253 [size]="size()"
246254 [customStyle]="buttonProperties().customStyle!">
247- @if (['text', 'both'].includes(navigation ())) {
255+ @if (['text', 'both'].includes(navigationMode ())) {
248256 <span>Last</span>
249257 }
250- @if (['icon', 'both'].includes(navigation ())) {
258+ @if (['icon', 'both'].includes(navigationMode ())) {
251259 @if (lastIcon()) {
252260 <ng-container [ngTemplateOutlet]="lastIcon()!" />
253261 } @else {
@@ -277,17 +285,17 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {
277285 public readonly domSanitizer = inject ( DomSanitizer ) ;
278286
279287 /**
280- * Value of the current page
288+ * Value of the total items
281289 *
282290 * @required
283291 */
284- public readonly currentPage = model . required < number > ( ) ;
292+ public readonly totalItems = model . required < number > ( ) ;
285293 /**
286- * Value of the total items
294+ * Value of the current page
287295 *
288- * @required
296+ * @default 1
289297 */
290- public readonly totalItems = model . required < number > ( ) ;
298+ public readonly currentPage = model ( inject ( FLOWBITE_PAGINATION_CURRENT_PAGE_DEFAULT_VALUE ) ) ;
291299 /**
292300 * Value of how many tabs are displayed
293301 *
@@ -305,19 +313,19 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {
305313 *
306314 * @default true
307315 */
308- public readonly prevNext = model ( inject ( FLOWBITE_PAGINATION_PREVNEXT_DEFAULT_VALUE ) ) ;
316+ public readonly hasPrevNext = model ( inject ( FLOWBITE_PAGINATION_HAS_PREV_NEXT_DEFAULT_VALUE ) ) ;
309317 /**
310318 * Whether to show or hide first and last buttons
311319 *
312320 * @default true
313321 */
314- public readonly firstLast = model ( inject ( FLOWBITE_PAGINATION_FIRSTLAST_DEFAULT_VALUE ) ) ;
322+ public readonly hasFirstLast = model ( inject ( FLOWBITE_PAGINATION_HAS_FIRST_LAST_DEFAULT_VALUE ) ) ;
315323 /**
316324 * Value of the navigation button's type
317325 *
318326 * @default icon
319327 */
320- public readonly navigation = model ( inject ( FLOWBITE_PAGINATION_NAVIGATION_DEFAULT_VALUE ) ) ;
328+ public readonly navigationMode = model ( inject ( FLOWBITE_PAGINATION_NAVIGATION_MODE_DEFAULT_VALUE ) ) ;
321329 /**
322330 * Value of the component's size
323331 *
@@ -474,43 +482,41 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {
474482 //#endregion
475483
476484 /**
477- * Sets the value of the `currentPage`
485+ * Sets the value of the `currentPage` if it's between 1 and `maxPages`
478486 * @param page number of the active page
479487 */
480- public changePage ( page : number ) {
481- if ( this . visibleCurrentPage ( ) === page ) return ;
488+ public goToPage ( page : number ) {
489+ if ( page < 1 || page > this . maxPages ( ) ) return ;
482490 this . currentPage . set ( page ) ;
483491 }
484492
485493 /**
486- * Decreases the value of `currentPage` if it's bigger than 1
494+ * Decreases the value of `currentPage` if it's more than 1
487495 */
488496 public goToPreviousPage ( ) {
489- if ( this . visibleCurrentPage ( ) == = 1 ) return ;
497+ if ( this . visibleCurrentPage ( ) < = 1 ) return ;
490498 this . currentPage . update ( ( value ) => value - 1 ) ;
491499 }
492500
493501 /**
494- * Increases the value of `currentPage` if it's smaller than `maxPages`
502+ * Increases the value of `currentPage` if it's less than `maxPages`
495503 */
496504 public goToNextPage ( ) {
497- if ( this . visibleCurrentPage ( ) == = this . maxPages ( ) ) return ;
505+ if ( this . visibleCurrentPage ( ) > = this . maxPages ( ) ) return ;
498506 this . currentPage . update ( ( value ) => value + 1 ) ;
499507 }
500508
501509 /**
502510 * Sets the value of `currentPage` to 1
503511 */
504512 public goToFirstPage ( ) {
505- if ( this . currentPage ( ) === 1 ) return ;
506513 this . currentPage . set ( 1 ) ;
507514 }
508515
509516 /**
510517 * Sets the value of `currentPage` equal to `maxPages`
511518 */
512519 public goToLastPage ( ) {
513- if ( this . currentPage ( ) === this . maxPages ( ) ) return ;
514520 this . currentPage . set ( this . maxPages ( ) ) ;
515521 }
516522}
0 commit comments