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
Show file tree
Hide file tree
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): move button design to its own directive
  • Loading branch information
bence444 committed Dec 19, 2024
commit 1bd73bdb08d9209d192e811cef6df0b9d20865cf
31 changes: 23 additions & 8 deletions libs/flowbite-angular/core/flowbite.theme.init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ import {
NavbarToggleThemeService,
} from 'flowbite-angular/navbar';
import {
FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN,
FLOWBITE_PAGINATION_THEME_TOKEN,
paginationButtonDefaultValueProvider,
paginationButtonTheme,
PaginationButtonThemeService,
paginationDefaultValueProvider,
paginationTheme,
PaginationThemeService,
} from 'flowbite-angular/pagination';
Expand Down Expand Up @@ -248,10 +253,6 @@ export function initFlowbite(): EnvironmentProviders {
provide: NavbarBrandThemeService,
useClass: NavbarBrandThemeService,
},
{
provide: PaginationThemeService,
useClass: PaginationThemeService,
},
{
provide: NavbarContentThemeService,
useClass: NavbarContentThemeService,
Expand All @@ -272,6 +273,14 @@ export function initFlowbite(): EnvironmentProviders {
provide: NavbarThemeService,
useClass: NavbarThemeService,
},
{
provide: PaginationThemeService,
useClass: PaginationThemeService,
},
{
provide: PaginationButtonThemeService,
useClass: PaginationButtonThemeService,
},
{
provide: ScrollTopThemeService,
useClass: ScrollTopThemeService,
Expand Down Expand Up @@ -384,10 +393,6 @@ export function initFlowbite(): EnvironmentProviders {
provide: FLOWBITE_NAVBAR_CONTENT_THEME_TOKEN,
useValue: navbarContentTheme,
},
{
provide: FLOWBITE_PAGINATION_THEME_TOKEN,
useValue: paginationTheme,
},
{
provide: FLOWBITE_NAVBAR_ITEM_THEME_TOKEN,
useValue: navbarItemTheme,
Expand All @@ -404,6 +409,14 @@ export function initFlowbite(): EnvironmentProviders {
provide: FLOWBITE_NAVBAR_THEME_TOKEN,
useValue: navbarTheme,
},
{
provide: FLOWBITE_PAGINATION_THEME_TOKEN,
useValue: paginationTheme,
},
{
provide: FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN,
useValue: paginationButtonTheme,
},
{
provide: FLOWBITE_SCROLL_TOP_THEME_TOKEN,
useValue: scrollTopTheme,
Expand Down Expand Up @@ -460,6 +473,8 @@ export function initFlowbite(): EnvironmentProviders {
navbarIconButtonDefaultValueProvider,
navbarContentDefaultValueProvider,
navbarBrandDefaultThemeProvider,
paginationDefaultValueProvider,
paginationButtonDefaultValueProvider,
scrollTopDefaultValueProvider,
sidebarDefaultValueProvider,
sidebarToggleDefaultValueProvider,
Expand Down
21 changes: 20 additions & 1 deletion libs/flowbite-angular/pagination/index.ts
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';
44 changes: 44 additions & 0 deletions libs/flowbite-angular/pagination/pagination-button.directive.ts
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> {
Copy link
Contributor

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.

 @Directive({
   standalone: true,
   selector: 'button[flowbitePaginationButton]',
+  host: {
+    'role': 'button',
+    '[attr.aria-current]': 'active() ? "page" : null',
+    '[attr.aria-label]': '"Page " + label',
+  }
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Directive({
standalone: true,
selector: 'button[flowbitePaginationButton]',
})
export class PaginationButtonDirective extends BaseComponent<PaginationButtonClass> {
@Directive({
standalone: true,
selector: 'button[flowbitePaginationButton]',
host: {
'role': 'button',
'[attr.aria-current]': 'active() ? "page" : null',
'[attr.aria-label]': '"Page " + label',
}
})
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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public readonly baseTheme = inject(FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN);
public readonly baseTheme = inject(FLOWBITE_PAGINATION_BUTTON_THEME_TOKEN, {
optional: true
}) ?? {};


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;
}
}
38 changes: 38 additions & 0 deletions libs/flowbite-angular/pagination/pagination-button.theme.ts
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;
Loading