-
Notifications
You must be signed in to change notification settings - Fork 47
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
Changes from 1 commit
18761f3
e6482df
cc20b83
6d48101
9f2ca65
1bd73bd
6a77a41
b2c05d5
a43f5cb
1aa9da0
cbaf247
620f320
2c083bf
ea541d2
a47e774
1ceabbe
c92b724
15376cb
523363e
3edf1c4
e524102
cb31e76
338e5f3
970b79d
b914355
c983fca
434bfa4
783c3ed
0ec0dfa
87b1887
021058b
3947513
bd238c4
e8860f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
export { PaginationComponent } from './pagination.component'; | ||
export { | ||
PaginationComponent, | ||
paginationDefaultValueProvider, | ||
FLOWBITE_PAGINATION_CUSTOM_STYLE_DEFAULT_VALUE, | ||
} from './pagination.component'; | ||
export type { PaginationProperties, PaginationClass, PaginationTheme } from './pagination.theme'; | ||
export { paginationTheme } from './pagination.theme'; | ||
export { | ||
PaginationThemeService, | ||
FLOWBITE_PAGINATION_THEME_TOKEN, | ||
} from './pagination.theme.service'; | ||
|
||
export { | ||
paginationButtonDefaultValueProvider, | ||
FLOWBITE_PAGINATION_BUTTON_CUSTOM_STYLE_DEFAULT_VALUE, | ||
} from './pagination-button.directive'; | ||
export type { | ||
PaginationButtonProperties, | ||
PaginationButtonClass, | ||
PaginationButtonTheme, | ||
} from './pagination-button.theme'; | ||
export { paginationButtonTheme } from './pagination-button.theme'; | ||
export { | ||
PaginationButtonThemeService, | ||
FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN, | ||
} from './pagination-button.theme.service'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { PaginationButtonClass, PaginationButtonTheme } from './pagination-button.theme'; | ||
import { PaginationButtonThemeService } from './pagination-button.theme.service'; | ||
|
||
import type { DeepPartial } from 'flowbite-angular'; | ||
import { BaseComponent, booleanToFlowbiteBoolean } from 'flowbite-angular'; | ||
|
||
import { | ||
Directive, | ||
inject, | ||
InjectionToken, | ||
input, | ||
makeEnvironmentProviders, | ||
model, | ||
} from '@angular/core'; | ||
|
||
export const FLOWBITE_PAGINATION_BUTTON_CUSTOM_STYLE_DEFAULT_VALUE = new InjectionToken< | ||
DeepPartial<PaginationButtonTheme> | ||
>('FLOWBITE_PAGINATION_BUTTON_CUSTOM_STYLE_DEFAULT_VALUE'); | ||
|
||
export const paginationButtonDefaultValueProvider = makeEnvironmentProviders([ | ||
{ | ||
provide: FLOWBITE_PAGINATION_BUTTON_CUSTOM_STYLE_DEFAULT_VALUE, | ||
useValue: {}, | ||
}, | ||
]); | ||
|
||
@Directive({ | ||
standalone: true, | ||
selector: 'button[flowbitePaginationButton]', | ||
}) | ||
export class PaginationButtonDirective extends BaseComponent<PaginationButtonClass> { | ||
public readonly themeService = inject(PaginationButtonThemeService); | ||
|
||
public readonly active = input(false); | ||
|
||
public customStyle = model(inject(FLOWBITE_PAGINATION_BUTTON_CUSTOM_STYLE_DEFAULT_VALUE)); | ||
|
||
public override fetchClass(): PaginationButtonClass { | ||
return this.themeService.getClasses({ | ||
active: booleanToFlowbiteBoolean(this.active()), | ||
customStyle: this.customStyle(), | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||||||
import type { | ||||||||||
PaginationButtonClass, | ||||||||||
PaginationButtonProperties, | ||||||||||
PaginationButtonTheme, | ||||||||||
} from './pagination-button.theme'; | ||||||||||
|
||||||||||
import type { FlowbiteThemeService } from 'flowbite-angular'; | ||||||||||
import { mergeTheme } from 'flowbite-angular/utils'; | ||||||||||
|
||||||||||
import { inject, Injectable, InjectionToken } from '@angular/core'; | ||||||||||
import { twMerge } from 'tailwind-merge'; | ||||||||||
|
||||||||||
/** | ||||||||||
* `InjectionToken` used to import `PaginationButtonTheme` value | ||||||||||
* | ||||||||||
* @example | ||||||||||
* ``` | ||||||||||
* var theme = inject(FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN) | ||||||||||
* ``` | ||||||||||
*/ | ||||||||||
export const FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN = new InjectionToken<PaginationButtonTheme>( | ||||||||||
'FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN' | ||||||||||
); | ||||||||||
|
||||||||||
@Injectable({ | ||||||||||
providedIn: 'root', | ||||||||||
}) | ||||||||||
export class PaginationButtonThemeService | ||||||||||
implements FlowbiteThemeService<PaginationButtonProperties> | ||||||||||
{ | ||||||||||
public readonly baseTheme = inject(FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add null check for injected theme The injected theme should be checked for null/undefined to prevent runtime errors. - public readonly baseTheme = inject(FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN);
+ public readonly baseTheme = inject(FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN, {
+ optional: true
+ }) ?? {}; 📝 Committable suggestion
Suggested change
|
||||||||||
|
||||||||||
public getClasses(properties: PaginationButtonProperties): PaginationButtonClass { | ||||||||||
const theme: PaginationButtonTheme = mergeTheme(this.baseTheme, properties.customStyle); | ||||||||||
|
||||||||||
const output: PaginationButtonClass = { | ||||||||||
rootClass: twMerge(theme.root.base, theme.root.active[properties.active]), | ||||||||||
}; | ||||||||||
|
||||||||||
return output; | ||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { DeepPartial, FlowbiteBoolean, FlowbiteClass } from 'flowbite-angular'; | ||
import { createTheme } from 'flowbite-angular/utils'; | ||
|
||
/** | ||
* Required properties for the class generation of `PaginationButtonDirective` | ||
*/ | ||
export interface PaginationButtonProperties { | ||
active: keyof FlowbiteBoolean; | ||
customStyle: DeepPartial<PaginationButtonTheme>; | ||
} | ||
|
||
/** | ||
* Theme definition for `PaginationButtonDirective` | ||
*/ | ||
export interface PaginationButtonTheme { | ||
root: { | ||
base: string; | ||
active: FlowbiteBoolean; | ||
}; | ||
} | ||
|
||
/** | ||
* Default theme value for `PaginationButtonDirective` | ||
*/ | ||
export const paginationButtonTheme: PaginationButtonTheme = createTheme({ | ||
root: { | ||
base: 'flex items-center justify-center px-3 h-8 ms-0 leading-tight text-gray-500 bg-white border border-e-0 border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white first:rounded-l-lg last:rounded-r-lg', | ||
active: { | ||
enabled: 'bg-red-500 dark:bg-red-700', | ||
disabled: '', | ||
}, | ||
}, | ||
}); | ||
|
||
/** | ||
* Generated class definition for `PaginationButtonDirective` | ||
*/ | ||
export type PaginationButtonClass = FlowbiteClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add ARIA attributes for accessibility
The pagination button should include appropriate ARIA attributes for better accessibility.
📝 Committable suggestion