-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Feat/#32] Input 공통 컴포넌트 제작 #47
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
11a18b8
feat: cap 없는 버전 text field(default, narrow) 제작
imddoy 34fb78a
feat: unit type에 따른 라벨링 추가
imddoy 838a8f2
design: cap 스타일링
imddoy 77c48d0
Merge branch 'develop' into feat/#32/CommonInput
imddoy 61070a9
feat: text area 컴포넌트 제작
imddoy b92347d
Merge branch 'develop' into feat/#32/CommonInput
imddoy 51cd877
design: 입력 내용 삭제 버튼 디자인
imddoy e5267e6
feat: maxLength 설정
imddoy 01f3338
design: textarea 스크롤바 없애기
imddoy ff019e6
design: input 컬러 통일
imddoy ad06a8f
feat: 스토리북 theme 적용
imddoy 5055fe1
feat: text clear 구현
imddoy ed298df
feat: 전화번호 및 숫자 입력 처리 추가, narrow 시 clear 버튼 제거
imddoy c6ef32d
chore: 컨벤션 맞추기
imddoy ba325bf
fix: 정규표현식 백트래킹 해결
imddoy bc88b9c
style: 가격 필터링 정규표현식 제거
imddoy 279e5d9
style: 셀프 클로징 및 줄바꿈으로 가독성 높이기
imddoy 80ce035
fix: input 밀림 해결
imddoy e5a309a
chore: 오타 수정 컨벤션 통일
imddoy 88e92c6
feat: 상태 컴포넌트 외부로 빼주기
imddoy 42942c0
Merge branch 'develop' of https://github.com/TEAM-BEAT/BEAT-Client in…
pepperdad 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ThemeProvider } from "styled-components"; | ||
import theme from "../src/styles/theme"; | ||
import React, { ReactNode } from "react"; | ||
import GlobalStyle from "../src/styles/global"; | ||
|
||
interface ProviderProps { | ||
children?: ReactNode; | ||
theme?: unknown; | ||
} | ||
|
||
export const Provider = ({ children }: ProviderProps) => { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<GlobalStyle /> | ||
{children} | ||
</ThemeProvider> | ||
); | ||
}; |
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
Empty file.
29 changes: 29 additions & 0 deletions
29
src/components/commons/inputs/textAreas/TextArea.stories.tsx
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,29 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { fn } from "@storybook/test"; | ||
import TextArea from "./TextArea"; | ||
import { useState } from "react"; | ||
|
||
const meta = { | ||
title: "TextArea", | ||
component: TextArea, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
argTypes: {}, | ||
args: { value: "", onClick: fn(), placeholder: "플레이스 홀더", onChangeValue: fn() }, | ||
} satisfies Meta<typeof TextArea>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
const Template = (args) => { | ||
const [value, setValue] = useState(args.value); | ||
|
||
return <TextArea {...args} value={value} onChangeValue={setValue} />; | ||
}; | ||
|
||
export const CapOn: Story = Template.bind({}); | ||
CapOn.args = { maxLength: 300 }; | ||
|
||
export const CapOff: Story = Template.bind({}); | ||
CapOff.args = {}; |
49 changes: 49 additions & 0 deletions
49
src/components/commons/inputs/textAreas/TextArea.styled.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,49 @@ | ||
import { Generators } from "@styles/generator"; | ||
import styled from "styled-components"; | ||
|
||
export const TextAreaWrapper = styled.section` | ||
position: relative; | ||
width: 32.7rem; | ||
`; | ||
|
||
export const TextAreaInput = styled.textarea` | ||
${Generators.flexGenerator("row", "center", "center")} | ||
width: 100%; | ||
height: 12.9rem; | ||
padding: 1.8rem; | ||
|
||
color: ${({ theme }) => theme.colors.gray_0}; | ||
|
||
background: ${({ theme }) => theme.colors.gray_800}; | ||
outline: none; | ||
border: 1px solid transparent; | ||
border-radius: 0.6rem; | ||
|
||
resize: none; | ||
|
||
${({ theme }) => theme.fonts["body2-long"]}; | ||
|
||
&::placeholder { | ||
color: ${({ theme }) => theme.colors.gray_600}; | ||
} | ||
|
||
&:focus { | ||
border: 1px solid ${({ theme }) => theme.colors.gray_0}; | ||
} | ||
|
||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
`; | ||
|
||
export const TextCap = styled.p` | ||
${Generators.flexGenerator("row", "center", "end")} | ||
|
||
width: 100%; | ||
margin: 0; | ||
margin-top: 0.6rem; | ||
|
||
color: ${({ theme }) => theme.colors.gray_500}; | ||
text-align: right; | ||
${({ theme }) => theme.fonts["body2-normal-medi"]}; | ||
`; |
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,32 @@ | ||
import { ChangeEvent, TextareaHTMLAttributes } from "react"; | ||
import * as S from "./TextArea.styled"; | ||
|
||
export interface TextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> { | ||
onChangeValue: (value: string) => void; | ||
maxLength?: number; | ||
placeholder: string; | ||
} | ||
|
||
const TextArea = ({ value, onChangeValue, maxLength, placeholder, ...rest }: TextAreaProps) => { | ||
const handleOnInput = (e: ChangeEvent<HTMLTextAreaElement>) => { | ||
let inputValue = e.target.value; | ||
if (maxLength && inputValue.length > maxLength) { | ||
inputValue = inputValue.slice(0, maxLength); | ||
} | ||
onChangeValue(inputValue); | ||
}; | ||
return ( | ||
<S.TextAreaWrapper> | ||
<S.TextAreaInput | ||
{...rest} | ||
value={value} | ||
onChange={handleOnInput} | ||
maxLength={maxLength} | ||
placeholder={placeholder} | ||
/> | ||
{maxLength && <S.TextCap>{`${(value as string).length}/${maxLength}`}</S.TextCap>} | ||
</S.TextAreaWrapper> | ||
); | ||
}; | ||
|
||
export default TextArea; |
44 changes: 44 additions & 0 deletions
44
src/components/commons/inputs/textFields/TextField.stories.tsx
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,44 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { fn } from "@storybook/test"; | ||
import TextField from "./TextField"; | ||
import { numericFilter, phoneNumberFilter, priceFilter } from "../../../../utils/useInputFilter"; | ||
import { useState } from "react"; | ||
|
||
const meta = { | ||
title: "TextField", | ||
component: TextField, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
argTypes: {}, | ||
args: { value: "", onClick: fn(), placeholder: "플레이스 홀더", onChangeValue: fn() }, | ||
} satisfies Meta<typeof TextField>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
const Template = (args) => { | ||
const [value, setValue] = useState(args.value); | ||
|
||
return <TextField {...args} value={value} onChangeValue={setValue} />; | ||
}; | ||
|
||
export const DefaultCapOn: Story = Template.bind({}); | ||
DefaultCapOn.args = { maxLength: 30 }; | ||
|
||
export const DefaultCapOff: Story = Template.bind({}); | ||
DefaultCapOff.args = {}; | ||
|
||
export const Narrow: Story = Template.bind({}); | ||
Narrow.args = { narrow: true }; | ||
|
||
export const Time: Story = Template.bind({}); | ||
Time.args = { unit: "time", filter: numericFilter }; | ||
|
||
export const Ticket: Story = Template.bind({}); | ||
Ticket.args = { unit: "ticket", filter: numericFilter }; | ||
|
||
export const Amount: Story = Template.bind({}); | ||
Amount.args = { unit: "amount", filter: priceFilter }; | ||
|
||
export const Phone: Story = Template.bind({}); | ||
Phone.args = { filter: phoneNumberFilter }; |
63 changes: 63 additions & 0 deletions
63
src/components/commons/inputs/textFields/TextField.styled.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,63 @@ | ||
import { IconTextfiedlDelete } from "@assets/svgs"; | ||
import { Generators } from "@styles/generator"; | ||
import styled from "styled-components"; | ||
|
||
export const TextFieldLayout = styled.section<{ narrow?: false | true }>` | ||
position: relative; | ||
width: ${({ narrow }) => (narrow ? "13.6rem" : "32.7rem")}; | ||
`; | ||
|
||
export const TextFieldWrapper = styled.article` | ||
${Generators.flexGenerator("row", "center", "center")} | ||
`; | ||
|
||
export const TextFieldInput = styled.input` | ||
width: 100%; | ||
height: 4.8rem; | ||
padding: 0 1.6rem; | ||
|
||
color: ${({ theme }) => theme.colors.gray_0}; | ||
|
||
background: ${({ theme }) => theme.colors.gray_800}; | ||
border: 1px solid transparent; | ||
border-radius: 0.6rem; | ||
|
||
${({ theme }) => theme.fonts["body2-normal-medi"]}; | ||
|
||
&::placeholder { | ||
color: ${({ theme }) => theme.colors.gray_600}; | ||
} | ||
|
||
&:focus { | ||
border: 1px solid ${({ theme }) => theme.colors.gray_0}; | ||
} | ||
`; | ||
|
||
export const TextClear = styled(IconTextfiedlDelete)` | ||
position: absolute; | ||
top: 1.2rem; | ||
right: 1.2rem; | ||
width: 2.4rem; | ||
|
||
cursor: pointer; | ||
`; | ||
|
||
export const TextUnit = styled.p` | ||
position: absolute; | ||
right: 1.6rem; | ||
|
||
color: ${({ theme }) => theme.colors.gray_0}; | ||
${({ theme }) => theme.fonts["body2-normal-medi"]}; | ||
`; | ||
|
||
export const TextCap = styled.p` | ||
${Generators.flexGenerator("row", "center", "end")} | ||
|
||
width: 100%; | ||
margin: 0; | ||
margin-top: 0.6rem; | ||
|
||
color: ${({ theme }) => theme.colors.gray_500}; | ||
text-align: right; | ||
${({ theme }) => theme.fonts["body2-normal-medi"]}; | ||
`; |
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,60 @@ | ||
import { ChangeEvent, InputHTMLAttributes } from "react"; | ||
import * as S from "./TextField.styled"; | ||
|
||
export interface TextFieldProps extends InputHTMLAttributes<HTMLInputElement> { | ||
onChangeValue: (value: string) => void; | ||
maxLength?: number; | ||
placeholder: string; | ||
narrow?: false | true; | ||
unit?: "time" | "ticket" | "amount"; // 단위 : "분", "매", "원" | ||
filter?: (value: string) => string; | ||
} | ||
|
||
const TextField = ({ | ||
value, | ||
onChangeValue, | ||
maxLength, | ||
placeholder, | ||
narrow, | ||
unit, | ||
filter, | ||
...rest | ||
}: TextFieldProps) => { | ||
const label = unit === "time" ? "분" : unit === "ticket" ? "매" : "원"; | ||
|
||
// 값 입력될 떄 | ||
const handleOnInput = (e: ChangeEvent<HTMLInputElement>) => { | ||
let inputValue = e.target.value; | ||
if (filter) { | ||
inputValue = filter(inputValue); | ||
} | ||
if (maxLength && inputValue.length > maxLength) { | ||
inputValue = inputValue.slice(0, maxLength); | ||
} | ||
onChangeValue(inputValue); | ||
}; | ||
|
||
// 값 지울 때 | ||
const handleClearInput = () => { | ||
onChangeValue(""); | ||
}; | ||
|
||
return ( | ||
<S.TextFieldLayout narrow={narrow}> | ||
<S.TextFieldWrapper> | ||
<S.TextFieldInput | ||
{...rest} | ||
value={value} | ||
onChange={handleOnInput} | ||
maxLength={maxLength} | ||
placeholder={placeholder} | ||
/> | ||
{!narrow && !unit && value && <S.TextClear onClick={handleClearInput} />} | ||
{unit && <S.TextUnit>{label}</S.TextUnit>} | ||
</S.TextFieldWrapper> | ||
{maxLength && <S.TextCap>{`${(value as string).length}/${maxLength}`}</S.TextCap>} | ||
</S.TextFieldLayout> | ||
); | ||
}; | ||
|
||
export default TextField; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
p5) 주석 최고 ㅎㅎ