-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: text input 컴포넌트 추가 (#ATR-603)
- Loading branch information
Showing
6 changed files
with
396 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
@import 'badge'; | ||
@import 'switch'; | ||
@import 'chip'; | ||
@import 'text-input'; |
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
123 changes: 123 additions & 0 deletions
123
packages/design-system/packages/core/src/components/text-input/TextInput.stories.tsx
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,123 @@ | ||
/* eslint-disable tailwindcss/no-custom-classname */ | ||
import React from 'react' | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import TextInput from './TextInput' | ||
import { $variable } from '../../token' | ||
|
||
const meta: Meta<typeof TextInput> = { | ||
title: 'Inputs/TextInput', | ||
component: TextInput, | ||
tags: ['autodocs'], | ||
parameters: { | ||
componentSubtitle: 'Attraction에서 사용되는 인풋 컴포넌트입니다.', | ||
}, | ||
argTypes: { | ||
state: { | ||
description: '인풋의 상태를 지정합니다.', | ||
control: 'select', | ||
options: ['default', 'danger', 'warn', 'success'], | ||
table: { | ||
type: { | ||
summary: ['default', 'danger', 'warn', 'success'].join(' | '), | ||
}, | ||
defaultValue: { summary: 'default' }, | ||
}, | ||
}, | ||
size: { | ||
description: '인풋의 크기를 지정합니다.', | ||
control: 'select', | ||
options: ['md', 'lg'], | ||
table: { | ||
type: { summary: ['md', 'lg'].join(' | ') }, | ||
defaultValue: { summary: 'md' }, | ||
}, | ||
}, | ||
round: { | ||
description: '인풋의 모서리 형태를 지정합니다.', | ||
control: 'select', | ||
options: ['xs', 'sm', 'md', 'lg', 'full'], | ||
table: { | ||
type: { summary: ['xs', 'sm', 'md', 'lg', 'full'].join(' | ') }, | ||
defaultValue: { summary: 'sm' }, | ||
}, | ||
}, | ||
disabled: { | ||
description: '인풋의 비활성화 상태를 지정합니다.', | ||
control: 'boolean', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
defaultValue: { summary: 'undefined' }, | ||
}, | ||
}, | ||
withBackground: { | ||
description: '인풋 배경색의 기본 상태를 지정합니다.', | ||
control: 'boolean', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
defaultValue: { summary: 'undefined' }, | ||
}, | ||
}, | ||
required: { | ||
description: '필수 인풋 여부를 지정합니다. label 옵션과 함께 사용됩니다.', | ||
control: 'boolean', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
defaultValue: { summary: 'undefined' }, | ||
}, | ||
}, | ||
label: { | ||
description: '인풋의 label을 지정합니다.', | ||
control: 'text', | ||
table: { | ||
type: { summary: 'ReactNode | string' }, | ||
defaultValue: { summary: 'undefined' }, | ||
}, | ||
}, | ||
placeholder: { | ||
description: '인풋의 placeholder를 지정합니다.', | ||
control: 'text', | ||
table: { | ||
type: { summary: 'string' }, | ||
defaultValue: { summary: 'undefined' }, | ||
}, | ||
}, | ||
description: { | ||
description: '인풋의 설명(하단 텍스트)을 지정합니다.', | ||
control: 'text', | ||
table: { | ||
type: { summary: 'ReactNode | string' }, | ||
defaultValue: { summary: 'undefined' }, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
|
||
const style: React.CSSProperties = { | ||
display: 'block', | ||
padding: '30px', | ||
width: '50%', | ||
} | ||
|
||
export const TextInputDefault: Story = { | ||
render: (props) => ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
}}> | ||
<div style={style}> | ||
<TextInput {...props} /> | ||
</div> | ||
<div | ||
className="dark" | ||
style={{ ...style, backgroundColor: $variable.color.gray800 }}> | ||
<TextInput {...props} /> | ||
</div> | ||
</div> | ||
), | ||
} |
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
58 changes: 54 additions & 4 deletions
58
packages/design-system/packages/core/src/components/text-input/TextInput.tsx
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 |
---|---|---|
@@ -1,15 +1,65 @@ | ||
import React from 'react' | ||
import { cn } from '@attraction/utils' | ||
import { textInputVariants, variants } from './TextInput.style' | ||
|
||
type TextInputVariant = typeof variants | ||
|
||
interface TextProps | ||
extends React.DetailedHTMLProps< | ||
React.InputHTMLAttributes<HTMLInputElement>, | ||
HTMLInputElement | ||
extends Omit< | ||
React.DetailedHTMLProps< | ||
React.InputHTMLAttributes<HTMLInputElement>, | ||
HTMLInputElement | ||
>, | ||
'size' | ||
> { | ||
state?: keyof TextInputVariant['state'] | ||
size?: keyof TextInputVariant['size'] | ||
round?: keyof TextInputVariant['round'] | ||
withBackground?: boolean | ||
label?: React.ReactNode | string | ||
required?: boolean | ||
description?: React.ReactNode | string | ||
} | ||
|
||
const TextInput = React.forwardRef<HTMLInputElement, TextProps>( | ||
({ withBackground, ...props }, ref) => <input ref={ref} {...props} />, | ||
( | ||
{ | ||
className, | ||
id, | ||
type, | ||
label, | ||
required, | ||
state, | ||
size, | ||
round, | ||
withBackground, | ||
style, | ||
description, | ||
...props | ||
}, | ||
ref, | ||
) => ( | ||
<div | ||
className={cn( | ||
textInputVariants({ | ||
state, | ||
size, | ||
round, | ||
background: withBackground ? 'with' : null, | ||
}), | ||
className, | ||
)} | ||
style={style}> | ||
{label && ( | ||
<label htmlFor={id}> | ||
{label} | ||
{required && <span>*</span>} | ||
</label> | ||
)} | ||
<input ref={ref} id={id} type={type || 'text'} {...props} /> | ||
{description && <p>{description}</p>} | ||
</div> | ||
), | ||
) | ||
|
||
export default TextInput |
Oops, something went wrong.