Skip to content

Commit 7a7779c

Browse files
committed
chore: breadcrumb-migration
1 parent cab06cb commit 7a7779c

File tree

2 files changed

+64
-55
lines changed

2 files changed

+64
-55
lines changed

src/lib/breadcrumb.tsx

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,79 @@
11
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";
385

396
interface BreadcrumbProps {
407
items: { text: string; value: any }[];
418
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
429
callback?: Function;
4310
clickable?: boolean;
4411
className?: string;
12+
variant?: "primary" | "secondary";
4513
}
4614

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({
4832
items,
4933
callback,
5034
clickable,
5135
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}
6251
>
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+
}
7178

7279
export default Breadcrumb;

src/styles/global.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157

158158
--radius-base: var(--klerosUIComponentsBaseRadius);
159159

160+
--default-transition-duration: var(--klerosUIComponentsTransitionSpeed);
161+
160162
/* Animations */
161163
@keyframes fadeIn {
162164
0% {

0 commit comments

Comments
 (0)