Skip to content

Commit 361c9a4

Browse files
authored
Feat(design-system): 레벨 컴포넌트 (#36)
* feat: 레벨 뱃지 컴포넌트 * feat: 스토리북 코드 도입 * fix: 기본 코드 세팅 복구 * feat: 스토리북 수정 * chore: 스토리북 초기 세팅 중복 삭제
1 parent fc5ee9d commit 361c9a4

File tree

11 files changed

+204
-3
lines changed

11 files changed

+204
-3
lines changed

.storybook/main.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { StorybookConfig } from '@storybook/react-vite';
2+
3+
import { join, dirname } from "path"
4+
5+
/**
6+
* This function is used to resolve the absolute path of a package.
7+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
8+
*/
9+
function getAbsolutePath(value: string): any {
10+
return dirname(require.resolve(join(value, 'package.json')))
11+
}
12+
const config: StorybookConfig = {
13+
"stories": [
14+
"../stories/**/*.mdx",
15+
"../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"
16+
],
17+
"addons": [
18+
getAbsolutePath('@chromatic-com/storybook'),
19+
getAbsolutePath('@storybook/addon-docs'),
20+
getAbsolutePath("@storybook/addon-a11y"),
21+
getAbsolutePath("@storybook/addon-vitest")
22+
],
23+
"framework": {
24+
"name": getAbsolutePath('@storybook/react-vite'),
25+
"options": {}
26+
}
27+
};
28+
export default config;

.storybook/preview.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Preview } from '@storybook/react-vite';
2+
3+
const preview: Preview = {
4+
parameters: {
5+
controls: {
6+
matchers: {
7+
color: /(background|color)$/i,
8+
date: /Date$/i,
9+
},
10+
},
11+
12+
a11y: {
13+
// 'todo' - show a11y violations in the test UI only
14+
// 'error' - fail CI on a11y violations
15+
// 'off' - skip a11y checks entirely
16+
test: 'todo',
17+
},
18+
},
19+
};
20+
21+
export default preview;

.storybook/vitest.setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as a11yAddonAnnotations from "@storybook/addon-a11y/preview";
2+
import { setProjectAnnotations } from '@storybook/react-vite';
3+
import * as projectAnnotations from './preview';
4+
5+
// This is an important step to apply the right configuration when testing your stories.
6+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
7+
setProjectAnnotations([a11yAddonAnnotations, projectAnnotations]);

apps/client/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function App() {
1616
<img src={reactLogo} className="logo react" alt="React logo" />
1717
</a>
1818
</div>
19-
<h1>Vite + React</h1>
19+
<h1>Vite + React</h1>\
2020
<div className="card">
2121
<button onClick={() => setCount((count) => count + 1)}>
2222
count is {count}

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,28 @@
77
"lint": "turbo run lint",
88
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
99
"check-types": "turbo run check-types",
10-
"test": "turbo run test"
10+
"test": "turbo run test",
11+
"storybook": "storybook dev -p 6006",
12+
"build-storybook": "storybook build"
1113
},
1214
"devDependencies": {
15+
"@chromatic-com/storybook": "^4.1.1",
1316
"@pivanov/vite-plugin-svg-sprite": "^3.1.3",
17+
"@storybook/addon-a11y": "^9.1.3",
18+
"@storybook/addon-docs": "^9.1.3",
19+
"@storybook/addon-vitest": "^9.1.3",
20+
"@storybook/react-vite": "^9.1.3",
1421
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
1522
"prettier": "^3.6.2",
1623
"prettier-plugin-tailwindcss": "^0.6.14",
24+
"storybook": "^9.1.3",
1725
"turbo": "^2.5.6",
1826
"typescript": "5.9.2",
19-
"vite": "7.1.2"
27+
"vite": "7.1.2",
28+
"vitest": "^3.2.4",
29+
"@vitest/browser": "^3.2.4",
30+
"playwright": "^1.55.0",
31+
"@vitest/coverage-v8": "^3.2.4"
2032
},
2133
"pnpm": {
2234
"overrides": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { default as Button } from './button/Button';
22
export { Switch } from './switch/Switch';
33
export { default as Input } from './input/Input';
4+
export { default as Level } from './level/Level';
45
export { Textarea } from './textarea/Textarea';
56
export { Progress } from './progress/Progress';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Meta, StoryObj } from '@storybook/react-vite';
2+
import Level from './Level';
3+
4+
const meta: Meta<typeof Level> = {
5+
title: 'Components/Level',
6+
component: Level,
7+
tags: ['autodocs'],
8+
parameters: {
9+
layout: 'centered',
10+
},
11+
argTypes: {
12+
level: {
13+
control: { type: 'number', min: 1, max: 100 },
14+
description: '현재 레벨 값',
15+
},
16+
},
17+
};
18+
export default meta;
19+
20+
type Story = StoryObj<typeof Level>;
21+
22+
// 기본 예시
23+
export const Default: Story = {
24+
args: {
25+
level: 1,
26+
},
27+
};
28+
29+
export const Level10: Story = {
30+
args: {
31+
level: 10,
32+
},
33+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
interface LevelProps {
2+
level: number;
3+
}
4+
const Level = ({ level }: LevelProps) => {
5+
return (
6+
<span className="caption2-sb text-main600 bg-main100 rounded-[0.4rem] px-[0.8rem] py-[0.2rem]">
7+
Lv.{level}
8+
</span>
9+
);
10+
};
11+
12+
export default Level;

pnpm-lock.yaml

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitest.config.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
4+
import { defineConfig } from 'vitest/config';
5+
6+
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
7+
8+
const dirname =
9+
typeof __dirname !== 'undefined'
10+
? __dirname
11+
: path.dirname(fileURLToPath(import.meta.url));
12+
13+
// More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
14+
export default defineConfig({
15+
test: {
16+
projects: [
17+
{
18+
extends: true,
19+
plugins: [
20+
// The plugin will run tests for the stories defined in your Storybook config
21+
// See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
22+
storybookTest({ configDir: path.join(dirname, '.storybook') }),
23+
],
24+
test: {
25+
name: 'storybook',
26+
browser: {
27+
enabled: true,
28+
headless: true,
29+
provider: 'playwright',
30+
instances: [{ browser: 'chromium' }],
31+
},
32+
setupFiles: ['.storybook/vitest.setup.ts'],
33+
},
34+
},
35+
],
36+
},
37+
});

0 commit comments

Comments
 (0)