Skip to content

Commit

Permalink
Gmmq 147 feat: Badge 공통 컴포넌트 개발 (#9)
Browse files Browse the repository at this point in the history
* feat: 차크라UI 스토리북 애드온 설치 및 적용

* chore: 예시 스토리북 컴포넌트 Button 제거

* feat: Badge 컴포넌트 차크라UI + 스토리북 테스트

* feat: Badge 공통 컴포넌트

* fix: eslint 설정 - react/no-unescaped-entities 비활성화

* feat: Badge 컴포넌트 내보내기
  • Loading branch information
khakhiD authored Oct 27, 2023
1 parent d799b08 commit 8b0337a
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 96 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
rules: {
'no-console': 'warn',
'react/react-in-jsx-scope': 'off',
'react/no-unescaped-entities': 0,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'import/order': [
'warn',
Expand Down
7 changes: 6 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
stories: [
'../src/**/*.mdx',
'../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
'../src/components/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-onboarding',
'@storybook/addon-interactions',
'@chakra-ui/storybook-addon',
],
framework: {
name: '@storybook/react-vite',
Expand Down
4 changes: 4 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Preview } from '@storybook/react';
import theme from '../src/theme/index';

const preview: Preview = {
parameters: {
Expand All @@ -9,6 +10,9 @@ const preview: Preview = {
date: /Date$/i,
},
},
chakra: {
theme,
},
},
};

Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"zustand": "^4.4.3"
},
"devDependencies": {
"@chakra-ui/storybook-addon": "^5.0.1",
"@storybook/addon-essentials": "^7.5.0",
"@storybook/addon-interactions": "^7.5.0",
"@storybook/addon-links": "^7.5.0",
Expand Down
45 changes: 45 additions & 0 deletions src/components/atoms/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Badge as ChakraBadge, BadgeProps as ChakraBadgeProps, Text } from '@chakra-ui/react';
import { ReactNode } from 'react';

type BadgeProps = ChakraBadgeProps & {
children: ReactNode;
type?: 'mentor' | 'mentee' | 'default';
};

const Badge = ({
children,
px = '1.5',
py = '1',
bg = 'gray.300',
color = 'gray.800',
type = 'default',
...props
}: BadgeProps) => {
const BADGE_TYPE_COLOR = {
default: {
color,
bg,
},
mentor: {
color: 'gray.100',
bg: 'highlight.500',
},
mentee: {
color: 'primary.800',
bg: 'primary.100',
},
};
return (
<ChakraBadge
bg={BADGE_TYPE_COLOR[type].bg}
px={px}
py={py}
borderRadius={'base'}
{...props}
>
<Text color={BADGE_TYPE_COLOR[type].color}>{children}</Text>
</ChakraBadge>
);
};

export default Badge;
49 changes: 49 additions & 0 deletions src/components/atoms/Badge/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { Meta, StoryObj } from '@storybook/react';
import Badge from './Badge';

const meta = {
title: 'Resumeme/Components/Badge',
component: Badge,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
color: { control: 'color' },
bg: { control: 'color' },
children: { control: 'text' },
},
} satisfies Meta<typeof Badge>;

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

export const Default: Story = {
args: {
children: '기본',
type: 'default',
},
};

export const DefaultCustom: Story = {
args: {
children: '기본2',
type: 'default',
bg: '#191F28',
color: '#FFFFFF',
},
};

export const Mentee: Story = {
args: {
children: '멘티',
type: 'mentee',
},
};

export const Mentor: Story = {
args: {
children: '멘토',
type: 'mentor',
},
};
1 change: 1 addition & 0 deletions src/components/atoms/Badge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Badge } from './Badge';
45 changes: 0 additions & 45 deletions src/components/atoms/Button/Button.tsx

This file was deleted.

50 changes: 0 additions & 50 deletions src/components/atoms/Button/index.stories.ts

This file was deleted.

Empty file.

0 comments on commit 8b0337a

Please sign in to comment.