-
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.
- Loading branch information
1 parent
e7deac2
commit a756a36
Showing
2 changed files
with
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import styled from '@emotion/styled'; | ||
import { HTMLAttributes } from 'react'; | ||
|
||
import { convertCSS } from '../../utils/convertCSS'; | ||
|
||
interface Props extends HTMLAttributes<HTMLTextAreaElement> { | ||
width?: string | number; | ||
height?: string | number; | ||
padding?: string; | ||
} | ||
|
||
const TextArea = styled.textarea<Props>` | ||
box-sizing: border-box; | ||
width: ${({ width }) => (width && convertCSS(width)) || '100%'}; | ||
height: ${({ height }) => (height && convertCSS(height)) || '100px'}; | ||
border-radius: 6px; | ||
padding: ${({ padding }) => padding || '11px 16px'}; | ||
font-size: ${({ theme }) => theme.font.suit14r.fontSize}px; | ||
font-weight: ${({ theme }) => theme.font.suit14r.fontWeight}; | ||
border: 1px solid ${({ theme }) => theme.color.l2}; | ||
outline: none; | ||
color: ${({ theme }) => theme.color.b4}; | ||
background: ${({ theme }) => theme.color.w1}; | ||
&:focus { | ||
border-color: ${({ theme }) => theme.color.c1}; | ||
} | ||
`; | ||
|
||
export default TextArea; |
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,67 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import Textarea from '../components/Textarea/Textarea'; | ||
import { ChangeEvent, useEffect, useState } from 'react'; | ||
|
||
const meta = { | ||
title: 'Components/Textarea', | ||
component: Textarea, | ||
tags: ['autodocs'], | ||
argTypes: { | ||
width: { | ||
control: 'text', | ||
description: 'Textarea 컴포넌트의 넓이를 지정합니다.', | ||
}, | ||
height: { | ||
control: 'text', | ||
description: 'Textarea 컴포넌트의 높이를 지정합니다.', | ||
}, | ||
padding: { | ||
control: 'text', | ||
description: 'Textarea 컴포넌트 padding을 설정합니다.', | ||
}, | ||
value: { | ||
control: 'text', | ||
description: 'Textarea 컴포넌트의 텍스트를 나타내는 값입니다.', | ||
}, | ||
onChange: { | ||
control: false, | ||
description: | ||
'Textarea 컴포넌트의 value를 변경할 수 있는 onChange 함수입니다.', | ||
}, | ||
}, | ||
} as Meta<typeof Textarea>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Textarea>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
width: '100%', | ||
height: '100px', | ||
padding: '11px 16px', | ||
value: 'textarea', | ||
}, | ||
render: ({ value, width, height, padding }) => { | ||
const userInput = value as string; | ||
const [textarea, setTextarea] = useState<string>(userInput); | ||
|
||
useEffect(() => { | ||
setTextarea(userInput); | ||
}, [userInput]); | ||
|
||
return ( | ||
<> | ||
<Textarea | ||
value={textarea} | ||
width={width} | ||
height={height} | ||
padding={padding} | ||
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => | ||
setTextarea(e.target.value) | ||
} | ||
/> | ||
</> | ||
); | ||
}, | ||
}; |