-
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
213 additions
and
82 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,48 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { vstack } from "../../../styled-system/patterns"; | ||
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 }, | ||
}, | ||
}; |
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,61 @@ | ||
import { css } from "../../../styled-system/css"; | ||
import type { TextStyle, FontSize, FontWeight } from "../../tokens/typography"; | ||
|
||
type Level = 1 | 2 | 3 | 4 | 5 | 6; | ||
|
||
export interface HeadingProps extends React.HTMLAttributes<HTMLHeadingElement> { | ||
/** 텍스트 */ | ||
children: React.ReactNode | string; | ||
/** 단계 */ | ||
level?: Level; | ||
/** 크기 */ | ||
size?: FontSize; | ||
/** 굵기 */ | ||
weight?: FontWeight; | ||
/** 명암비 */ | ||
// contrast?: "low" | "high"; | ||
} | ||
|
||
const textStyles: Record<Level, TextStyle> = { | ||
1: "4xl", | ||
2: "3xl", | ||
3: "2xl", | ||
4: "xl", | ||
5: "lg", | ||
6: "md", | ||
}; | ||
|
||
/** | ||
* - `level` 속성을 통해서 `<h1>`, `<h2>`, `<h3>`, `<h4>`, `<h5>`, `<h6>` 요소 중 하나를 선택할 수 있습니다. | ||
* - `level` 속성은 단계 별 기본 텍스트 스타일을 제공합니다. | ||
* - `size` 속성과 `weight` 속성을 통해서 기본 스타일을 변경할 수 있습니다. | ||
*/ | ||
export const Heading = ({ | ||
children, | ||
level, | ||
size, | ||
weight, | ||
// 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={css({ | ||
textStyle: textStyles[level], | ||
fontSize: size, | ||
fontWeight: weight, | ||
})} | ||
{...rest} | ||
> | ||
{children} | ||
</Tag> | ||
); | ||
}; |
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