Skip to content

Commit 9cce1a7

Browse files
authored
Merge pull request #71 from kleros/chore/dot-migration
Chore/dot breadcrumb migration
2 parents be08ba3 + 7fa7c99 commit 9cce1a7

File tree

5 files changed

+114
-71
lines changed

5 files changed

+114
-71
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/lib/dot.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import styled from "styled-components";
2-
import { borderBox } from "../styles/common-style";
3-
1+
import React from "react";
2+
import { cn } from "../utils";
43
interface DotProps {
54
color: string;
5+
className?: string;
66
}
77

8-
const Dot = styled.div<DotProps>`
9-
${borderBox}
10-
background: ${({ color }) => color};
11-
border-radius: 50%;
12-
width: 8px;
13-
height: 8px;
14-
`;
15-
8+
function Dot({ color, className }: Readonly<DotProps>) {
9+
return (
10+
<div
11+
style={{ background: color }}
12+
className={cn("box-border h-2 w-2 rounded-full", className)}
13+
/>
14+
);
15+
}
1616
export default Dot;

src/lib/dropdown/base-item.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ const StyledText = styled.p`
4747
user-select: none;
4848
`;
4949

50-
const StyledDot = styled(Dot)`
51-
margin-right: 8px;
52-
`;
53-
5450
const CountDisplay = styled.label`
5551
width: 24px;
5652
height: 24px;
@@ -89,7 +85,7 @@ const BaseItem: React.FC<IBaseItem> = ({
8985
{...{ onClick, ...props }}
9086
>
9187
{icon ?? (Icon && <Icon className="item-icon" />)}
92-
{dot && <StyledDot color={dot} />}
88+
{dot && <Dot className="mr-2" color={dot} />}
9389
<StyledText>{text}</StyledText>
9490
{childrenCount !== undefined ? (
9591
<CountDisplay className="count-display">

src/stories/breadcrumb.stories.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import { IPreviewArgs } from "./utils";
4+
5+
import BreadcrumbComponent from "../lib/breadcrumb";
6+
7+
const meta = {
8+
component: BreadcrumbComponent,
9+
title: "Pagination/Breadcrumb",
10+
tags: ["autodocs"],
11+
argTypes: {
12+
variant: {
13+
options: ["primary", "secondary"],
14+
control: { type: "radio" },
15+
},
16+
clickable: {
17+
control: "boolean",
18+
},
19+
},
20+
} satisfies Meta<typeof BreadcrumbComponent>;
21+
22+
export default meta;
23+
24+
type Story = StoryObj<typeof meta> & IPreviewArgs;
25+
26+
export const Breadcrumb: Story = {
27+
args: {
28+
variant: "primary",
29+
themeUI: "dark",
30+
backgroundUI: "light",
31+
items: [
32+
{ text: "General Court", value: 0 },
33+
{ text: "Blockchain", value: 1 },
34+
{ text: "Non-Technical", value: 2 },
35+
],
36+
clickable: false,
37+
},
38+
};

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)