Skip to content

Commit a84896b

Browse files
committed
Update Button component to use shorthand size props and remove unnecessary controls
1 parent 5b6da92 commit a84896b

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

bun.lockb

349 KB
Binary file not shown.

src/components/Button/Button.stories.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export const Variants: StoryObj<typeof Button> = {
3333
control: false,
3434
},
3535
variant: {
36-
control: "radio",
37-
options: ["solid", "outline"],
36+
control: false,
3837
},
3938
},
4039
};
@@ -63,8 +62,7 @@ export const Tones: StoryObj<typeof Button> = {
6362
control: false,
6463
},
6564
tone: {
66-
control: "radio",
67-
options: ["neutral", "accent", "danger", "warning"],
65+
control: false,
6866
},
6967
},
7068
};
@@ -73,13 +71,13 @@ export const Sizes: StoryObj<typeof Button> = {
7371
render: (args) => {
7472
return (
7573
<div className={vstack({ gap: "4" })}>
76-
<Button {...args} size="small">
74+
<Button {...args} size="sm">
7775
작은 버튼
7876
</Button>
79-
<Button {...args} size="medium">
77+
<Button {...args} size="md">
8078
중간 버튼
8179
</Button>
82-
<Button {...args} size="large">
80+
<Button {...args} size="lg">
8381
큰 버튼
8482
</Button>
8583
</div>
@@ -90,8 +88,7 @@ export const Sizes: StoryObj<typeof Button> = {
9088
control: false,
9189
},
9290
size: {
93-
control: "radio",
94-
options: ["small", "medium", "large"],
91+
control: false,
9592
},
9693
},
9794
};
@@ -112,7 +109,7 @@ export const Disabled: StoryObj<typeof Button> = {
112109
control: false,
113110
},
114111
disabled: {
115-
control: "boolean",
112+
control: false,
116113
},
117114
},
118115
};

src/components/Button/Button.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, { type HTMLAttributes } from "react";
22
import { css, cva } from "../../../styled-system/css";
3-
import type { SystemStyleObject } from "@pandacss/types";
3+
import type { Tone } from "../../tokens/colors";
44

55
type ButtonVariant = "solid" | "outline";
6-
type ButtonTone = "neutral" | "accent" | "danger" | "warning";
7-
type ButtonSize = "small" | "medium" | "large";
6+
type ButtonSize = "sm" | "md" | "lg";
87

98
export interface ButtonProps
109
extends Omit<HTMLAttributes<HTMLElement>, "style"> {
@@ -17,20 +16,18 @@ export interface ButtonProps
1716
/** 종류 */
1817
variant: ButtonVariant;
1918
/** 색조 */
20-
tone?: ButtonTone;
19+
tone?: Tone;
2120
/** 버튼의 크기 */
2221
size?: ButtonSize;
23-
/** 추가 스타일 */
24-
style?: SystemStyleObject;
2522
/** 버튼 비활성화 여부 */
2623
disabled?: boolean;
2724
}
2825

2926
/**
30-
* - `variant` 속성으로 버튼의 스타일 종류를 지정할 수 있습니다. (solid, outline)
31-
* - `tone` 속성으로 버튼의 색상 강조를 지정할 수 있습니다. (neutral, accent, danger, warning)
32-
* - `size` 속성으로 버튼의 크기를 지정할 수 있습니다. (small, medium, large)
33-
* - `type` 속성으로 버튼의 타입을 지정할 수 있습니다. (button, submit)
27+
* - `variant` 속성으로 버튼의 스타일 종류를 지정할 수 있습니다.
28+
* - `tone` 속성으로 버튼의 색상 강조를 지정할 수 있습니다.
29+
* - `size` 속성으로 버튼의 크기를 지정할 수 있습니다.
30+
* - `type` 속성으로 버튼의 타입을 지정할 수 있습니다.
3431
* - `disabled` 속성을 사용하여 버튼을 비활성화할 수 있습니다.
3532
*/
3633
export const Button = ({
@@ -39,18 +36,13 @@ export const Button = ({
3936
onClick,
4037
variant = "solid",
4138
tone = "neutral",
42-
style,
43-
size = "medium",
39+
size = "md",
4440
disabled,
4541
...rest
4642
}: ButtonProps) => {
4743
return (
4844
<button
49-
className={css(
50-
styles.raw({ tone, variant, size }),
51-
baseStyles,
52-
...(Array.isArray(style) ? style : [style])
53-
)}
45+
className={css(styles.raw({ tone, variant, size }), baseStyles)}
5446
type={type}
5547
onClick={onClick}
5648
disabled={disabled}
@@ -88,15 +80,15 @@ const styles = cva({
8880
},
8981
variants: {
9082
size: {
91-
small: {
83+
sm: {
9284
padding: "0.5rem 1.5rem",
9385
fontSize: "sm",
9486
},
95-
medium: {
87+
md: {
9688
padding: "0.7rem 2rem",
9789
fontSize: "md",
9890
},
99-
large: {
91+
lg: {
10092
padding: "1rem 2.5rem",
10193
fontSize: "lg",
10294
},
@@ -183,7 +175,7 @@ const styles = cva({
183175
css: {
184176
border: "3px solid",
185177
borderColor: "border",
186-
color: "text.DEFAULT.base",
178+
color: "text",
187179
"&:active, &:hover": {
188180
background: "bg.hover",
189181
color: "text.muted",
@@ -201,7 +193,7 @@ const styles = cva({
201193
css: {
202194
border: "3px solid",
203195
borderColor: "border.accent",
204-
color: "text.accent.base",
196+
color: "text.accent",
205197
"&:active, &:hover": {
206198
background: "bg.hover.accent",
207199
color: "text.muted.accent",
@@ -219,7 +211,7 @@ const styles = cva({
219211
css: {
220212
border: "3px solid",
221213
borderColor: "border.danger",
222-
color: "text.danger.base",
214+
color: "text.danger",
223215
"&:active, &:hover": {
224216
background: "bg.hover.danger",
225217
color: "text.muted.danger",
@@ -237,7 +229,7 @@ const styles = cva({
237229
css: {
238230
border: "3px solid",
239231
borderColor: "border.warning",
240-
color: "text.warning.base",
232+
color: "text.warning",
241233
"&:active, &:hover": {
242234
background: "bg.hover.warning",
243235
color: "text.muted.warning",

0 commit comments

Comments
 (0)