-
Notifications
You must be signed in to change notification settings - Fork 1
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
input 옮기기 & 리드미 작성 #77
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,2 @@ | ||
<div id="custom-root"></div> | ||
<div id="dialog-container"></div> |
Large diffs are not rendered by default.
Oops, something went wrong.
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,49 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import Input from './Input'; | ||
|
||
const meta: Meta<typeof Input> = { | ||
title: 'Input', | ||
component: Input, | ||
argTypes: { | ||
rightIcon: { | ||
control: { type: 'boolean' }, | ||
mapping: { false: '', true: '🔎' }, | ||
}, | ||
}, | ||
args: { | ||
customWidth: '300px', | ||
isError: false, | ||
rightIcon: false, | ||
errorMessage: '', | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Input>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const WithPlaceholder: Story = { | ||
args: { | ||
placeholder: '상품 이름을 검색하세요.', | ||
}, | ||
}; | ||
|
||
export const WithIcon: Story = { | ||
args: { | ||
placeholder: '상품 이름을 검색하세요.', | ||
rightIcon: true, | ||
}, | ||
}; | ||
|
||
export const Error: Story = { | ||
args: { | ||
isError: true, | ||
errorMessage: '10글자 이내로 입력해주세요.', | ||
}, | ||
}; | ||
|
||
export const Disabled: Story = { | ||
render: () => <Input disabled />, | ||
}; |
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,98 @@ | ||
import type { ComponentPropsWithRef, ForwardedRef, ReactNode } from 'react'; | ||
import { forwardRef } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import Text from '../Text'; | ||
|
||
export interface InputProps extends ComponentPropsWithRef<'input'> { | ||
/** | ||
* Input 컴포넌트의 너비값입니다. | ||
*/ | ||
customWidth?: string; | ||
/** | ||
* Input 컴포넌트의 최소 너비값입니다. | ||
*/ | ||
minWidth?: string; | ||
/** | ||
* Input value에 에러가 있는지 여부입니다. | ||
*/ | ||
isError?: boolean; | ||
/** | ||
* Input 컴포넌트 오른쪽에 위치할 아이콘입니다. | ||
*/ | ||
rightIcon?: ReactNode; | ||
/** | ||
* isError가 true일 때 보여줄 에러 메시지입니다. | ||
*/ | ||
errorMessage?: string; | ||
} | ||
|
||
const Input = forwardRef( | ||
( | ||
{ customWidth = '300px', minWidth, isError = false, rightIcon, errorMessage, ...props }: InputProps, | ||
ref: ForwardedRef<HTMLInputElement> | ||
) => { | ||
return ( | ||
<> | ||
<InputContainer customWidth={customWidth} minWidth={minWidth}> | ||
<CustomInput ref={ref} isError={isError} {...props} /> | ||
{rightIcon && <IconWrapper>{rightIcon}</IconWrapper>} | ||
</InputContainer> | ||
{isError && <ErrorMessage>{errorMessage}</ErrorMessage>} | ||
</> | ||
); | ||
} | ||
); | ||
|
||
Input.displayName = 'Input'; | ||
|
||
export default Input; | ||
|
||
type InputContainerStyleProps = Pick<InputProps, 'customWidth' | 'minWidth'>; | ||
type CustomInputStyleProps = Pick<InputProps, 'isError'>; | ||
|
||
const InputContainer = styled.div<InputContainerStyleProps>` | ||
position: relative; | ||
min-width: ${({ minWidth }) => minWidth ?? 0}; | ||
max-width: ${({ customWidth }) => customWidth}; | ||
text-align: center; | ||
`; | ||
|
||
const CustomInput = styled.input<CustomInputStyleProps>` | ||
width: 100%; | ||
height: 40px; | ||
padding: 10px 0 10px 12px; | ||
color: ${({ isError, theme }) => (isError ? theme.colors.error : theme.textColors.default)}; | ||
border: 1px solid ${({ isError, theme }) => (isError ? theme.colors.error : theme.borderColors.default)}; | ||
border-radius: 5px; | ||
|
||
&:focus { | ||
border: 2px solid ${({ isError, theme }) => (isError ? theme.colors.error : theme.borderColors.strong)}; | ||
outline: none; | ||
} | ||
|
||
&:disabled { | ||
border: 1px solid ${({ theme }) => theme.borderColors.disabled}; | ||
background: ${({ theme }) => theme.colors.gray1}; | ||
} | ||
|
||
&::placeholder { | ||
color: ${({ theme }) => theme.textColors.disabled}; | ||
font-size: ${({ theme }) => theme.fontSizes.sm}; | ||
} | ||
`; | ||
|
||
const IconWrapper = styled.div` | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
display: flex; | ||
align-items: center; | ||
height: 100%; | ||
margin-right: 8px; | ||
`; | ||
|
||
const ErrorMessage = styled(Text)` | ||
color: ${({ theme }) => theme.colors.error}; | ||
font-size: ${({ theme }) => theme.fontSizes.xs}; | ||
`; |
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,5 @@ | ||
import Input from './Input'; | ||
|
||
export type { InputProps } from './Input'; | ||
|
||
export default 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅋㅋㅋㅋㅋ 이렇게 대체하셨군여