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(system): Text에 typography스타일 추가 #14

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"react": "^18",
"react-dom": "^18",
"tailwind-merge": "^2.4.0",
"tailwind-variants": "^0.2.1",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import { QueryProvider } from '@/lib';
import './globals.css';
import QueryProvider from '@/context/QueryProvider/QueryProvider';

const inter = Inter({ subsets: ['latin'] });

Expand Down
13 changes: 12 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { Text } from '@/system/components';
import { typographyVariant } from '@/system/token/typography';

export default function Home() {
return <div>123</div>;
return (
<>
{typographyVariant.map((typo) => (
<Text typography={typo} key={typo}>
하이하이
</Text>
))}
</>
);
}
10 changes: 2 additions & 8 deletions src/system/components/Text/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use-client';
import { forwardRef } from 'react';
import { useTextStyles } from './styles/useTextStyles';
import type { ComponentProps, ElementType } from 'react';
Expand All @@ -16,14 +17,7 @@ export const Text = forwardRef<HTMLParagraphElement, TextProps>(function Text(
) {
const textStyle = useTextStyles({ typography, className });

return (
<Component
ref={ref}
style={{ color, ...style }}
{...textStyle.paragraph}
{...restProps}
/>
);
return <Component ref={ref} style={{ color, ...style }} {...textStyle.paragraph} {...restProps} />;
});

Text.displayName = 'Text';
45 changes: 45 additions & 0 deletions src/system/components/Text/styles/typography.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Typography } from '@/system/token/typography/index';

// NOTE: px정보를 typography token에서 직접 가져올 경우 tailwind에서 인식하지 못하는 문제가 있어 임시적으로 값을 넣어놓습니다.
// FIXME: 추후 수정해야합니다.
export const fontSize: Record<Typography, `text-[${number}px]`> = {
Comment on lines +3 to +5
Copy link
Member Author

Choose a reason for hiding this comment

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

이런 문제가 있어, typography의 토큰을 복사해서 임시파일을 만들어 유지하였어요. 다른 해결책이 있다면 말씀주세요!

Copy link
Member

Choose a reason for hiding this comment

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

혹시 NOTE에 대해 조금 더 설명해주실 수 있을까요??

className을 prop으로 넘겨주는 과정에서 오류가 난다는 말씀일까요??

Copy link
Member Author

Choose a reason for hiding this comment

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

이게 검색을 좀 해보니 tailwind특성상 중간에 text-${something} 이런식으로 끼워넣으면 인식하지 못하는 것 같아요.
우선 컴포넌트를 사용하는 것이 급할 것 같아서 임시로 대응해두었습니닷..!

title1: 'text-[36px]',
title2: 'text-[28px]',
title3: 'text-[24px]',
heading1: 'text-[20px]',
heading2: 'text-[18px]',
body1: 'text-[16px]',
body2: 'text-[15px]',
label1: 'text-[14px]',
label2: 'text-[13px]',
caption1: 'text-[12px]',
caption2: 'text-[11px]',
} as const;

export const lineHeight: Record<Typography, `leading-[${number}px]`> = {
title1: 'leading-[48px]',
title2: 'leading-[38px]',
title3: 'leading-[32px]',
heading1: 'leading-[28px]',
heading2: 'leading-[26px]',
body1: 'leading-[24px]',
body2: 'leading-[22px]',
label1: 'leading-[20px]',
label2: 'leading-[18px]',
caption1: 'leading-[16px]',
caption2: 'leading-[14px]',
} as const;

export const letterSpacing: Record<Typography, `tracking-[${number}em]`> = {
title1: 'tracking-[-0.027em]',
title2: 'tracking-[-0.0236em]',
title3: 'tracking-[-0.023em]',
heading1: 'tracking-[-0.012em]',
heading2: 'tracking-[-0.002em]',
body1: 'tracking-[0.0057em]',
body2: 'tracking-[0.0096em]',
label1: 'tracking-[0.0145em]',
label2: 'tracking-[0.0194em]',
caption1: 'tracking-[0.0252em]',
caption2: 'tracking-[0.0311em]',
} as const;
11 changes: 4 additions & 7 deletions src/system/components/Text/styles/useTextStyles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clsx } from 'clsx';
import { textVariants } from './variants';
import { paragraphVariants } from './variants';
import type { Typography } from '@/system/token/typography';
import type { TextAnatomy } from '../anatomy';

Expand All @@ -8,15 +8,12 @@ interface Props {
typography: Typography;
}

export function useTextStyles({
className,
typography,
}: Props): Record<TextAnatomy, { className: string }> {
const styleVariants = textVariants({ typography });
export function useTextStyles({ className, typography }: Props): Record<TextAnatomy, { className: string }> {
const paragraphStyle = paragraphVariants({ typography });

return {
paragraph: {
className: clsx(className, styleVariants),
className: clsx(className, paragraphStyle),
},
};
}
14 changes: 5 additions & 9 deletions src/system/components/Text/styles/variants.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { typographyVariant } from '@/system/token/typography';
import { tv } from 'tailwind-variants';
import { cva } from 'class-variance-authority';
import type { Typography } from '@/system/token/typography';
import { fontSize, lineHeight, letterSpacing } from '@/system/components/Text/styles/typography';

export const textVariants = tv({
base: 'm-0',
slots: {
paragraph: [],
},
export const paragraphVariants = cva(['m-0'], {
variants: {
typography: typographyVariant.reduce(
(acc, typography) => {
// TODO: fontsize, fontweight, lineheight등 tailwind정보 추가
acc[typography] = [];
acc[typography] = [fontSize[typography], lineHeight[typography], letterSpacing[typography]];
return acc;
},
{} as Record<Typography, []>,
{} as Record<Typography, string[]>,
),
},
});
83 changes: 51 additions & 32 deletions src/system/token/typography/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,57 @@
export const typographyVariant = [
'Display1',
'Display2',
'Title1',
'Title2',
'Title3',
'Heading1',
'Heading2',
'Headline1',
'Headline2',
'Body1',
'Body2',
'Label1',
'Label2',
'Caption1',
'Caption2',
'title1',
'title2',
'title3',
'heading1',
'heading2',
'body1',
'body2',
'label1',
'label2',
'caption1',
'caption2',
] as const;

export type Typography = (typeof typographyVariant)[number];

// TODO: 자간 / 행간 높이 설정
export const fontSize: Record<Typography, number> = {
Display1: 56,
Display2: 40,
Title1: 36,
Title2: 28,
Title3: 24,
Heading1: 22,
Heading2: 20,
Headline1: 18,
Headline2: 17,
Body1: 16,
Body2: 15,
Label1: 14,
Label2: 13,
Caption1: 12,
Caption2: 11,
export const fontSize: Record<Typography, `${number}px`> = {
title1: '36px',
title2: '28px',
title3: '24px',
Comment on lines 16 to +20
Copy link
Member Author

Choose a reason for hiding this comment

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

letter-spacing은 em단위를 가지고 있어 px, em단위를 명시해줍니다

Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 tailwind.config에서 작성된 extend로 해결되지 않는 부분인걸까요-??

Copy link
Member Author

@qkrdmstlr3 qkrdmstlr3 Jul 22, 2024

Choose a reason for hiding this comment

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

토큰을 어딘가에 정의해둘 필요는 있다고 생각해서 파일로 만들어두었어요.
이것도 추후 tailwind.config에 통합될 예정입니다! 시간이 없어서.. 우선 asap으로 처리합니다..

Copy link
Collaborator

Choose a reason for hiding this comment

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

tailwind.config 얘기가 나와서 그런데,
이미 컴포넌트 만들어주신 시점에 너무 늦은 제안이긴 하지만,, 사실 tailwind 설정만 잘 해주면 Text 컴포넌트가 아예 필요 없을수도 있지 않을까 생각하는데,, 이 부분은 어떻게 생각하시나요!?

Copy link
Member Author

Choose a reason for hiding this comment

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

엇 그렇네요? ㅋㅋㅋㅋㅋ
색상을 강제하고 있지도 않아서, 불필요한 컴포넌트가 될 수 있겠군요. 동의합니다!!

heading1: '20px',
heading2: '18px',
body1: '16px',
body2: '15px',
label1: '14px',
label2: '13px',
caption1: '12px',
caption2: '11px',
} as const;

export const lineHeight: Record<Typography, `${number}px`> = {
title1: '48px',
title2: '38px',
title3: '32px',
heading1: '28px',
heading2: '26px',
body1: '24px',
body2: '22px',
label1: '20px',
label2: '18px',
caption1: '16px',
caption2: '14px',
} as const;

export const letterSpacing: Record<Typography, `${number}em`> = {
title1: '-0.027em',
title2: '-0.0236em',
title3: '-0.023em',
heading1: '-0.012em',
heading2: '-0.002em',
body1: '0.0057em',
body2: '0.0096em',
label1: '0.0145em',
label2: '0.0194em',
caption1: '0.0252em',
caption2: '0.0311em',
} as const;
Loading