Skip to content

Commit

Permalink
feat: Textarea 컴포넌트 및 스토리북 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
semnil5202 committed Apr 18, 2024
1 parent e7deac2 commit a756a36
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/Textarea/Textarea.tsx
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;
67 changes: 67 additions & 0 deletions src/stories/Textarea.stories.tsx
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)
}
/>
</>
);
},
};

0 comments on commit a756a36

Please sign in to comment.