๐ฆ ๊ณตํต ์ปดํฌ๋ํธ ์ค๊ณ ๊ฐ์ด๋ (React + Tailwind)
๐ฏ ์ ๊ณตํต ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ค๊น?
๊ณตํต ์ปดํฌ๋ํธ๋
๐ ๋์์ธ ์ผ๊ด์ฑ ์ ์ง
๐ ์ฝ๋ ์ฌ์ฌ์ฉ
๐ ์ ์ง๋ณด์ ํจ์จ ์ฆ๊ฐ
๋ฅผ ์ํด ์ฌ์ฉํ๋ค.
๋จ, ๋ฌด์กฐ๊ฑด ๋ง์ด ๋ง๋๋ ๊ฒ ์๋๋ผ โํ์ํ ๋งํผ๋งโ ๋ง๋๋ ๊ฒ ํต์ฌ์ด๋ค.
๐ง ํต์ฌ ๊ธฐ์ค (๊ฐ์ฅ ์ค์)
๊ณตํต ์ปดํฌ๋ํธ๋ ์๋ 3๊ฐ์ง ์กฐ๊ฑด์ ๋ง์กฑํ ๋ ๋ง๋ ๋ค.
- 3๋ฒ ์ด์ ๋ฐ๋ณต๋๋ค
- ๋์์ธ์ด ๋์ผํ๋ค
- props๋ก ์ ์ด ๊ฐ๋ฅํ๋ค
๐ 3๊ฐ ๋ชจ๋ YES์ผ ๋๋ง ๋ง๋ ๋ค.
๐งฉ ์ปดํฌ๋ํธ ์ข ๋ฅ
1๏ธโฃ UI ์ปดํฌ๋ํธ (๊ณตํต)
- Button
- Card
- Input
- ProgressBar
๐ ํน์ง:
- ์ฌ์ฌ์ฉ ๊ฐ๋ฅ
- ์คํ์ผ ์ค์ฌ
- ๋ก์ง ๊ฑฐ์ ์์
2๏ธโฃ ๋๋ฉ์ธ ์ปดํฌ๋ํธ (์๋น์ค ์ ์ฉ)
- ResultCard
- QuestionCard
- MatchSection
๐ ํน์ง:
- ํน์ ๊ธฐ๋ฅ ํฌํจ
- ํด๋น ์๋น์ค์์๋ง ์ฌ์ฉ
๐จ Button ์ปดํฌ๋ํธ ์ค๊ณ (์ค์ ์์)
๐ Button.jsx
export default function Button({
variant = "primary",
size = "md",
children,
disabled = false,
onClick,
className = "",
}) {
const base =
"rounded-xl font-medium transition active:scale-95";
const variants = {
primary: "bg-yellow-400 text-black",
secondary: "bg-gray-200 text-black",
danger: "bg-red-500 text-white",
outline: "border border-gray-300 text-black",
};
const sizes = {
sm: "px-3 py-1 text-sm",
md: "px-4 py-2 text-base",
lg: "px-5 py-3 text-lg",
};
const disabledStyle = disabled
? "opacity-50 cursor-not-allowed"
: "";
return (
<button
onClick={onClick}
disabled={disabled}
className={`${base} ${variants[variant]} ${sizes[size]} ${disabledStyle} ${className}`}
>
{children}
</button>
);
}
๐ ์ฌ์ฉ ์์
<Button variant="primary">์์ํ๊ธฐ</Button>
<Button variant="danger">์ญ์ </Button>
<Button variant="outline">์ทจ์</Button>
<Button size="lg">ํฐ ๋ฒํผ</Button>
๐ด Card ์ปดํฌ๋ํธ
export default function Card({ children, className = "" }) {
return (
<div className={`bg-white rounded-2xl shadow-md p-4 ${className}`}>
{children}
</div>
);
}
๐ง ResultCard (๋๋ฉ์ธ ์ปดํฌ๋ํธ)
import Card from "../common/Card";
export default function ResultCard({ bread, description, mbti }) {
return (
<Card className="text-center">
<h2 className="text-xl font-bold">{bread}</h2>
<p className="mt-2 text-sm text-gray-600">{description}</p>
<span className="mt-3 inline-block text-xs bg-gray-100 px-2 py-1 rounded">
{mbti}
</span>
</Card>
);
}
๐ ํด๋ ๊ตฌ์กฐ
components/
common/
Button.jsx
Card.jsx
ProgressBar.jsx
domain/
ResultCard.jsx
QuestionCard.jsx
โ ๏ธ ํ์ง ๋ง์์ผ ํ ๊ฒ
โ ๋ชจ๋ ์์๋ฅผ ์ปดํฌ๋ํธํ
โ ์คํ์ผ์ props๋ก ๋ฌดํ ํ์ฅ
โ ๊ณตํตํ ๊ธฐ์ค ์์ด ๋ถ๋ฆฌ
๐ ๊ณผํ ์ถ์ํ๋ ์คํ๋ ค ์ ์ง๋ณด์๋ฅผ ์ด๋ ต๊ฒ ๋ง๋ ๋ค.
๐ก ์ค์ ํ
- ์คํ์ผ์ variant๋ก ๊ด๋ฆฌ
- ๋ ์ด์์์ className์ผ๋ก ๋ฎ์ด์ฐ๊ธฐ
- ์ฒ์๋ถํฐ ๋ง๋ค์ง ๋ง๊ณ ๋ฐ๋ณต๋๋ฉด ๋ถ๋ฆฌ
๐ ํ์ค ์ ๋ฆฌ
๐ โ๊ณตํต ์ปดํฌ๋ํธ๋ ๋ฏธ๋ฆฌ ๋ง๋๋ ๊ฒ ์๋๋ผ, ๋ฐ๋ณต๋ ๋ ๋ฝ๋ ๊ฒ์ด๋ค.โ