Skip to content

Commit 93b8299

Browse files
authored
Merge pull request #34 from prgrms-web-devcourse-final-project/feat/button#32
[style] 버튼 공통 컴포넌트 #32
2 parents 9841fff + d7d202e commit 93b8299

File tree

9 files changed

+138
-33
lines changed

9 files changed

+138
-33
lines changed

package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
]
1919
},
2020
"dependencies": {
21+
"class-variance-authority": "^0.7.1",
2122
"gsap": "^3.13.0",
2223
"next": "15.5.3",
2324
"react": "19.1.0",

src/app/design-system/page.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

3-
import Button from '@/shared/components/Button';
3+
import Button from '@/shared/components/button/Button';
4+
import TextButton from '@/shared/components/button/TextButton';
45
import ConfirmPop from '@/shared/components/ModalPop/ConfirmPop';
56
import ModalLayout from '@/shared/components/ModalPop/ModalLayout';
67
import { useState } from 'react';
@@ -43,11 +44,23 @@ function Page() {
4344

4445
<div className="space-y-2">
4546
<h3 className="text-xl font-medium border-b pb-1">Button</h3>
46-
<Button>버튼</Button>
47-
<Button variant="purple" size="sm">
47+
<Button type="button">버튼</Button>
48+
<Button color="purple" type="button">
4849
Button
4950
</Button>
50-
<Button variant="disable">button</Button>
51+
<Button disabled>button</Button>
52+
<Button type="button" size="sm">
53+
버튼
54+
</Button>
55+
<Button type="button" size="sm" color="purple">
56+
버튼
57+
</Button>
58+
<Button size="sm" disabled>
59+
버튼
60+
</Button>
61+
62+
<TextButton>텍스트 버튼</TextButton>
63+
<TextButton size="sm">텍스트 버튼</TextButton>
5164
</div>
5265
</div>
5366

src/components/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function index() {
2+
return <button>버튼</button>;
3+
}
4+
export default index;

src/shared/components/Button.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import tw from '@/shared/utills/tw';
2+
import { cva } from 'class-variance-authority';
3+
import { ButtonHTMLAttributes, Ref } from 'react';
4+
5+
// 버튼속성을 다 받을 수 있게
6+
// 클래스네임, 기본적인건 다 props로 받을 수 있게
7+
// 버튼 보여질 경우 arial hidden을 넣고 아이콘의경우 aria-label넣는다
8+
// 속성값에 disabled넣었을때 알어서 바뀔수 있게 할 수 있게 수정하기.
9+
// Ref가 잘 되는지 확인해보기
10+
11+
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
12+
size?: 'default' | 'sm';
13+
color?: 'default' | 'purple';
14+
ref?: Ref<HTMLButtonElement | null>;
15+
disable?: boolean;
16+
type?: 'submit' | 'button';
17+
children?: React.ReactNode;
18+
className?: string;
19+
}
20+
21+
export const ButtonClass = cva(
22+
`
23+
py-1 px-2 rounded-lg text-base font-bold flex-center text-bold text-navy duration-300 disabled:bg-gray disabled:cursor-not-allowed disabled:text-primary
24+
`,
25+
{
26+
variants: {
27+
color: {
28+
default: 'bg-secondary text-navy enabled:hover:inset-shadow-black',
29+
purple: 'bg-tertiary text-secondary enabled:hover:inset-shadow-white',
30+
},
31+
size: {
32+
default: 'h-10, min-w-25',
33+
sm: 'h-8 min-w-20',
34+
},
35+
},
36+
defaultVariants: {
37+
color: 'default',
38+
size: 'default',
39+
},
40+
}
41+
);
42+
43+
function Button({
44+
size,
45+
type = 'button',
46+
color,
47+
children,
48+
className,
49+
ref,
50+
disabled,
51+
...rest
52+
}: Props) {
53+
return (
54+
<button
55+
className={tw(ButtonClass({ color, size, className }))}
56+
type={type}
57+
ref={ref}
58+
disabled={disabled}
59+
{...rest}
60+
>
61+
{children}
62+
</button>
63+
);
64+
}
65+
export default Button;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Ref } from 'react';
2+
3+
interface Props {
4+
size?: 'default' | 'sm';
5+
type?: 'button' | 'submit';
6+
ref?: Ref<HTMLButtonElement | null>;
7+
children: React.ReactNode;
8+
className?: string;
9+
}
10+
11+
const SIZE = {
12+
default: 'text-base flex flex-col justfy-center',
13+
sm: 'text-sm flex flex-col justfy-center',
14+
};
15+
16+
function TextButton({
17+
type = 'button',
18+
children,
19+
className,
20+
ref,
21+
size = 'default',
22+
...rest
23+
}: Props) {
24+
return (
25+
<button className={`${SIZE[size]} ${className}`} type={type} ref={ref} {...rest}>
26+
{children}
27+
<div className="h-[1px] w-100% bg-white"></div>
28+
</button>
29+
);
30+
}
31+
export default TextButton;

src/shared/styles/_theme.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
--color-white: #ffffff;
1414
--color-black: #0f172a;
1515
--color-bg-pop: #3d3d3d;
16+
--color-navy:#1f2544;
1617
--font-serif: 'Hahmlet', serif;
18+
19+
--inset-shadow-black: inset 0 2px 6px rgba(0, 0, 0, 0.3);
20+
--inset-shadow-white: inset 0 0 8px rgba(255, 255, 255, 0.4);
21+
1722
}

src/shared/styles/global.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
'NanumSquareNeo',sans-serif;
1313
line-height: 1.5;
1414
font-weight: 500;
15+
color:#fff;
16+
background-color: var(--color-primary)
1517
}
1618

0 commit comments

Comments
 (0)