-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
176 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { vstack } from "../../../styled-system/patterns"; | ||
import { fontSizes } from "../../tokens/typography"; | ||
import { Heading } from "./Heading"; | ||
|
||
const meta = { | ||
component: Heading, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
args: { | ||
children: "제목", | ||
level: 2, | ||
}, | ||
} satisfies Meta<typeof Heading>; | ||
|
||
export default meta; | ||
|
||
export const Basic: StoryObj<typeof meta> = {}; | ||
|
||
export const Levels: StoryObj<typeof meta> = { | ||
render: (args) => { | ||
return ( | ||
<div className={vstack({ gap: "6" })}> | ||
<Heading {...args} level={1}> | ||
1 단계 제목 | ||
</Heading> | ||
<Heading {...args} level={2}> | ||
2 단계 제목 | ||
</Heading> | ||
<Heading {...args} level={3}> | ||
3 단계 제목 | ||
</Heading> | ||
<Heading {...args} level={4}> | ||
4 단계 제목 | ||
</Heading> | ||
<Heading {...args} level={5}> | ||
5 단계 제목 | ||
</Heading> | ||
<Heading {...args} level={6}> | ||
6 단계 제목 | ||
</Heading> | ||
</div> | ||
); | ||
}, | ||
parameters: { | ||
controls: { disable: true }, | ||
}, | ||
}; | ||
|
||
export const Sizes: StoryObj<typeof meta> = { | ||
render: (args) => { | ||
return ( | ||
<div className={vstack({ gap: "1" })}> | ||
{Object.keys(fontSizes).map((size) => ( | ||
<Heading {...args} size={size as keyof typeof fontSizes}> | ||
{size} 제목 | ||
</Heading> | ||
))} | ||
</div> | ||
); | ||
}, | ||
parameters: { | ||
controls: { disable: true }, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { composeStories } from "@storybook/react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { expect, test } from "vitest"; | ||
import * as stories from "./Heading.stories"; | ||
|
||
const { Basic } = composeStories(stories); | ||
|
||
test("renders the text content", () => { | ||
render(<Basic>제목</Basic>); | ||
|
||
const heading = screen.getByRole("heading"); | ||
|
||
expect(heading).toHaveTextContent("제목"); | ||
}); | ||
|
||
test.each([1, 2, 3, 4, 5, 6] as const)("use the correct level %s", (level) => { | ||
render(<Basic level={level} />); | ||
|
||
expect(screen.getByRole("heading", { level })).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { cva } from "../../../styled-system/css"; | ||
import { fontSizes, fontWeights } from "../../tokens/typography"; | ||
|
||
export interface HeadingProps extends React.HTMLAttributes<HTMLHeadingElement> { | ||
/** 텍스트 */ | ||
children: React.ReactNode | string; | ||
/** 단계 */ | ||
level?: 1 | 2 | 3 | 4 | 5 | 6; | ||
/** 크기 */ | ||
size?: keyof typeof fontSizes; | ||
/** 굵기 */ | ||
weight?: keyof typeof fontWeights; | ||
/** 명암비 */ | ||
// contrast?: "low" | "high"; | ||
} | ||
|
||
export const Heading = ({ | ||
children, | ||
level, | ||
size = "3xl", | ||
weight = "bold", | ||
// contrast = "low", | ||
...rest | ||
}: HeadingProps) => { | ||
if (!level) { | ||
throw new Error( | ||
"The level prop is required and you can cause accessibility issues." | ||
); | ||
} | ||
|
||
const Tag = `h${level}` as const; | ||
|
||
return ( | ||
<Tag className={style({ size, weight })} {...rest}> | ||
{children} | ||
</Tag> | ||
); | ||
}; | ||
|
||
const style = cva({ | ||
variants: { | ||
size: Object.fromEntries( | ||
Object.keys(fontSizes).map((key) => [key, { fontSize: key }]) | ||
), | ||
weight: Object.fromEntries( | ||
Object.keys(fontWeights).map((key) => [key, { fontWeight: key }]) | ||
), | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
@layer reset, base, tokens, recipes, utilities; | ||
@import url(//spoqa.github.io/spoqa-han-sans/css/SpoqaHanSansNeo.css); | ||
@import url(https://spoqa.github.io/spoqa-han-sans/css/SpoqaHanSansNeo.css); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters