Skip to content

Commit cf9e79e

Browse files
committed
feat(pagination): support custom labels
1 parent ee8b639 commit cf9e79e

File tree

5 files changed

+118
-14
lines changed

5 files changed

+118
-14
lines changed

apps/website/src/routes/docs/headless/(components)/pagination/examples.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import CustomButtonLabels from '@/apps/website/src/routes/docs/headless/(components)/pagination/examples/customButtonLabels';
12
import HidePrevNextButtons from '@/apps/website/src/routes/docs/headless/(components)/pagination/examples/hidePrevNextButtons';
23
import { JSXNode, component$ } from '@builder.io/qwik';
34
import { PreviewCodeExampleTabs } from '../../../_components/preview-code-example/preview-code-example-tabs';
@@ -7,6 +8,7 @@ import Interactive from './examples/interactive';
78
import basicCode from './examples/basic?raw';
89
import interactiveCode from './examples/interactive?raw';
910
import hidePrevNextButtonsCode from './examples/hidePrevNextButtons?raw';
11+
import customButtonLabelsCode from './examples/customButtonLabels?raw';
1012

1113
export type Example = {
1214
component: JSXNode;
@@ -27,6 +29,10 @@ export const examples: Record<string, Example> = {
2729
component: <HidePrevNextButtons />,
2830
code: hidePrevNextButtonsCode,
2931
},
32+
customButtonLabels: {
33+
component: <CustomButtonLabels />,
34+
code: customButtonLabelsCode,
35+
},
3036
};
3137

3238
export type ShowExampleProps = {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { component$, useSignal } from '@builder.io/qwik';
2+
import { Pagination } from '@qwik-ui/headless';
3+
4+
export default component$(() => {
5+
const selectedPage = useSignal(1);
6+
const totalPages = useSignal(10);
7+
8+
return (
9+
<div class="mt-4 flex flex-col gap-6">
10+
<Pagination
11+
selectedPage={selectedPage.value}
12+
totalPages={totalPages.value}
13+
onPageChange$={(page) => {
14+
selectedPage.value = page;
15+
}}
16+
customArrowTexts={{ previous: 'LEFT', next: 'RIGHT' }}
17+
/>
18+
</div>
19+
);
20+
});

apps/website/src/routes/docs/headless/(components)/pagination/examples/interactive.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Toggle } from '@qwik-ui/tailwind';
44

55
export default component$(() => {
66
const selectedPage = useSignal(1);
7-
const totalPages = useSignal(10);
7+
const totalPages = useSignal(20);
88

99
const hideNextButton = useSignal(false);
1010
const hidePrevButton = useSignal(false);

apps/website/src/routes/docs/headless/(components)/pagination/index.mdx

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
statusByComponent,
1212
ShowExample,
1313
BackdropCss,
14-
BuildingBlocksSnip,
1514
PageLoadSnip,
16-
AnimationSnip
15+
AnimationSnip,
16+
Basics
1717
} from './exports';
1818

1919
import testImage from '../../../../../../public/images/test-image.png'
@@ -22,14 +22,89 @@ import testImage from '../../../../../../public/images/test-image.png'
2222

2323
# Pagination
2424

25+
## ✨ Features
26+
27+
- Pagination ranges
28+
- Custom Arrows
29+
- Custom Button Labels
30+
- Support custom styles (default, selected and divider)
31+
2532
## Interactive Example
2633

2734
<ShowExample example="interactive" />
2835

36+
37+
### 🎨 Properties
38+
<AnatomyTable
39+
propDescriptors={[
40+
{
41+
name: 'selectedPage',
42+
description: 'Current Page Index (start from 1)',
43+
},
44+
{
45+
name: 'totalPages',
46+
description: 'The total of available pages',
47+
},
48+
{
49+
name: 'onPageChange$',
50+
description: `Emitted when a button is clicked`,
51+
},
52+
{
53+
name: 'siblingCount',
54+
description: `set sibling items close to the selected value`,
55+
},
56+
{
57+
name: 'boundaryCount',
58+
description: `set adjacent items to the start and end page number`,
59+
},
60+
{
61+
name: 'hidePrevButton',
62+
description: `hide the previous button`,
63+
},
64+
{
65+
name: 'hideNextButton',
66+
description: `hide the next button`,
67+
},
68+
{
69+
name: 'customArrowTexts',
70+
description: `customize the PREVIOUS and NEXT button labels`,
71+
},
72+
{
73+
name: 'gap',
74+
description: `set the gap between items`,
75+
},
76+
{
77+
name: 'wrapperClass',
78+
description: `(TODO) allow to apply a custom class to the pagination wrapper `,
79+
},
80+
{
81+
name: 'defaultClass',
82+
description: `custom class for the pagination item`,
83+
},
84+
{
85+
name: 'selectedClass',
86+
description: `custom class for the selected item`,
87+
},
88+
{
89+
name: 'dividerClass',
90+
description: `custom class for the divider item`,
91+
}
92+
]}
93+
/>
94+
95+
96+
2997
## Basic Example
3098

3199
<ShowExample example="basic" />
32100

33101
## Hide Next/Prev Buttons
34102

35103
<ShowExample example="hidePrevNextButtons" />
104+
105+
## Custom Button Labels
106+
107+
<ShowExample example="customButtonLabels" />
108+
109+
110+
## TODO (Snippet di codice)

packages/kit-headless/src/components/pagination/pagination.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ import { component$, Slot, useSignal, useTask$, useVisibleTask$ } from '@builder
44

55
/**
66
* TODO
7-
* show / hide PREV / NEXT buttons
8-
* customArrowTexts: { previous: '...', next: '... }
97
* disabled: enable/disable paginator
10-
*
118
*/
12-
139
export interface PaginationProps {
1410
selectedPage: number;
1511
totalPages: number;
@@ -20,8 +16,9 @@ export interface PaginationProps {
2016
boundaryCount?: number;
2117
hidePrevButton?: boolean;
2218
hideNextButton?: boolean;
19+
customArrowTexts?: { previous: string; next: string };
2320

24-
// styles
21+
// styling
2522
class?: string;
2623
gap?: number | string;
2724
defaultClass?: string;
@@ -34,12 +31,16 @@ export const Pagination = component$<PaginationProps>(
3431
selectedPage,
3532
totalPages,
3633
onPageChange$,
37-
34+
// configuration
3835
siblingCount = 1,
3936
boundaryCount = 1,
4037
hidePrevButton = false,
4138
hideNextButton = false,
42-
39+
customArrowTexts: {
40+
previous: previousButtonLabel = 'PREV',
41+
next: nextButtonLabel = 'NEXT',
42+
} = {},
43+
// styling
4344
class: _class,
4445
gap = '10px',
4546
defaultClass,
@@ -65,7 +66,7 @@ export const Pagination = component$<PaginationProps>(
6566
data-testid="pagination"
6667
style={{ display: 'flex', alignItems: 'center', gap: gap }}
6768
>
68-
{/* PREV BUTTON */}
69+
{/* Prev Button */}
6970
{isPrevButtonVisible() && (
7071
<button
7172
type="button"
@@ -78,9 +79,11 @@ export const Pagination = component$<PaginationProps>(
7879
}}
7980
>
8081
<Slot name="prefix" />
81-
<span>PREV</span>
82+
<span>{previousButtonLabel}</span>
8283
</button>
8384
)}
85+
86+
{/* Button List */}
8487
{visibleItems.value.map((item: string | number, index: number) => {
8588
return (
8689
<span key={index}>
@@ -103,7 +106,7 @@ export const Pagination = component$<PaginationProps>(
103106
);
104107
})}
105108

106-
{/* NEXT BUTTON */}
109+
{/* Next Button */}
107110
{isNextButtonVisible() && (
108111
<button
109112
type="button"
@@ -115,7 +118,7 @@ export const Pagination = component$<PaginationProps>(
115118
}
116119
}}
117120
>
118-
<span>NEXT</span>
121+
<span>{nextButtonLabel}</span>
119122
<Slot name="suffix" />
120123
</button>
121124
)}

0 commit comments

Comments
 (0)