Skip to content

Commit

Permalink
add contrast prop to heading component
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleSeo committed Jan 9, 2025
1 parent 676d8f8 commit 958b857
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 22 deletions.
34 changes: 31 additions & 3 deletions src/components/Heading/Heading.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const meta = {
},
args: {
children: "์ œ๋ชฉ",
level: 2,
level: 1,
},
} satisfies Meta<typeof Heading>;

Expand Down Expand Up @@ -42,7 +42,35 @@ export const Levels: StoryObj<typeof meta> = {
</div>
);
},
parameters: {
controls: { disable: true },
argTypes: {
children: {
control: false,
},
level: {
control: false,
},
},
};

export const Contrasts: StoryObj<typeof meta> = {
render: (args) => {
return (
<div className={vstack({ gap: "6" })}>
<Heading {...args} contrast="low">
๋‚ฎ์€ ๋ช…์•”๋น„
</Heading>
<Heading {...args} contrast="high">
๋†’์€ ๋ช…์•”๋น„
</Heading>
</div>
);
},
argTypes: {
children: {
control: false,
},
contrast: {
control: false,
},
},
};
48 changes: 29 additions & 19 deletions src/components/Heading/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
import { css } from "../../../styled-system/css";
import type { TextStyle, FontSize, FontWeight } from "../../tokens/typography";
import { css, cva } from "../../../styled-system/css";
import type { 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;
level: Level;
/** ํฌ๊ธฐ */
size?: FontSize;
/** ๊ตต๊ธฐ */
weight?: FontWeight;
/** ๋ช…์•”๋น„ */
// contrast?: "low" | "high";
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` ์†์„ฑ์€ ๋‹จ๊ณ„ ๋ณ„ ๊ธฐ๋ณธ ํ…์ŠคํŠธ ์Šคํƒ€์ผ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
Expand All @@ -35,7 +26,7 @@ export const Heading = ({
level,
size,
weight,
// contrast = "low",
contrast = "low",
...rest
}: HeadingProps) => {
if (!level) {
Expand All @@ -48,14 +39,33 @@ export const Heading = ({

return (
<Tag
className={css({
textStyle: textStyles[level],
fontSize: size,
fontWeight: weight,
})}
className={css(
style.raw({ level, contrast }),
css.raw({
fontSize: size,
fontWeight: weight,
})
)}
{...rest}
>
{children}
</Tag>
);
};

const style = cva({
variants: {
level: {
1: { textStyle: "4xl" },
2: { textStyle: "3xl" },
3: { textStyle: "2xl" },
4: { textStyle: "xl" },
5: { textStyle: "lg" },
6: { textStyle: "md" },
},
contrast: {
low: { color: "text" },
high: { color: "text.contrast" },
},
},
});

0 comments on commit 958b857

Please sign in to comment.