Skip to content

Commit 0fb0ec1

Browse files
committed
chore: button-migration
1 parent c2211a3 commit 0fb0ec1

File tree

12 files changed

+171
-216
lines changed

12 files changed

+171
-216
lines changed

src/App.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ const StyledTabs = styled(Tabs)`
5757
width: 995px;
5858
`;
5959

60-
const StyledButton = styled(Button)`
61-
margin-top: 64px;
62-
`;
63-
6460
const App = () => {
6561
const [theme, setTheme] = useState(lightTheme);
6662
const [tailwindTheme, setTailwindTheme] = useState("light");
@@ -118,8 +114,9 @@ const App = () => {
118114
{example === "tooltip" && <Tooltips />}
119115
{example === "copiable" && <Copiable />}
120116
</StyledCard>
121-
<StyledButton
117+
<Button
122118
variant="primary"
119+
className="mt-16"
123120
text={"Change theme"}
124121
onClick={changeTheme}
125122
/>

src/examples/buttons.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const Buttons = () => (
66
<>
77
<Button text="Primary Button" />
88
<Button small text="Get help" Icon={Telegram} />
9-
<Button disabled isLoading text="Hello" />
9+
<Button isDisabled isLoading text="Hello" />
1010
<Button variant="secondary" text="Hello" />
11-
<Button variant="secondary" isLoading disabled text="Hello" />
11+
<Button variant="secondary" isLoading isDisabled text="Hello" />
1212
<Button variant="tertiary" small text="Hello" />
1313
</>
1414
);

src/lib/button/ButtonIcon.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from "react";
2+
import { cn } from "../../utils";
3+
import { ButtonProps } from ".";
4+
5+
const ButtonIcon: React.FC<
6+
Pick<ButtonProps, "Icon" | "icon" | "isDisabled" | "isLoading" | "variant">
7+
> = ({ Icon, icon, isDisabled, isLoading, variant }) => {
8+
const isSecondary = variant === "secondary";
9+
return (
10+
icon ??
11+
(Icon && (
12+
<Icon
13+
className={cn(
14+
"button-svg",
15+
"mr-2 h-4 w-4",
16+
"fill-klerosUIComponentsWhiteBackground",
17+
isLoading && ["invisible"],
18+
isSecondary && ["fill-klerosUIComponentsPrimaryBlue"],
19+
isDisabled && ["fill-klerosUIComponentsStroke"],
20+
)}
21+
/>
22+
))
23+
);
24+
};
25+
export default ButtonIcon;

src/lib/button/ButtonText.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
import { ButtonProps } from ".";
3+
import { cn } from "../../utils";
4+
5+
const ButtonText: React.FC<
6+
Pick<ButtonProps, "text" | "isDisabled" | "isLoading" | "variant">
7+
> = ({ text, isDisabled, isLoading, variant }) => {
8+
const isSecondary = variant === "secondary";
9+
return (
10+
<p
11+
className={cn(
12+
"button-text",
13+
"text-klerosUIComponentsWhiteBackground text-center leading-[22px] font-semibold whitespace-pre",
14+
isLoading && ["invisible"],
15+
isSecondary && ["text-klerosUIComponentsPrimaryBlue"],
16+
isDisabled && ["text-klerosUIComponentsStroke"],
17+
)}
18+
>
19+
{text}
20+
</p>
21+
);
22+
};
23+
24+
export default ButtonText;

src/lib/button/KlerosSymbol.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react";
2+
import { ButtonProps } from ".";
3+
import KlerosIcon from "../../assets/svgs/kleros.svg";
4+
import { cn } from "../../utils";
5+
6+
const KlerosSymbol: React.FC<Pick<ButtonProps, "isDisabled" | "variant">> = ({
7+
isDisabled,
8+
variant,
9+
}) => {
10+
const isPrimary = variant === "primary" || variant === undefined;
11+
const isSecondary = variant === "secondary";
12+
const isTertiary = variant === "tertiary";
13+
return (
14+
<KlerosIcon
15+
className={cn(
16+
"button-loading",
17+
"absolute h-[22px]",
18+
"fill-klerosUIComponentsStroke animate-breathing",
19+
(isPrimary || isTertiary) && ["fill-klerosUIComponentsWhiteBackground"],
20+
isSecondary && ["fill-klerosUIComponentsPrimaryBlue"],
21+
isDisabled && ["fill-klerosUIComponentsStroke"],
22+
)}
23+
/>
24+
);
25+
};
26+
27+
export default KlerosSymbol;

src/lib/button/base.tsx

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/lib/button/index.tsx

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
import React from "react";
2-
import { BaseButtonProps } from "./base";
3-
import PrimaryButton from "./primary";
4-
import SecondaryButton from "./secondary";
5-
import TertiaryButton from "./tertiary";
6-
import KlerosSymbol from "../../assets/svgs/kleros.svg";
2+
import { cn } from "../../utils";
3+
import {
4+
Button as AriaButton,
5+
type ButtonProps as AriaButtonProps,
6+
} from "react-aria-components";
7+
import ButtonText from "./ButtonText";
8+
import KlerosSymbol from "./KlerosSymbol";
9+
import ButtonIcon from "./ButtonIcon";
710

8-
interface ButtonProps extends Omit<BaseButtonProps, "$loading"> {
9-
disabled?: boolean;
11+
export interface BaseButtonProps {
12+
variant?: "primary" | "secondary" | "tertiary";
13+
small?: boolean;
14+
isLoading?: boolean;
15+
}
16+
17+
export interface ButtonProps
18+
extends AriaButtonProps,
19+
Omit<BaseButtonProps, "$loading"> {
1020
text: string;
1121
Icon?: React.FC<React.SVGAttributes<SVGElement>>;
1222
icon?: React.ReactNode;
1323
onClick?: React.MouseEventHandler<HTMLButtonElement>;
24+
className?: string;
1425
}
1526

1627
const Button: React.FC<ButtonProps> = ({
@@ -20,18 +31,45 @@ const Button: React.FC<ButtonProps> = ({
2031
icon,
2132
onClick,
2233
isLoading,
34+
className,
35+
isDisabled,
2336
...props
2437
}) => {
25-
let ButtonType = PrimaryButton;
26-
if (variant === "secondary") ButtonType = SecondaryButton;
27-
if (variant === "tertiary") ButtonType = TertiaryButton;
28-
38+
const isPrimary = variant === "primary" || variant === undefined;
39+
const isSecondary = variant === "secondary";
40+
const isTertiary = variant === "tertiary";
2941
return (
30-
<ButtonType {...{ variant, onClick, isLoading, ...props }}>
31-
{isLoading && <KlerosSymbol className="button-loading" />}
32-
{icon ?? (Icon && <Icon className="button-svg" />)}
33-
<p className="button-text">{text}</p>
34-
</ButtonType>
42+
<AriaButton
43+
className={cn(
44+
"relative box-border h-fit w-fit",
45+
"flex flex-row items-center justify-center",
46+
"rounded-base hover:cursor-pointer",
47+
"ease-ease transition-[background] duration-(--klerosUIComponentsTransitionSpeed)",
48+
49+
props.small ? "px-6 py-1.5" : "px-8 py-[11.5px]",
50+
isPrimary && [
51+
"bg-klerosUIComponentsPrimaryBlue hover:bg-klerosUIComponentsSecondaryBlue",
52+
],
53+
isSecondary && [
54+
"bg-klerosUIComponentsWhiteBackground hover:bg-klerosUIComponentsMediumBlue",
55+
"border-klerosUIComponentsPrimaryBlue border",
56+
props.small ? "px-[23px] py-[5px]" : "px-[31px] py-[10.5px]",
57+
],
58+
isTertiary && [
59+
"bg-klerosUIComponentsSecondaryPurple hover:bg-klerosUIComponentsPrimaryPurple",
60+
],
61+
isDisabled && [
62+
"bg-klerosUIComponentsLightGrey hover:bg-klerosUIComponentsLightGrey hover:cursor-not-allowed",
63+
isSecondary && "border-klerosUIComponentsStroke border",
64+
],
65+
className,
66+
)}
67+
{...{ variant, onClick, isLoading, isDisabled, ...props }}
68+
>
69+
{isLoading && <KlerosSymbol {...{ isDisabled, variant }} />}
70+
<ButtonIcon {...{ icon, Icon, isDisabled, isLoading, variant }} />
71+
<ButtonText {...{ isLoading, isDisabled, variant, text }} />
72+
</AriaButton>
3573
);
3674
};
3775

src/lib/button/primary.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/lib/button/secondary.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/lib/button/tertiary.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/lib/dropdown/cascader/selector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Selector: React.FC<ISelector> = ({
3333
<Button
3434
onClick={() => onSelect()}
3535
text={currentSelection ? `Select\n${currentSelection}` : "No Selection"}
36-
disabled={!currentSelection}
36+
isDisabled={!currentSelection}
3737
/>
3838
</Wrapper>
3939
);

0 commit comments

Comments
 (0)