Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Heading 컴포넌트 추가 #87

Merged
merged 7 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/components/Common/Text/Text.tsx

This file was deleted.

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;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react';

import Text from './Text';
import { sizes } from './text.types';
import { sizes } from '../typography.types';

const meta: Meta<typeof Text> = {
title: 'common/Text',
Expand Down
28 changes: 28 additions & 0 deletions src/components/Common/Typography/Text/Text.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';

export type TextElement = Extract<ElementType, 'p' | 'span'>;
type TextProps<T extends TextElement> = OverridableComponentPropsWithoutRef<T, TypographyVariants>;

const Text = <T extends TextElement = 'p'>({
children,
size = 'body',
weight = 'regular',
color = 'default',
as,
className,
...props
}: TextProps<T>) => {
const Component = as || 'p';

return (
<Component className={cx(typography({ color, size, weight }), className)} {...props}>
{children}
</Component>
);
};

export default Text;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const baseText = style({
lineHeight: 1.4,
});

export const text = recipe({
export const typography = recipe({
base: baseText,
variants: {
color: {
Expand All @@ -22,6 +22,7 @@ export const text = recipe({
caption1: { fontSize: '1.4rem' },
body: { fontSize: '1.6rem' },
headline: { fontSize: '1.8rem' },
display1: { fontSize: '2.2rem' },
},
weight: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기에 bold도 추가해주세요~~
700으로 하면 될 듯?!

regular: { fontWeight: 400 },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import type { ElementType, ComponentPropsWithoutRef } from 'react';

import type { text } from './text.css';
import type { typography } from './typography.css';

import type { RecipeVariants } from '@vanilla-extract/recipes';

export const colors = ['default', 'sub', 'info', 'disabled', 'white'] as const;
export const sizes = ['caption4', 'caption3', 'caption2', 'caption1', 'body', 'headline'] as const;
export const sizes = ['caption4', 'caption3', 'caption2', 'caption1', 'body', 'headline', 'display1'] as const;
export const weights = ['regular', 'medium', 'semiBold'] as const;

export type Color = (typeof colors)[number];
export type Size = (typeof sizes)[number];
export type Weight = (typeof weights)[number];

export type TextVariants = RecipeVariants<typeof text>;

export type OverridableComponentPropsWithoutRef<T extends ElementType, P = unknown> = P &
ComponentPropsWithoutRef<T> & { as?: T };
export type TextElement = Extract<ElementType, 'p' | 'span'>;

export type TypographyVariants = RecipeVariants<typeof typography>;
3 changes: 2 additions & 1 deletion src/components/Common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export { default as SelectOptionList } from './SelectOptionList/SelectOptionList
export { default as PageHeader } from './PageHeader/PageHeader';
export { default as Badge } from './Badge/Badge';
export { default as WriteButton } from './WriteButton/WriteButton';
export { default as Text } from './Text/Text';
export { default as Text } from './Typography/Text/Text';
export { default as Heading } from './Typography/Heading/Heading';