-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: css 초기화 코드 추가 * feat: Text 컴포넌트 생성 * design: tailwind 적용 * refactor: 코드 리뷰 반영
- Loading branch information
Showing
3 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
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
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,83 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import Text from './Text'; | ||
|
||
const meta: Meta<typeof Text> = { | ||
title: 'Components/ui/Text', | ||
component: Text, | ||
tags: ['autodocs'], | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
argTypes: { | ||
children: { | ||
defaultValue: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
control: { type: 'text' }, | ||
}, | ||
size: { | ||
defaultValue: 'md', | ||
options: ['xs', 'sm', 'md', 'lg', 'xl'], | ||
control: { type: 'select' }, | ||
}, | ||
weight: { | ||
defaultValue: 'regular', | ||
options: ['light', 'regular', 'bold'], | ||
control: { type: 'inline-radio' }, | ||
}, | ||
underline: { | ||
defaultValue: false, | ||
control: { type: 'boolean' }, | ||
}, | ||
block: { | ||
defaultValue: false, | ||
control: { type: 'boolean' }, | ||
}, | ||
transform: { | ||
options: [undefined, 'capitalize', 'uppercase', 'lowercase'], | ||
control: { type: 'inline-radio' }, | ||
}, | ||
align: { | ||
options: [undefined, 'left', 'center', 'right'], | ||
control: { type: 'inline-radio' }, | ||
}, | ||
lineClamp: { | ||
defaultValue: undefined, | ||
control: { type: 'number' }, | ||
}, | ||
color: { | ||
options: [undefined, 'primary', 'black', 'gray', 'white'], | ||
control: { type: 'inline-radio' }, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
size: 'md', | ||
weight: 'regular', | ||
underline: false, | ||
block: false, | ||
transform: undefined, | ||
align: undefined, | ||
lineClamp: undefined, | ||
color: undefined, | ||
}, | ||
}; | ||
|
||
export const Center: Story = { | ||
args: { | ||
children: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
size: 'md', | ||
weight: 'regular', | ||
underline: false, | ||
block: false, | ||
transform: undefined, | ||
align: 'center', | ||
lineClamp: undefined, | ||
color: undefined, | ||
}, | ||
}; |
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,81 @@ | ||
import React from 'react'; | ||
|
||
interface TextProps { | ||
children: React.ReactNode; | ||
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'; | ||
weight?: 'light' | 'regular' | 'bold'; | ||
underline?: boolean; | ||
block?: boolean; | ||
transform?: 'capitalize' | 'uppercase' | 'lowercase'; | ||
align?: 'left' | 'center' | 'right'; | ||
lineClamp?: number; | ||
color?: 'primary' | 'black' | 'gray' | 'white'; | ||
inherit?: boolean; | ||
} | ||
|
||
function Text({ | ||
children, | ||
size = 'md', | ||
weight = 'regular', | ||
underline = false, | ||
block = false, | ||
transform, | ||
align, | ||
lineClamp, | ||
color = 'black', | ||
inherit = false, | ||
}: TextProps): JSX.Element { | ||
// 말줄임 설정 위한 코드 | ||
let displayStyle: string = 'inline'; | ||
if (lineClamp) { | ||
displayStyle = '-webkit-box'; | ||
} else if (block) { | ||
displayStyle = 'block'; | ||
} | ||
|
||
const colorClass = | ||
{ | ||
primary: 'text-primary', // #007BFF | ||
black: 'text-black', | ||
gray: 'text-gray-500', | ||
white: 'text-white', | ||
}[color] || 'text-black'; // 기본값 | ||
|
||
const sizeClass = | ||
{ | ||
xs: 'text-xs', | ||
sm: 'text-sm', | ||
md: 'text-base', | ||
lg: 'text-xl', | ||
xl: 'text-2xl', | ||
}[size] || 'text-base'; | ||
|
||
const weightClass = | ||
{ | ||
light: 'font-extralight', | ||
regular: 'font-medium', | ||
bold: 'font-extrabold', | ||
}[weight] || 'regular'; | ||
|
||
const baseStyles: React.CSSProperties = { | ||
display: displayStyle, | ||
textDecoration: underline ? 'underline' : 'none', | ||
textTransform: transform, | ||
textAlign: align, | ||
color: inherit ? 'inherit' : color || 'black', | ||
WebkitLineClamp: lineClamp, | ||
overflow: lineClamp ? 'hidden' : 'visible', | ||
WebkitBoxOrient: lineClamp ? 'vertical' : undefined, | ||
}; | ||
|
||
return ( | ||
<span | ||
style={{ ...baseStyles }} | ||
className={[colorClass, sizeClass, weightClass].join(' ')} | ||
> | ||
{children} | ||
</span> | ||
); | ||
} | ||
|
||
export default Text; |