Skip to content

Commit c083445

Browse files
committed
fix(pagination): remove useTask
1 parent 9b2d1da commit c083445

File tree

3 files changed

+14
-111
lines changed

3 files changed

+14
-111
lines changed

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

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -99,88 +99,6 @@ export default component$(() => {
9999
label="hidePrevButton"
100100
/>
101101
</div>
102-
103-
{/*
104-
105-
<Pagination
106-
activeClass="bg-red-500"
107-
pages={20} page={10} onPaging$={() => console.log('pippo')}/>
108-
109-
<h2>Interactive Demo</h2>
110-
111-
<Pagination
112-
pages={pages.value}
113-
page={page.value}
114-
onPaging$={(newValue: number) => {
115-
page.value = newValue;
116-
}}
117-
showFirstButton={showFirstButton.value}
118-
showLastButton={showLastButton.value}
119-
hideNextButton={hideNextButton.value}
120-
hidePrevButton={hidePrevButton.value}
121-
siblingCount={siblingCount.value}
122-
boundaryCount={boundaryCount.value}
123-
/>*/}
124-
{/*
125-
126-
<h2>Size</h2>
127-
<div class="flex flex-col gap-8">
128-
<Pagination pages={5} page={1} size="xs" />
129-
<Pagination pages={5} page={1} size="sm" />
130-
<Pagination pages={5} page={1} size="md" />
131-
<Pagination pages={5} page={1} size="lg" />
132-
</div>
133-
134-
<h2>Variants</h2>
135-
<div class="flex flex-col gap-8">
136-
<Pagination pages={5} page={1} />
137-
<Pagination pages={5} page={1} variant="primary" />
138-
<Pagination pages={5} page={1} variant="secondary" />
139-
<Pagination pages={5} page={1} variant="accent" />
140-
<Pagination pages={5} page={1} variant="disabled" />
141-
<Pagination pages={5} page={1} variant="success" />
142-
<Pagination pages={5} page={1} variant="error" />
143-
<Pagination pages={5} page={1} variant="info" />
144-
<Pagination pages={5} page={1} variant="link" />
145-
<Pagination pages={5} page={1} variant="warning" />
146-
</div>
147-
148-
<h2>Outline</h2>
149-
<div class="flex flex-col gap-8">
150-
<Pagination pages={5} page={1} outline />
151-
</div>
152-
153-
<h2>Square</h2>
154-
<div class="flex flex-col gap-8">
155-
<Pagination pages={5} page={1} square />
156-
</div>
157-
158-
<h2>Disabled</h2>
159-
<div class="flex flex-col gap-8">
160-
<Pagination pages={5} page={1} disabled={true} />
161-
</div>
162-
163-
<h2>Custom styles and labels</h2>
164-
165-
<div class="flex flex-col gap-8">
166-
<Pagination
167-
pages={pages.value}
168-
page={page.value}
169-
onPaging$={(newValue: number) => {
170-
page.value = newValue;
171-
}}
172-
showFirstButton={showFirstButton.value}
173-
showLastButton={showLastButton.value}
174-
hideNextButton={hideNextButton.value}
175-
hidePrevButton={hidePrevButton.value}
176-
siblingCount={siblingCount.value}
177-
boundaryCount={boundaryCount.value}
178-
activeClass="!bg-cyan-800"
179-
defaultClass="bg-cyan-500"
180-
labels={{ prev: '⬅️', next: '➡️', first: 'START', last: 'END' }}
181-
/>
182-
</div>
183-
*/}
184102
</div>
185103
);
186104
});

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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { usePagination } from './use-pagination';
22
import type { PropFunction } from '@builder.io/qwik';
3-
import { component$, Slot, useSignal, useTask$ } from '@builder.io/qwik';
4-
5-
/**
6-
* TODO
7-
* disabled: enable/disable paginator
8-
*/
3+
import { component$, Slot } from '@builder.io/qwik';
94

105
type ArrowLabels = {
116
previous: string;
@@ -39,6 +34,8 @@ export const Pagination = component$<PaginationProps>((props) => {
3934
totalPages,
4035
onPageChange$,
4136
// configuration
37+
siblingCount,
38+
boundaryCount,
4239
hidePrevButton = false,
4340
hideNextButton = false,
4441
disabled = false,
@@ -54,25 +51,15 @@ export const Pagination = component$<PaginationProps>((props) => {
5451
dividerClass,
5552
} = props;
5653

57-
const visibleItems = useSignal<(string | number)[]>([]);
5854
const isPrevButtonVisible = () => !hidePrevButton && selectedPage > 1;
5955
const isNextButtonVisible = () => !hideNextButton && selectedPage !== totalPages;
6056

61-
useTask$(({ track }) => {
62-
track(() => [
63-
props.selectedPage,
64-
props.totalPages,
65-
props.siblingCount,
66-
props.boundaryCount,
67-
]);
68-
69-
visibleItems.value = usePagination(
70-
props.totalPages,
71-
props.selectedPage,
72-
props.siblingCount || 1,
73-
props.boundaryCount || 1,
74-
);
75-
});
57+
const visibleItems = usePagination(
58+
totalPages,
59+
selectedPage,
60+
siblingCount || 1,
61+
boundaryCount || 1,
62+
);
7663

7764
return (
7865
<nav
@@ -105,7 +92,7 @@ export const Pagination = component$<PaginationProps>((props) => {
10592
)}
10693

10794
{/* Button List */}
108-
{visibleItems.value.map((item: string | number, index: number) => {
95+
{visibleItems.map((item: string | number, index: number) => {
10996
return (
11097
<span key={index}>
11198
{typeof item === 'string' ? (

packages/kit-headless/src/components/pagination/use-pagination.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// example: usePagination(20, 6, 1, 1);
2-
31
export function usePagination(
4-
count: number,
5-
defaultPage: number,
2+
totalPages: number,
3+
selectedPage: number,
64
siblingCount = 1,
75
boundaryCount = 1,
86
) {
9-
const pageCount = Math.min(count, Math.max(1, count));
10-
const page = Math.min(Math.max(1, defaultPage), pageCount);
7+
const pageCount = Math.min(totalPages, Math.max(1, totalPages));
8+
const page = Math.min(Math.max(1, selectedPage), pageCount);
119

1210
const range = (start: number, end: number) =>
1311
Array.from({ length: end - start + 1 }, (_, i) => start + i);

0 commit comments

Comments
 (0)