Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PEAUTY-42] 태그 컴포넌트 생성 #8

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/components/global/Tag/Tag.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Meta, StoryObj } from "@storybook/react";
import { Tag } from "./Tag";
import { colors } from "../../../style/color";

// Storybook 메타데이터 설정
const meta: Meta<typeof Tag> = {
title: "Components/Tag", // Storybook에서의 위치
component: Tag,
parameters: {
layout: "centered", // 컴포넌트를 중앙에 배치
},
tags: ["autodocs"], // 자동 문서화 태그
};

export default meta;
type Story = StoryObj<typeof Tag>;

// 기본 태그
export const Default: Story = {
args: {
children: "기본 태그", // children으로 전달
},
};

// 커스텀 색상 태그
export const CustomColorTag: Story = {
args: {
children: "커스텀 색상 태그", // children으로 전달
color: {
backgroundColor: colors.white, // 황금색 배경
borderColor: colors.gray300, // 주황색 테두리
fontColor: colors.gray300, // 흰색 폰트
},
},
};

// 길이가 긴 태그
export const LongTag: Story = {
args: {
children: "문자가 기이이이인 태그", // children으로 전달
},
};
26 changes: 26 additions & 0 deletions src/components/global/Tag/Tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import styled from "styled-components";
import { colors } from "../../../style/color";
import { typography } from "../../../style/typography";

interface TagProps {
// tagName은 이제 children으로 대체됩니다.
color?: {
backgroundColor?: string;
borderColor?: string;
fontColor?: string;
};
}

const TagWrapper = styled.div<TagProps>`
color: ${({ color }) => color?.fontColor || colors.blue200}; /* 폰트 색상 */
border: 1px solid ${({ color }) => color?.borderColor || colors.blue200}; /* border 색상 */
border-radius: 5px;
background-color: ${({ color }) => color?.backgroundColor || colors.blue100}; /* 배경 색상 */
font-size: ${typography.body6};
padding: 3px 10px;
font-weight: 500;
`;

export function Tag({ children, color }: React.PropsWithChildren<TagProps>) {
return <TagWrapper color={color}>{children}</TagWrapper>;
}
Loading