Skip to content

Commit c29b417

Browse files
committed
feat: added the button component
1 parent 6de9364 commit c29b417

File tree

3 files changed

+118
-28
lines changed

3 files changed

+118
-28
lines changed

apps/docs/stories/button.stories.tsx

+43-16
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const meta: Meta<typeof Button> = {
88
argTypes: {
99
variant: {
1010
control: { type: "select" },
11-
options: ["primary", "danger", "warning", "default", "ghost", "link"],
11+
options: ["primary", "danger", "warning", "secondary", "ghost", "link", "solid", "dashed"],
1212
},
1313
size: {
1414
control: { type: "select" },
15-
options: ["default", "sm", "lg", "icon"],
15+
options: ["xs", "sm", "md", "lg"],
1616
},
1717
theme: {
1818
control: { type: "select" },
@@ -45,9 +45,9 @@ type Story = StoryObj<typeof Button>;
4545
export const Primary: Story = {
4646
render: (args) => <Button {...args} />,
4747
args: {
48-
children: "Button",
48+
children: "Big Button 1",
4949
variant: "primary",
50-
size: "default",
50+
size: "xs",
5151
theme: "light",
5252
asChild: false,
5353
onClick: () => {
@@ -56,38 +56,65 @@ export const Primary: Story = {
5656
},
5757
};
5858

59-
export const Default: Story = {
59+
export const Secondary: Story = {
6060
render: (args) => <Button {...args} />,
6161
args: {
6262
...Primary.args,
63-
children: "Default",
64-
variant: "default",
63+
children: "Big Button 1",
64+
variant: "secondary",
6565
},
6666
};
6767

68-
export const Large: Story = {
68+
export const Warning: Story = {
6969
render: (args) => <Button {...args} />,
7070
args: {
7171
...Primary.args,
72-
children: "Large",
73-
size: "lg",
72+
children: "Big Button 1",
73+
variant: "warning",
7474
},
7575
};
7676

77-
export const Small: Story = {
77+
export const Danger: Story = {
7878
render: (args) => <Button {...args} />,
7979
args: {
8080
...Primary.args,
81-
children: "Small",
82-
size: "sm",
81+
children: "Big Button 1",
82+
variant: "danger",
8383
},
8484
};
8585

86-
export const Dark: Story = {
86+
export const Link: Story = {
8787
render: (args) => <Button {...args} />,
8888
args: {
8989
...Primary.args,
90-
children: "Dark Theme",
91-
theme: "dark",
90+
children: "Big Button 1",
91+
variant: "link",
9292
},
9393
};
94+
95+
export const Ghost: Story = {
96+
render: (args) => <Button {...args} />,
97+
args: {
98+
...Primary.args,
99+
children: "Big Button 1",
100+
variant: "ghost",
101+
},
102+
};
103+
104+
export const Solid: Story = {
105+
render: (args) => <Button {...args} />,
106+
args: {
107+
...Primary.args,
108+
children: "Big Button 1",
109+
variant: "solid",
110+
},
111+
};
112+
113+
export const Dashed: Story = {
114+
render: (args) => <Button {...args} />,
115+
args: {
116+
...Primary.args,
117+
children: "Big Button 1",
118+
variant: "dashed",
119+
},
120+
};

packages/button/src/button-variants.tsx

+12-10
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,34 @@ const buttonVariants = cva(
1010
danger:
1111
"bg-cherry-500 text-destructive-foreground shadow-sm hover:bg-cherry-500/90",
1212
warning:
13-
"bg-amber-500 text-primary-foreground shadow hover:bg-amber-500/90",
14-
default:
13+
"bg-amber-500 text-black shadow hover:bg-amber-500/90",
14+
secondary:
1515
"bg-slate-400 text-vanilla-100 shadow-sm hover:bg-slate-400/80",
1616
ghost: "text-primary-foreground ",
17-
link: "text-slate-100 underline-offset-4 hover:underline",
17+
link: "text-robin-500 underline-offset-4",
18+
solid: "outline text-primary-foreground outline-[#1D2023] rounded-sm hover:bg-[#24272B]",
19+
dashed: "outline-dashed text-primary-foreground outline-[#1D2023] hover:bg-[#24272B]"
1820
},
1921
size: {
20-
default: "h-9 px-4 py-2",
21-
sm: "h-8 rounded-md px-3 text-xs",
22-
lg: "h-10 rounded-md px-8",
23-
icon: "h-9 w-9",
22+
xs: "h-6 rounded-sm py-1 text-[10px]",
23+
sm: "h-8 rounded-sm py-2 text-xs",
24+
md: "h-9 rounded-sm py-2 text-xs",
25+
lg: "h-12 rounded-sm py-3.5 text-base",
2426
},
2527
theme: {
2628
light: "",
2729
dark: "dark",
2830
},
2931
},
3032
defaultVariants: {
31-
variant: "default",
32-
size: "default",
33+
variant: "primary",
34+
size: "sm",
3335
theme: "light",
3436
},
3537
compoundVariants: [
3638
{
3739
theme: "dark",
38-
variant: "default",
40+
variant: "primary",
3941
className:
4042
"bg-robin-500 text-primary-foreground-dark shadow hover:bg-robin-500/90",
4143
},

packages/button/src/button.tsx

+63-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { type VariantProps } from "class-variance-authority";
55
import buttonVariants from "./button-variants";
66

77
import { cn } from "./lib/utils";
8+
import React from "react";
89

910
export interface ButtonProps
1011
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
@@ -13,18 +14,78 @@ export interface ButtonProps
1314
theme?: "light" | "dark";
1415
}
1516

17+
interface ArrowIconProps {
18+
stroke: string;
19+
className: string;
20+
}
21+
22+
const svgLeftVariants = ({ size }: { size?: "xs" | "sm" | "md" | "lg" | null | undefined }) => {
23+
return cn({
24+
"w-2.5 ml-2 mr-1.5": size === "xs",
25+
"w-4 ml-4 mr-2": size === "sm",
26+
"w-4 ml-4 mr-2 h-4": size === "md",
27+
"w-5 h-5 ml-6 mr-2": size === "lg",
28+
});
29+
};
30+
31+
const svgRighttVariants = ({ size }: { size?: "xs" | "sm" | "md" | "lg" | null | undefined }) => {
32+
return cn({
33+
"w-2.5 ml-1.5 mr-2": size === "xs",
34+
"w-4 ml-2 mr-4": size === "sm",
35+
"w-4 ml-2 mr-4 h-4": size === "md",
36+
"w-5 h-5 ml-2 mr-6": size === "lg",
37+
});
38+
};
39+
40+
41+
const ArrowIcon = ({ stroke, className }: ArrowIconProps) => (
42+
<svg
43+
className={className}
44+
viewBox="0 0 28 28"
45+
fill="none"
46+
xmlns="http://www.w3.org/2000/svg"
47+
>
48+
<path
49+
d="M18.7776 20.7145L25.4919 14.0002L18.7776 7.28595"
50+
stroke={stroke}
51+
stroke-width="2.51786"
52+
stroke-linecap="round"
53+
stroke-linejoin="round"
54+
/>
55+
<path
56+
d="M9.82513 7.28595L3.11084 14.0002L9.82513 20.7145"
57+
stroke={stroke}
58+
stroke-width="2.51786"
59+
stroke-linecap="round"
60+
stroke-linejoin="round"
61+
/>
62+
</svg>
63+
);
64+
65+
1666
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
1767
(
18-
{ className, variant, size, theme = "light", asChild = false, ...props },
68+
{ className, variant, size, children, theme = "light", asChild = false, ...props },
1969
ref
2070
) => {
2171
const Comp = asChild ? Slot : "button";
72+
const stroke = variant === 'warning' ? 'black' : variant === 'link' ? '#4E74F8' : 'white';
2273
return (
2374
<Comp
2475
className={cn(buttonVariants({ variant, size, theme, className }))}
2576
ref={ref}
2677
{...props}
27-
/>
78+
>
79+
<ArrowIcon
80+
stroke={stroke}
81+
className={cn(svgLeftVariants({ size }))}
82+
/>
83+
{children}
84+
<ArrowIcon
85+
stroke={stroke}
86+
className={cn(svgRighttVariants({ size }))}
87+
/>
88+
</Comp>
2889
);
2990
}
3091
);

0 commit comments

Comments
 (0)