|
1 | 1 | import React from "react"; |
2 | | -import styled from "styled-components"; |
3 | | -import { borderBox, small, button } from "../styles/common-style"; |
4 | | - |
5 | | -const Wrapper = styled.div` |
6 | | - ${borderBox} |
7 | | - display: flex; |
8 | | - flex-wrap: wrap; |
9 | | - gap: 2px 0; |
10 | | -`; |
11 | | - |
12 | | -const Element = styled.button<{ clickable?: boolean }>` |
13 | | - ${button} |
14 | | - background: none; |
15 | | - padding: 0; |
16 | | -
|
17 | | - :hover { |
18 | | - ${({ clickable, theme }) => |
19 | | - clickable |
20 | | - ? `small { color: ${theme.klerosUIComponentsPrimaryText}; }` |
21 | | - : `cursor: text !important`} |
22 | | - } |
23 | | -`; |
24 | | - |
25 | | -const Content = styled.small` |
26 | | - ${small} |
27 | | - transition: color ease |
28 | | - ${({ theme }) => theme.klerosUIComponentsTransitionSpeed}; |
29 | | -`; |
30 | | - |
31 | | -const Separator = styled(Content)` |
32 | | - margin: 0px 8px; |
33 | | -`; |
34 | | - |
35 | | -const ActiveElement = styled(Content)` |
36 | | - color: ${({ theme }) => theme.klerosUIComponentsPrimaryText}; |
37 | | -`; |
| 2 | +import { cn } from "../utils"; |
| 3 | +import { Button } from "react-aria-components"; |
| 4 | +import { clsx } from "clsx"; |
38 | 5 |
|
39 | 6 | interface BreadcrumbProps { |
40 | 7 | items: { text: string; value: any }[]; |
41 | 8 | // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type |
42 | 9 | callback?: Function; |
43 | 10 | clickable?: boolean; |
44 | 11 | className?: string; |
| 12 | + variant?: "primary" | "secondary"; |
45 | 13 | } |
46 | 14 |
|
47 | | -const Breadcrumb: React.FC<BreadcrumbProps> = ({ |
| 15 | +const Content: React.FC< |
| 16 | + React.ComponentProps<"small"> & { variant?: "primary" | "secondary" } |
| 17 | +> = ({ children, className, variant, ...props }) => ( |
| 18 | + <small |
| 19 | + className={cn( |
| 20 | + "ease-ease transition-colors", |
| 21 | + "text-klerosUIComponentsSecondaryText text-sm break-words", |
| 22 | + className, |
| 23 | + variant === "primary" && "text-klerosUIComponentsPrimaryBlue", |
| 24 | + )} |
| 25 | + {...props} |
| 26 | + > |
| 27 | + {children} |
| 28 | + </small> |
| 29 | +); |
| 30 | + |
| 31 | +function Breadcrumb({ |
48 | 32 | items, |
49 | 33 | callback, |
50 | 34 | clickable, |
51 | 35 | className, |
52 | | -}) => ( |
53 | | - <Wrapper {...{ className }}> |
54 | | - {items.map(({ text, value }, i) => |
55 | | - i === items.length - 1 ? ( |
56 | | - <ActiveElement key={i}>{text}</ActiveElement> |
57 | | - ) : ( |
58 | | - <React.Fragment key={i}> |
59 | | - <Element |
60 | | - onClick={() => (callback ? callback(value) : null)} |
61 | | - {...{ clickable }} |
| 36 | + variant, |
| 37 | +}: Readonly<BreadcrumbProps>) { |
| 38 | + return ( |
| 39 | + <div |
| 40 | + className={cn( |
| 41 | + "box-border flex flex-wrap items-center gap-y-0.5", |
| 42 | + className, |
| 43 | + )} |
| 44 | + > |
| 45 | + {items.map(({ text, value }, i) => |
| 46 | + i === items.length - 1 ? ( |
| 47 | + <Content |
| 48 | + className="text-klerosUIComponentsPrimaryText font-semibold" |
| 49 | + {...{ variant }} |
| 50 | + key={i} |
62 | 51 | > |
63 | | - <Content>{text}</Content> |
64 | | - </Element> |
65 | | - <Separator>{"/"}</Separator> |
66 | | - </React.Fragment> |
67 | | - ), |
68 | | - )} |
69 | | - </Wrapper> |
70 | | -); |
| 52 | + {text} |
| 53 | + </Content> |
| 54 | + ) : ( |
| 55 | + <React.Fragment key={i}> |
| 56 | + <Button |
| 57 | + className={clsx(clickable ? "cursor-pointer" : "cursor-text")} |
| 58 | + onPress={() => (callback ? callback(value) : null)} |
| 59 | + > |
| 60 | + <Content |
| 61 | + className={clsx( |
| 62 | + clickable && "hover:text-klerosUIComponentsPrimaryText", |
| 63 | + )} |
| 64 | + {...{ variant }} |
| 65 | + > |
| 66 | + {text} |
| 67 | + </Content> |
| 68 | + </Button> |
| 69 | + <Content className="mx-2" {...{ variant }}> |
| 70 | + {"/"} |
| 71 | + </Content> |
| 72 | + </React.Fragment> |
| 73 | + ), |
| 74 | + )} |
| 75 | + </div> |
| 76 | + ); |
| 77 | +} |
71 | 78 |
|
72 | 79 | export default Breadcrumb; |
0 commit comments