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

Textarea 컴포넌트 추가 #31

Merged
merged 8 commits into from
Feb 12, 2022
4 changes: 4 additions & 0 deletions src/components/common/Input/Input.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const Input = styled.input<StyledInputProps>`
border-radius: 0.9rem;
outline: none;

&::placeholder {
color: ${theme.colors.gray50};
}

&:hover {
border: 0.1rem solid ${theme.colors.purple40};
}
Expand Down
27 changes: 27 additions & 0 deletions src/components/common/Textarea/Textarea.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
HaJunRyu marked this conversation as resolved.
Show resolved Hide resolved
import * as Styled from './Textarea.styled';

export interface TextareaProps extends React.InputHTMLAttributes<HTMLTextAreaElement> {
id: string;
label: string;
errorMessage?: string;
}

const Textarea = ({ id, required, label, errorMessage, ...restProps }: TextareaProps) => {
return (
<Styled.TextareaWrapper>
<Styled.TextareaLabel htmlFor={id}>
<span>{label}</span>
{required && <Styled.RequiredDot />}
</Styled.TextareaLabel>
<Styled.Textarea {...restProps} />
{errorMessage && <Styled.TextareaErrorMessage>{errorMessage}</Styled.TextareaErrorMessage>}
</Styled.TextareaWrapper>
);
};

export default Textarea;

Textarea.defaultProps = {
errorMessage: '',
};
Copy link
Member

Choose a reason for hiding this comment

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

[질문]
이부분 지금까지 저는 props 파라미터에 직접 default 값을 주는 식으로 처리했었는데 defaultProps를 사용하는게 더 좋을까요?

Copy link
Member

@HaJunRyu HaJunRyu Feb 12, 2022

Choose a reason for hiding this comment

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

이 부분은 recruit에서 작업할때 OptionalProp을 사용할때 eslint airbnb규칙에 의존된 react/require-default-props에 의해서 에러를 발생시키는 경우가 있었는데 현재 admin쪽에는 그러한 상황이 발생하지 않는것 같아요 (이유는 자세히 의존성을 보지 않아서 모르겠네요)
아마 @mango906 님이 recruit쪽에서 해당 코드를 리뷰했었어서 이렇게 맞추신거 같아요!

똑같이 맞춰서 가려면 defaultProps로 해도 좋을거 같고 사실 이 부분은 저희가 컨벤션으로 따로 맞춘게 없어서 admin에선 어느 방향으로 해도 괜찮은거 같습니다~~

Copy link
Member Author

Choose a reason for hiding this comment

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

사실 요 부분은 이상하게 여기서만 default 파라미터가 작동하지 않더라구요;; 그래서 우선 이렇게 작업했었는데 한번 더 확인해볼게요!

Copy link
Member Author

Choose a reason for hiding this comment

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

다시 해보니 잘돼서 수정했습니다! 87c4940

18 changes: 18 additions & 0 deletions src/components/common/Textarea/Textarea.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import Textarea, { TextareaProps } from './Textarea.component';

export default {
title: 'Textarea',
component: Textarea,
} as ComponentMeta<typeof Textarea>;

const Template: ComponentStory<typeof Textarea> = (args: TextareaProps) => <Textarea {...args} />;

export const textarea = Template.bind({});

textarea.args = {
label: '지원서 내용입니다. 최소 200자 이내',
required: true,
placeholder: '내용을 입력해주세요',
};
65 changes: 65 additions & 0 deletions src/components/common/Textarea/Textarea.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';

export const TextareaWrapper = styled.div`
display: flex;
flex-direction: column;
`;

export const TextareaLabel = styled.label`
${({ theme }) => css`
${theme.fonts.medium15};
display: flex;
align-items: center;
margin-bottom: 0.6rem;
color: ${theme.colors.gray70};
`}
`;

export const RequiredDot = styled.span`
width: 0.6rem;
height: 0.6rem;
margin-left: 0.6rem;
background-color: #eb6963;
border-radius: 50%;
`;

export const Textarea = styled.textarea`
${({ theme }) => css`
${theme.fonts.regular15};

min-height: 20rem;
padding: 1.2rem 1.4rem;
background-color: ${theme.colors.white};
border: 1px solid ${theme.colors.gray30};
Copy link
Member

Choose a reason for hiding this comment

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

[제안]
이부분 rem으로 변경하면 좋을 것 같아요

Copy link
Member Author

Choose a reason for hiding this comment

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

수정했습니다!

border-radius: 1.2rem;
outline: none;
resize: none;
Copy link
Member

Choose a reason for hiding this comment

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

TextArea를 common한 컴포넌트로 사용할거라면 resize는 props로 받게끔 해주는것도 좋은것 같아요. 근데 현재 디자인에서 resize되는 textArea가 없다고 한다면 굳이 넣을 필요도 없다고 생각합니다! 디자인쪽이랑 얘기해보고 결정하면 될것 같아요 :)

Copy link
Member Author

Choose a reason for hiding this comment

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

아직까진 크게 필요할거 같지않아서, 만약 쓸 상황이 생긴다면 허용해놓도록 하겠습니다!


&::placeholder {
color: ${theme.colors.gray50};
}

&:hover {
border: 0.1rem solid ${theme.colors.purple40};
}

&:focus {
border: 0.1rem solid ${theme.colors.purple70};
}

&:disabled {
background-color: ${theme.colors.gray5};
border: 0.1rem solid ${theme.colors.gray30};
}
`}
`;

export const TextareaErrorMessage = styled.span`
${({ theme }) => css`
${theme.fonts.regular15};
HaJunRyu marked this conversation as resolved.
Show resolved Hide resolved

margin-top: 0.6rem;
color: ${theme.colors.gray60};
`}
`;
1 change: 1 addition & 0 deletions src/components/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as Input } from './Input/Input.component';
export { default as Textarea } from './Textarea/Textarea.component';
export { default as Button } from './Button/Button.component';