|
1 | 1 | import React from "react"; |
2 | | -import styled from "styled-components"; |
3 | 2 | import usePagination from "../../hooks/pagination/use-pagination"; |
4 | 3 | import Arrow from "../../assets/svgs/arrows/light-left.svg"; |
5 | | -import { borderBox, button, svg } from "../../styles/common-style"; |
6 | | - |
7 | | -const Wrapper = styled.div` |
8 | | - ${borderBox} |
9 | | - display: flex; |
10 | | - align-items: center; |
11 | | - justify-content: center; |
12 | | -`; |
13 | | - |
14 | | -const PageButton = styled.button<{ selected?: boolean }>` |
15 | | - ${button} |
16 | | - height: 32px; |
17 | | - width: 32px; |
18 | | - margin: 4px; |
19 | | - background: ${(props) => |
20 | | - props.selected |
21 | | - ? props.theme.klerosUIComponentsLightBlue |
22 | | - : props.theme.klerosUIComponentsWhiteBackground}; |
23 | | - border: 1px solid |
24 | | - ${(props) => |
25 | | - props.selected |
26 | | - ? props.theme.klerosUIComponentsPrimaryBlue |
27 | | - : props.theme.klerosUIComponentsStroke}; |
28 | | - border-radius: 3px; |
29 | | - display: flex; |
30 | | - align-items: center; |
31 | | - justify-content: center; |
32 | | -
|
33 | | - font-size: 14px; |
34 | | - color: ${(props) => |
35 | | - props.selected |
36 | | - ? props.theme.klerosUIComponentsPrimaryBlue |
37 | | - : props.theme.klerosUIComponentsPrimaryText}; |
38 | | -
|
39 | | - :hover:enabled { |
40 | | - background: ${(props) => |
41 | | - props.selected |
42 | | - ? props.theme.klerosUIComponentsWhiteBackground |
43 | | - : props.theme.klerosUIComponentsLightBlue}; |
44 | | - border: 1px solid |
45 | | - ${(props) => |
46 | | - props.selected |
47 | | - ? props.theme.klerosUIComponentsPrimaryBlue |
48 | | - : props.theme.klerosUIComponentsSecondaryBlue}; |
49 | | - color: ${(props) => |
50 | | - props.selected |
51 | | - ? props.theme.klerosUIComponentsPrimaryBlue |
52 | | - : props.theme.klerosUIComponentsSecondaryBlue}; |
53 | | - } |
54 | | -
|
55 | | - :hover:disabled { |
56 | | - cursor: default; |
57 | | - } |
58 | | -`; |
59 | | - |
60 | | -const StyledArrow = styled.svg``; |
61 | | - |
62 | | -const ArrowButton = styled(PageButton)` |
63 | | - & ${StyledArrow} { |
64 | | - ${svg} |
65 | | - fill: ${(props) => |
66 | | - props.disabled |
67 | | - ? props.theme.klerosUIComponentsStroke |
68 | | - : props.theme.klerosUIComponentsPrimaryText}; |
69 | | - transition: fill ease |
70 | | - ${({ theme }) => theme.klerosUIComponentsTransitionSpeed}; |
71 | | - } |
72 | | -
|
73 | | - :hover:enabled { |
74 | | - & ${StyledArrow} { |
75 | | - fill: ${({ theme }) => theme.klerosUIComponentsSecondaryBlue}; |
76 | | - } |
77 | | - } |
78 | | -`; |
79 | | - |
80 | | -const LeftArrow = styled(ArrowButton)` |
81 | | - & ${StyledArrow} { |
82 | | - padding-right: 1px; |
83 | | - } |
84 | | -`; |
85 | | - |
86 | | -const RightArrow = styled(ArrowButton)` |
87 | | - & ${StyledArrow} { |
88 | | - padding-left: 1px; |
89 | | - transform: rotate(180deg); |
90 | | - } |
91 | | -`; |
| 4 | +import { cn } from "../../utils"; |
| 5 | +import { Button, type ButtonProps } from "react-aria-components"; |
| 6 | +import clsx from "clsx"; |
92 | 7 |
|
| 8 | +const PageButton: React.FC<ButtonProps & { selected?: boolean }> = ({ |
| 9 | + children, |
| 10 | + selected, |
| 11 | + className, |
| 12 | + ...props |
| 13 | +}) => ( |
| 14 | + <Button |
| 15 | + {...props} |
| 16 | + className={cn( |
| 17 | + "rounded-base m-1 h-8 w-8 border", |
| 18 | + "flex items-center justify-center text-sm", |
| 19 | + "hover:cursor-pointer hover:disabled:cursor-default", |
| 20 | + selected |
| 21 | + ? [ |
| 22 | + "bg-klerosUIComponentsLightBlue hover:enabled:bg-klerosUIComponentsWhiteBackground", |
| 23 | + "border-klerosUIComponentsPrimaryBlue hover:enabled:border-klerosUIComponentsPrimaryBlue", |
| 24 | + "text-klerosUIComponentsPrimaryBlue hover:enabled:text-klerosUIComponentsPrimaryBlue", |
| 25 | + ] |
| 26 | + : [ |
| 27 | + "bg-klerosUIComponentsWhiteBackground hover:enabled:bg-klerosUIComponentsLightBlue", |
| 28 | + "border-klerosUIComponentsStroke hover:enabled:border-klerosUIComponentsSecondaryBlue", |
| 29 | + "text-klerosUIComponentsPrimaryText hover:enabled:text-klerosUIComponentsSecondaryBlue", |
| 30 | + ], |
| 31 | + className, |
| 32 | + )} |
| 33 | + > |
| 34 | + {children} |
| 35 | + </Button> |
| 36 | +); |
93 | 37 | interface StandardPaginationProps { |
94 | 38 | currentPage: number; |
95 | 39 | numPages: number; |
@@ -119,25 +63,49 @@ const StandardPagination: React.FC<StandardPaginationProps> = ({ |
119 | 63 | ] = usePagination(currentPage, numPages, callback); |
120 | 64 |
|
121 | 65 | return ( |
122 | | - <Wrapper {...{ className }}> |
123 | | - <LeftArrow disabled={minPageReached} onClick={decrementPage}> |
124 | | - <Arrow className={StyledArrow.styledComponentId} /> |
125 | | - </LeftArrow> |
| 66 | + <div |
| 67 | + className={cn("box-border flex items-center justify-center", className)} |
| 68 | + > |
| 69 | + <PageButton |
| 70 | + isDisabled={minPageReached} |
| 71 | + onPress={decrementPage} |
| 72 | + className="hover:enabled:[&>svg]:fill-klerosUIComponentsSecondaryBlue" |
| 73 | + > |
| 74 | + <Arrow |
| 75 | + className={clsx( |
| 76 | + "ease-ease pr-0.25 transition-[fill]", |
| 77 | + minPageReached |
| 78 | + ? ["fill-klerosUIComponentsStroke"] |
| 79 | + : ["fill-klerosUIComponentsPrimaryText"], |
| 80 | + )} |
| 81 | + /> |
| 82 | + </PageButton> |
126 | 83 | {!hideNumbers && |
127 | 84 | getPageRange().map((i) => ( |
128 | 85 | <PageButton |
129 | 86 | key={i} |
130 | 87 | selected={currentPage === i} |
131 | | - onClick={() => goToPage(i)} |
132 | | - disabled={disableNumbers} |
| 88 | + onPress={() => goToPage(i)} |
| 89 | + isDisabled={disableNumbers} |
133 | 90 | > |
134 | 91 | {i} |
135 | 92 | </PageButton> |
136 | 93 | ))} |
137 | | - <RightArrow disabled={maxPageReached} onClick={incrementPage}> |
138 | | - <Arrow className={StyledArrow.styledComponentId} /> |
139 | | - </RightArrow> |
140 | | - </Wrapper> |
| 94 | + <PageButton |
| 95 | + isDisabled={maxPageReached} |
| 96 | + onPress={incrementPage} |
| 97 | + className="hover:enabled:[&>svg]:fill-klerosUIComponentsSecondaryBlue" |
| 98 | + > |
| 99 | + <Arrow |
| 100 | + className={cn( |
| 101 | + "ease-ease rotate-180 pl-0.25 transition-[fill]", |
| 102 | + maxPageReached |
| 103 | + ? ["fill-klerosUIComponentsStroke"] |
| 104 | + : ["fill-klerosUIComponentsPrimaryText"], |
| 105 | + )} |
| 106 | + /> |
| 107 | + </PageButton> |
| 108 | + </div> |
141 | 109 | ); |
142 | 110 | }; |
143 | 111 |
|
|
0 commit comments