Skip to content

Commit

Permalink
feat: Heading 컴포넌트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
xodms0309 committed Apr 14, 2024
1 parent 5cc35ed commit 7eed305
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/Common/Typography/Heading/Heading.stories.tsx
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 = {};
28 changes: 28 additions & 0 deletions src/components/Common/Typography/Heading/Heading.tsx
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;

0 comments on commit 7eed305

Please sign in to comment.