Skip to content

Commit b71af63

Browse files
committed
feat(component): add support for button custom labels
2 parents 8ad71bf + c1d742e commit b71af63

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

apps/website/src/routes/docs/tailwind/(components)/pagination/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export default component$(() => {
135135
boundaryCount={boundaryCount.value}
136136
activeClass="!bg-cyan-500"
137137
defaultClass="bg-cyan-200"
138+
labels={{ prev: '⬅️', next: '➡️', first: 'START', last: 'END' }}
138139
/>
139140
</div>
140141
</div>

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { Button as HeadlessButton } from '@qwik-ui/primitives';
77
*
88
* PROPS
99
* pageIndex: default pagination value
10-
* activeStyles: The styles of the active page button
11-
* normalStyles: The styles of the inactive page buttons
10+
* V activeStyles: The styles of the active page button
11+
* V normalStyles: The styles of the inactive page buttons
12+
* V customArrowTexts: { previous, next }
1213
* disabled: enable/disable paginator
1314
* color: primary | secondary
1415
* variant: outlined (show border without bg)
1516
* shape: rounded | square
1617
* size: 'sm' | 'md' | 'lg'
17-
* customArrowTexts: { previous, next }
1818
* paginationRange (see https://mui.com/material-ui/react-pagination/#pagination-ranges)
1919
*
2020
* EVENTS
@@ -38,8 +38,16 @@ export interface IRenderPaginationItemProps {
3838
key?: string | number;
3939
activeClass?: string;
4040
defaultClass?: string;
41+
labels?: TPaginationLabels;
4142
}
4243

44+
export type TPaginationLabels = {
45+
first?: string;
46+
last?: string;
47+
next?: string;
48+
prev?: string;
49+
};
50+
4351
export type TPaginationItemValue =
4452
| 'prev'
4553
| 'next'
@@ -79,11 +87,13 @@ export interface IGetPaginationItemsOptions {
7987
showLastButton?: boolean;
8088
activeClass?: string;
8189
defaultClass?: string;
90+
labels?: TPaginationLabels;
8291
}
8392

8493
export const getPaginationItems = (
8594
page: IGetPaginationItems['page'],
8695
count: IGetPaginationItems['count'],
96+
labels: TPaginationLabels | undefined,
8797
{
8898
boundaryCount = 1,
8999
siblingCount = 1,
@@ -185,9 +195,10 @@ export const Pagination = component$(
185195
pages,
186196
activeClass,
187197
defaultClass,
198+
labels,
188199
...rest
189200
}: IPaginationProps) => {
190-
const pagi = getPaginationItems(page, pages, rest);
201+
const pagi = getPaginationItems(page, pages, labels, rest);
191202

192203
const _onPaging$ = $((page: number) => {
193204
if (page < 1 || page > pages) return;
@@ -206,6 +217,7 @@ export const Pagination = component$(
206217
activeClass={activeClass}
207218
defaultClass={defaultClass}
208219
key={i}
220+
labels={labels}
209221
onClick$={() =>
210222
_onPaging$(
211223
(() => {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,23 @@ export const RenderPaginationItem = component$(
3232
value,
3333
activeClass,
3434
defaultClass,
35+
labels,
3536
}: IRenderPaginationItemProps) => {
37+
function getLabel() {
38+
switch (value) {
39+
case 'prev':
40+
return labels?.prev || '‹';
41+
case 'next':
42+
return labels?.next || '›';
43+
case 'first':
44+
return labels?.first || 'first';
45+
case 'last':
46+
return labels?.last || 'last';
47+
default:
48+
return value;
49+
}
50+
}
51+
3652
return (
3753
<Button
3854
onClick$={onClick$}
@@ -44,7 +60,7 @@ export const RenderPaginationItem = component$(
4460
circle
4561
class={ariaCurrent ? activeClass : defaultClass}
4662
>
47-
{value === 'prev' ? '‹' : value === 'next' ? '›' : value}
63+
{getLabel()}
4864
</Button>
4965
);
5066
}

0 commit comments

Comments
 (0)