Skip to content

Commit

Permalink
refactor: Typography 폴더로 Text 컴포넌트 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
xodms0309 committed Apr 14, 2024
1 parent a56add6 commit 5cc35ed
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
26 changes: 0 additions & 26 deletions src/components/Common/Text/Text.tsx

This file was deleted.

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: {
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>;
2 changes: 1 addition & 1 deletion src/components/Common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ 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';

0 comments on commit 5cc35ed

Please sign in to comment.