|
| 1 | +import { Meta, StoryObj } from "@storybook/react"; |
| 2 | + |
| 3 | +import typography from "./typography"; |
| 4 | + |
| 5 | +const meta: Meta<typeof Text> = { |
| 6 | + title: "Design Tokens/Typography", |
| 7 | + component: Text, |
| 8 | + argTypes: { |
| 9 | + typography: { |
| 10 | + control: { |
| 11 | + type: "radio", |
| 12 | + // radio label을 mm-semantic-typography-h1에서 h1로 변경 |
| 13 | + labels: Object.fromEntries( |
| 14 | + Object.entries(typography.$semantic).map(([key, value]) => [ |
| 15 | + value, |
| 16 | + key, |
| 17 | + ]), |
| 18 | + ), |
| 19 | + }, |
| 20 | + options: Object.values(typography.$semantic), |
| 21 | + }, |
| 22 | + }, |
| 23 | +}; |
| 24 | + |
| 25 | +export default meta; |
| 26 | + |
| 27 | +type Story = StoryObj<typeof Text>; |
| 28 | + |
| 29 | +export const Variants: Story = { |
| 30 | + args: { |
| 31 | + typography: typography.$semantic.body1Bold, |
| 32 | + children: "Git challenge 디자인 시스템", |
| 33 | + }, |
| 34 | +}; |
| 35 | + |
| 36 | +export const Overview: Story = { |
| 37 | + parameters: { |
| 38 | + controls: { exclude: ["typography", "children"] }, |
| 39 | + }, |
| 40 | + // render: () => {} 처럼 매개변수가 없으면, controls 필터링 기능이 동작하지 않는 문제가 있음 |
| 41 | + // https://github.com/storybookjs/storybook/issues/23343#issuecomment-1627351756 |
| 42 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 43 | + render: (_) => ( |
| 44 | + <div style={{ display: "flex", flexDirection: "column", gap: "6px" }}> |
| 45 | + {Object.entries(typography.$semantic).map(([key, value]) => ( |
| 46 | + <Text typography={value} key={key}> |
| 47 | + {key} |
| 48 | + </Text> |
| 49 | + ))} |
| 50 | + </div> |
| 51 | + ), |
| 52 | +}; |
| 53 | + |
| 54 | +type TypographySementicKey = keyof typeof typography.$semantic; |
| 55 | + |
| 56 | +interface TextProps<Key extends TypographySementicKey> { |
| 57 | + typography: (typeof typography.$semantic)[Key]; |
| 58 | + children: string; |
| 59 | +} |
| 60 | + |
| 61 | +function Text<Key extends TypographySementicKey>({ |
| 62 | + typography: className, |
| 63 | + children, |
| 64 | +}: TextProps<Key>) { |
| 65 | + return <div className={className}>{children}</div>; |
| 66 | +} |
0 commit comments