-
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
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/components/Common/Typography/Heading/Heading.stories.tsx
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 type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import Heading from './Heading'; | ||
|
||
const meta: Meta<typeof Heading> = { | ||
title: 'common/Heading', | ||
component: Heading, | ||
args: { | ||
children: '안녕하세요 펀잇입니다.', | ||
color: 'default', | ||
size: 'body', | ||
weight: 'regular', | ||
as: 'h1', | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = {}; |
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,28 @@ | ||
import cx from 'classnames'; | ||
import type { ElementType } from 'react'; | ||
|
||
import { typography } from '../typography.css'; | ||
import type { OverridableComponentPropsWithoutRef, TypographyVariants } from '../typography.types'; | ||
|
||
type HeadingElement = Extract<ElementType, 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'>; | ||
type HeadingProps<T extends HeadingElement> = OverridableComponentPropsWithoutRef<T, TypographyVariants>; | ||
|
||
const Heading = <T extends HeadingElement = 'h1'>({ | ||
children, | ||
size = 'body', | ||
weight = 'regular', | ||
color = 'default', | ||
as, | ||
className, | ||
...props | ||
}: HeadingProps<T>) => { | ||
const Component = as || 'h1'; | ||
|
||
return ( | ||
<Component className={cx(typography({ color, size, weight }), className)} {...props}> | ||
{children} | ||
</Component> | ||
); | ||
}; | ||
|
||
export default Heading; |