-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: TextField, DatePicker 컴포넌트 추가 (#26)
* feat: TextField 컴포넌트 기본 스타일 추가 * feat: cursor 스타일 추가 * feat: type이 date일때 캘린더 아이콘 보이도록 추가 * feat: file 타입 대응 * feat: DatePicker 추가, never로 추론되는 것 수정
- Loading branch information
Showing
9 changed files
with
274 additions
and
4 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
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
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
37 changes: 37 additions & 0 deletions
37
packages/ui/src/components/DatePicker/DatePicker.styles.ts
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,37 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export interface DatePickerProps { | ||
fromInputProps?: Omit<React.ComponentProps<'input'>, 'type'>; | ||
toInputProps?: Omit<React.ComponentProps<'input'>, 'type'>; | ||
size: 'small' | 'big'; | ||
} | ||
|
||
const Container = styled.div<DatePickerProps>` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
${({ size }) => { | ||
switch (size) { | ||
case 'small': | ||
return ` | ||
width: 386px; | ||
`; | ||
case 'big': | ||
return ` | ||
width: 600px; | ||
`; | ||
} | ||
}} | ||
& > div { | ||
width: auto; | ||
flex: 1; | ||
} | ||
`; | ||
|
||
export const Seperator = styled.span` | ||
margin: 0 4px; | ||
${({ theme }) => theme.typo.b4}; | ||
color: ${({ theme }) => theme.palette.grey.g80}; | ||
`; | ||
|
||
export default { Container, Seperator }; |
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,14 @@ | ||
import TextField from '../TextField'; | ||
import Styled, { DatePickerProps } from './DatePicker.styles'; | ||
|
||
const DatePicker = ({ fromInputProps, toInputProps, size }: DatePickerProps) => { | ||
return ( | ||
<Styled.Container size={size}> | ||
<TextField {...fromInputProps} size={size} inputType="date" placeholder="YYYY.MM.DD" /> | ||
<Styled.Seperator>~</Styled.Seperator> | ||
<TextField {...toInputProps} size={size} inputType="date" placeholder="YYYY.MM.DD" /> | ||
</Styled.Container> | ||
); | ||
}; | ||
|
||
export default DatePicker; |
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
102 changes: 102 additions & 0 deletions
102
packages/ui/src/components/TextField/TextField.styles.ts
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,102 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export interface TextFieldProps { | ||
size: 'small' | 'big'; | ||
inputType: 'text' | 'date' | 'file'; | ||
disabled?: boolean; | ||
buttonProps?: React.ComponentProps<'button'>; | ||
} | ||
|
||
const Container = styled.div<TextFieldProps>` | ||
display: flex; | ||
${({ size }) => { | ||
switch (size) { | ||
case 'small': | ||
return ` | ||
width: 386px; | ||
`; | ||
case 'big': | ||
return ` | ||
width: 600px; | ||
`; | ||
} | ||
}} | ||
`; | ||
|
||
const InputContainer = styled.div` | ||
position: relative; | ||
flex: 1; | ||
& > svg { | ||
position: absolute; | ||
right: 12px; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
} | ||
`; | ||
|
||
const InputLabel = styled.label` | ||
display: block; | ||
width: 100%; | ||
height: 48px; | ||
border-radius: 4px; | ||
padding: 12px 13px; | ||
color: ${({ theme }) => theme.palette.grey.g90}; | ||
border: 1px solid ${({ theme }) => theme.palette.grey.g90}; | ||
background: ${({ theme }) => theme.palette.grey.w}; | ||
${({ theme }) => theme.typo.b3}; | ||
`; | ||
|
||
const Input = styled.input` | ||
width: 100%; | ||
border-radius: 4px; | ||
padding: 12px 13px; | ||
color: ${({ theme }) => theme.palette.grey.g90}; | ||
border: 1px solid ${({ theme }) => theme.palette.grey.g90}; | ||
background: ${({ theme }) => theme.palette.grey.w}; | ||
${({ theme }) => theme.typo.b3}; | ||
&:placeholder-shown { | ||
border: 1px solid ${({ theme }) => theme.palette.grey.g20}; | ||
color: ${({ theme }) => theme.palette.grey.g30}; | ||
} | ||
&:disabled { | ||
background: ${({ theme }) => theme.palette.grey.g10}; | ||
border: 1px solid ${({ theme }) => theme.palette.grey.g20}; | ||
color: ${({ theme }) => theme.palette.grey.g40}; | ||
} | ||
&[type='date'] { | ||
opacity: 0; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
} | ||
&[type='date']::before { | ||
content: attr(data-placeholder); | ||
width: 100%; | ||
} | ||
&[type='date']::-webkit-inner-spin-button, | ||
&[type='date']::-webkit-calendar-picker-indicator { | ||
position: absolute; | ||
right: -10px; | ||
top: 0; | ||
transform: translateX(-10px); | ||
padding-left: 600px; | ||
height: 100%; | ||
opacity: 0; | ||
} | ||
&[type='file'] { | ||
display: none; | ||
} | ||
`; | ||
|
||
const ButtonContainer = styled.div` | ||
margin-left: 8px; | ||
`; | ||
|
||
export default { | ||
Container, | ||
Input, | ||
InputLabel, | ||
InputContainer, | ||
ButtonContainer, | ||
}; |
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,40 @@ | ||
import { CalendarIcon } from '@boolti/icon'; | ||
import { nanoid } from 'nanoid'; | ||
import Button from '../Button'; | ||
import Styled, { TextFieldProps } from './TextField.styles'; | ||
import { useRef } from 'react'; | ||
|
||
type Props = Omit<React.ComponentProps<'input'>, 'size' | 'type'> & TextFieldProps; | ||
|
||
const TextField = ({ disabled, size, inputType, buttonProps, placeholder, id, ...rest }: Props) => { | ||
const uuid = useRef<string>(id ?? nanoid(6)); | ||
return ( | ||
<Styled.Container disabled={disabled} size={size} inputType={inputType}> | ||
<Styled.InputContainer> | ||
{(inputType === 'file' || inputType === 'date') && ( | ||
<Styled.InputLabel htmlFor={uuid.current}> | ||
{rest.value ? rest.value : placeholder} | ||
</Styled.InputLabel> | ||
)} | ||
<Styled.Input | ||
id={uuid.current} | ||
data-placeholder={placeholder} | ||
placeholder={placeholder} | ||
disabled={disabled} | ||
type={inputType} | ||
{...rest} | ||
/> | ||
{inputType === 'date' && <CalendarIcon size={20} />} | ||
</Styled.InputContainer> | ||
{buttonProps && ( | ||
<Styled.ButtonContainer> | ||
<Button {...buttonProps} disabled={disabled} size="bold" colorTheme="netural"> | ||
{buttonProps.children} | ||
</Button> | ||
</Styled.ButtonContainer> | ||
)} | ||
</Styled.Container> | ||
); | ||
}; | ||
|
||
export default TextField; |
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