Skip to content

Commit e05014a

Browse files
committed
feat(pagination): add disable feature and improve doc
1 parent f85620c commit e05014a

File tree

8 files changed

+91
-18
lines changed

8 files changed

+91
-18
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import CustomButtonLabels from '@/apps/website/src/routes/docs/headless/(components)/pagination/examples/customButtonLabels';
2-
import HidePrevNextButtons from '@/apps/website/src/routes/docs/headless/(components)/pagination/examples/hidePrevNextButtons';
3-
import Styling from '@/apps/website/src/routes/docs/headless/(components)/pagination/examples/styling';
1+
import CustomArrows from './examples/custom-arrows';
2+
import CustomButtonLabels from './examples/custom-button-labels';
3+
import Disabled from './examples/disabled';
4+
import HidePrevNextButtons from './examples/hide-prev-next-buttons';
5+
import Styling from './examples/styling';
46
import { JSXNode, component$ } from '@builder.io/qwik';
57
import { PreviewCodeExampleTabs } from '../../../_components/preview-code-example/preview-code-example-tabs';
68

79
import Basic from './examples/basic';
810
import Interactive from './examples/interactive';
911
import basicCode from './examples/basic?raw';
1012
import interactiveCode from './examples/interactive?raw';
11-
import hidePrevNextButtonsCode from './examples/hidePrevNextButtons?raw';
12-
import customButtonLabelsCode from './examples/customButtonLabels?raw';
13+
import hidePrevNextButtonsCode from './examples/hide-prev-next-buttons?raw';
14+
import customButtonLabelsCode from './examples/custom-button-labels?raw';
1315
import stylingCode from './examples/styling?raw';
16+
import customArrowsCode from './examples/custom-arrows?raw';
17+
import disabledCode from './examples/disabled?raw';
1418

1519
export type Example = {
1620
component: JSXNode;
@@ -39,6 +43,14 @@ export const examples: Record<string, Example> = {
3943
component: <Styling />,
4044
code: stylingCode,
4145
},
46+
customArrows: {
47+
component: <CustomArrows />,
48+
code: customArrowsCode,
49+
},
50+
disabled: {
51+
component: <Disabled />,
52+
code: disabledCode,
53+
},
4254
};
4355

4456
export type ShowExampleProps = {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { component$, useSignal } from '@builder.io/qwik';
2+
import { Pagination } from '@qwik-ui/headless';
3+
4+
export default component$(() => {
5+
const selectedPage = useSignal(5);
6+
const totalPages = useSignal(20);
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+
>
17+
<span q:slot="prefix"> 👈 </span>
18+
<span q:slot="suffix"> 👉 </span>
19+
</Pagination>
20+
</div>
21+
);
22+
});
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+
disabled
14+
onPageChange$={(page) => {
15+
selectedPage.value = page;
16+
}}
17+
/>
18+
</div>
19+
);
20+
});

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Pagination } from '@qwik-ui/headless';
33
import { Toggle } from '@qwik-ui/tailwind';
44

55
export default component$(() => {
6-
const selectedPage = useSignal(1);
6+
const selectedPage = useSignal(5);
77
const totalPages = useSignal(20);
88

99
const hideNextButton = useSignal(false);
@@ -25,10 +25,9 @@ export default component$(() => {
2525
hidePrevButton={hidePrevButton.value}
2626
hideNextButton={hideNextButton.value}
2727
gap={'10px'}
28-
>
29-
<span q:slot="prefix">👈</span>
30-
<span q:slot="suffix">👉</span>
31-
</Pagination>
28+
/>
29+
30+
<hr />
3231

3332
<div
3433
class="flex flex-col items-stretch gap-2"

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import testImage from '../../../../../../public/images/test-image.png'
3434
<ShowExample example="interactive" />
3535

3636

37-
### 🎨 Properties
3837

3938

4039
## API
@@ -80,6 +79,11 @@ Here are the notable properties for this component:
8079
type: 'boolean',
8180
description: `hide the next button`,
8281
},
82+
{
83+
name: 'disabled',
84+
type: 'boolean',
85+
description: `disable mouse events`,
86+
},
8387
{
8488
name: 'customArrowTexts',
8589
type: 'ArrowLabels',
@@ -123,12 +127,23 @@ Here are the notable properties for this component:
123127

124128
<ShowExample example="styling" />
125129

130+
## Custom Button Labels
131+
132+
<ShowExample example="customButtonLabels" />
133+
134+
135+
## Custom Arrows
136+
137+
<ShowExample example="customArrows" />
138+
139+
126140
## Hide Next/Prev Buttons
127141

128142
<ShowExample example="hidePrevNextButtons" />
129143

130-
## Custom Button Labels
131144

132-
<ShowExample example="customButtonLabels" />
145+
## Disabled
146+
147+
<ShowExample example="disabled" />
133148

134149

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface PaginationProps {
2222
boundaryCount?: number;
2323
hidePrevButton?: boolean;
2424
hideNextButton?: boolean;
25+
disabled?: boolean;
2526
customArrowTexts?: ArrowLabels;
2627

2728
// styling
@@ -38,10 +39,9 @@ export const Pagination = component$<PaginationProps>((props) => {
3839
totalPages,
3940
onPageChange$,
4041
// configuration
41-
siblingCount = 1,
42-
boundaryCount = 1,
4342
hidePrevButton = false,
4443
hideNextButton = false,
44+
disabled = false,
4545
customArrowTexts: {
4646
previous: previousButtonLabel = 'PREV',
4747
next: nextButtonLabel = 'NEXT',
@@ -69,8 +69,8 @@ export const Pagination = component$<PaginationProps>((props) => {
6969
visibleItems.value = usePagination(
7070
props.totalPages,
7171
props.selectedPage,
72-
props.siblingCount,
73-
props.boundaryCount,
72+
props.siblingCount || 1,
73+
props.boundaryCount || 1,
7474
);
7575
});
7676

@@ -80,7 +80,12 @@ export const Pagination = component$<PaginationProps>((props) => {
8080
aria-label="pagination"
8181
data-testid="pagination"
8282
class={_class}
83-
style={{ display: 'flex', alignItems: 'center', gap: gap }}
83+
style={{
84+
display: 'flex',
85+
alignItems: 'center',
86+
gap,
87+
pointerEvents: disabled ? 'none' : 'inherit',
88+
}}
8489
>
8590
{/* Prev Button */}
8691
{isPrevButtonVisible() && (

0 commit comments

Comments
 (0)