Skip to content

Commit

Permalink
[Feature/BAR-89] Badge 컴포넌트 구현 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmswl98 authored Jan 8, 2024
1 parent eeeb205 commit 252eaf3
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/components/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Meta, StoryObj } from '@storybook/react';

import Badge from './Badge';
import { BADGE_TYPE } from './constants';

const meta: Meta<typeof Badge> = {
title: 'Components/Badge',
component: Badge,
parameters: {
componentSubtitle: '카테고리를 나타내는 컴포넌트',
},
};

export default meta;

type Story = StoryObj<typeof Badge>;

export const Basic: Story = {
args: {
children: '부탁하기',
color: 'blue',
},
render: (args) => <Badge color={args.color}>{args.children}</Badge>,
};

export const AllBadges: Story = {
render: () => (
<div style={{ display: 'flex', gap: '8px' }}>
<Badge color={BADGE_TYPE['부탁하기']}>부탁하기</Badge>
<Badge color={BADGE_TYPE['보고하기']}>보고하기</Badge>
<Badge color={BADGE_TYPE['축하하기']}>축하하기</Badge>
<Badge color={BADGE_TYPE['위로하기']}>위로하기</Badge>
<Badge color={BADGE_TYPE['감사 전하기']}>감사 전하기</Badge>
<Badge color={BADGE_TYPE['안부 전하기']}>안부 전하기</Badge>
<Badge color={BADGE_TYPE['기타']}>기타</Badge>
</div>
),
};
21 changes: 21 additions & 0 deletions src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { PropsWithChildren } from 'react';

import * as styles from './style.css';

interface BadgeProps {
color:
| 'blue'
| 'green'
| 'yellow'
| 'red'
| 'orange'
| 'purple'
| 'grey'
| 'black';
}

const Badge = ({ children, color }: PropsWithChildren<BadgeProps>) => {
return <span className={styles.badge({ color })}>{children}</span>;
};

export default Badge;
9 changes: 9 additions & 0 deletions src/components/Badge/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const BADGE_TYPE = {
부탁하기: 'blue',
보고하기: 'orange',
축하하기: 'green',
위로하기: 'purple',
'감사 전하기': 'red',
'안부 전하기': 'yellow',
기타: 'black',
} as const;
47 changes: 47 additions & 0 deletions src/components/Badge/style.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { recipe } from '@vanilla-extract/recipes';

import { sprinkles } from '@/src/styles/sprinkles.css';
import { COLORS } from '@/src/styles/tokens';

export const badge = recipe({
base: [
sprinkles({ typography: '13/Title/Semibold' }),
{
display: 'inline-block',
width: 'fit-content',
padding: '6px 8px',
color: COLORS['Grey/White'],
borderRadius: '6px',
whiteSpace: 'nowrap',
},
],
variants: {
color: {
blue: {
backgroundColor: COLORS['Blue/Default'],
},
green: {
backgroundColor: COLORS['Green'],
},
yellow: {
backgroundColor: COLORS['Yellow'],
},
red: {
backgroundColor: COLORS['LightRed'],
},
orange: {
backgroundColor: COLORS['Orange'],
},
purple: {
backgroundColor: COLORS['Purple'],
},
grey: {
color: COLORS['Grey/250'],
backgroundColor: COLORS['Grey/600'],
},
black: {
backgroundColor: COLORS['Grey/800'],
},
},
},
});
6 changes: 6 additions & 0 deletions src/styles/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export const TYPOGRAPHY = {
lineHeight: '14px',
letterSpacing: '0px',
},
'11/Caption/Regular': {
fontSize: '11px',
fontWeight: FONT_WEIGHT.regular,
lineHeight: '14px',
letterSpacing: '-0.3px',
},
};

export const COLORS = {
Expand Down

0 comments on commit 252eaf3

Please sign in to comment.