-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/#19 인풋필드 컴포넌트 #30
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
Merged
The head ref may contain hidden characters: "feature/#19_\uC778\uD48B\uD544\uB4DC-\uCEF4\uD3EC\uB10C\uD2B8"
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a38ac9b
🚧 이슈 해결을 위한 임시 커밋
crazyupinc-design 0b1fff1
💄 tailwind 반응형 범위 수정
junghwaYang 6f1fe4a
Merge branch 'develop' into feature/#19_인풋필드-컴포넌트
crazyupinc-design f9a22b9
Merge branch 'develop' into feature/#19_인풋필드-컴포넌트
crazyupinc-design d90c669
✨ 인풋필드 컴포넌트 추가
crazyupinc-design ba45033
🐛 CI ESlint 규칙에 맞게 수정
junghwaYang 6ae9dcb
Merge branch 'develop' into feature/#19_인풋필드-컴포넌트
junghwaYang 61bb58f
🚨충돌 해결 및 병합
crazyupinc-design 96c2593
🔧 인풋 유효성 검사 로직 분리
crazyupinc-design 3dff6ee
🚨test화면 충돌 해결 및 병합
crazyupinc-design 12e9ef1
🔥 프로필인풋삭제
crazyupinc-design cb93194
Merge branch 'develop' into feature/#19_인풋필드-컴포넌트
crazyupinc-design 65178c4
<p>태그 삭제
crazyupinc-design 0ef8bf6
🚨Resolve lint and prettier issues
crazyupinc-design a4d2b29
🚨Resolve lint and prettier issues
crazyupinc-design 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 hidden or 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,36 @@ | ||
| import { DayPicker } from 'react-day-picker'; | ||
| import 'react-day-picker/dist/style.css'; | ||
| import { ko } from 'date-fns/locale'; | ||
|
|
||
| interface CustomDayPickerProps { | ||
| selected?: Date; | ||
| onSelect?: (date: Date | undefined) => void; | ||
| } | ||
|
|
||
| function CustomDayPicker({ selected, onSelect }: CustomDayPickerProps) { | ||
| return ( | ||
| <div className="relative"> | ||
| <DayPicker | ||
| mode="single" | ||
| selected={selected} | ||
| onSelect={onSelect} | ||
| locale={ko} | ||
| captionLayout="dropdown" | ||
| fromYear={2000} | ||
| toYear={new Date().getFullYear()} | ||
| modifiersStyles={{ | ||
| selected: { | ||
| backgroundColor: '#32A68A', | ||
| color: 'white', | ||
| }, | ||
| today: { | ||
| color: '#32A68A', | ||
| fontWeight: 'bold', | ||
| }, | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default CustomDayPicker; |
This file contains hidden or 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,119 @@ | ||
| import React, { useState } from 'react'; | ||
| import { useValidation } from 'hooks/useValidation'; | ||
| import CustomDayPicker from './DayPicker'; | ||
|
|
||
| interface InputFieldProps { | ||
| value: string; | ||
| onChange: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
| type?: 'text' | 'email' | 'password' | 'name' | 'passwordConfirm'; | ||
| placeholder?: string; | ||
| label?: string; | ||
| compareValue?: string; | ||
| layout?: 'vertical' | 'horizontal'; | ||
| } | ||
|
|
||
| function InputField({ | ||
| value, | ||
| onChange, | ||
| type = 'text', | ||
| placeholder, | ||
| label, | ||
| compareValue, | ||
| layout = 'vertical', | ||
| }: InputFieldProps) { | ||
| const { errorMessage, validate } = useValidation({ | ||
| type, | ||
| compareValue, | ||
| }); | ||
|
|
||
| const [showDayPicker, setShowDayPicker] = useState(false); | ||
|
|
||
| const handleFocus = () => { | ||
| if (layout === 'horizontal' && label === '생일') { | ||
| setShowDayPicker(true); | ||
| } | ||
| }; | ||
|
|
||
| const closeDayPicker = () => { | ||
| setShowDayPicker(false); | ||
| }; | ||
|
|
||
| const handleBlur = () => { | ||
| if (layout === 'vertical') | ||
| // 가로모드 에러 확인 비활성화 | ||
| validate(value); | ||
| }; | ||
|
|
||
| const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| onChange(e); | ||
| if (layout === 'vertical' && errorMessage) { | ||
| validate(e.target.value); | ||
| } | ||
| }; | ||
| const getInputType = () => { | ||
| if (type === 'name') { | ||
| return 'text'; | ||
| } else if (type === 'passwordConfirm') { | ||
| return 'password'; | ||
| } | ||
| return type; | ||
| }; | ||
| //스타일에 따른 클래스 | ||
| const variantClass = { | ||
| containerVertical: 'mb-[24px] flex flex-col gap-[10px]', | ||
| containerHorizontal: 'mb-[24px] w-[239px] flex items-center gap-[10px]', | ||
| labelVertical: 'text-14 text-gray-500', | ||
| labelHorizontal: 'text-14 text-gray-400 w-[60px] flex-shrink-0', | ||
| base: 'px-[20px] py-[10px] h-[45px] w-[400px] rounded-md text-[14px] text-gray-500 placeholder:text-14 focus:outline-none mo:w-[355px]', | ||
| error: 'border border-red-100 bg-red-50', | ||
| normal: | ||
| 'bg-gray-100 focus:border-green-200 focus:ring-1 focus:ring-green-200', | ||
| errorText: 'text-12 text-red-100', | ||
| }; | ||
| const labelClass = | ||
| layout === 'horizontal' | ||
| ? variantClass.labelHorizontal | ||
| : variantClass.labelVertical; | ||
|
|
||
| const inputClass = `${variantClass.base} ${ | ||
| layout === 'vertical' && errorMessage | ||
| ? variantClass.error | ||
| : variantClass.normal | ||
| }`; | ||
|
|
||
| return ( | ||
| <div | ||
| className={ | ||
| layout === 'horizontal' | ||
| ? `${variantClass.containerHorizontal} relative` | ||
| : `${variantClass.containerVertical} relative` | ||
| } | ||
| > | ||
| {label && <label className={labelClass}>{label}</label>} | ||
| <input | ||
| type={getInputType()} | ||
| value={value} | ||
| onChange={handleChange} | ||
| placeholder={placeholder} | ||
| onBlur={handleBlur} | ||
| onFocus={handleFocus} | ||
| className={inputClass} | ||
| /> | ||
| {layout === 'vertical' && errorMessage && ( | ||
| <span className={variantClass.errorText}>{errorMessage}</span> | ||
| )} | ||
| {showDayPicker && ( | ||
| <div className="absolute left-0 top-full z-50 mt-2 rounded bg-white p-4 shadow-md"> | ||
| <p> | ||
| <CustomDayPicker /> | ||
| </p> | ||
| <button onClick={closeDayPicker} className="mt-2 text-gray-500"> | ||
| 닫기 | ||
| </button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default InputField; | ||
Empty file.
This file contains hidden or 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,59 @@ | ||
| import { useState } from 'react'; | ||
|
|
||
| type ValidationType = | ||
| | 'text' | ||
| | 'email' | ||
| | 'password' | ||
| | 'name' | ||
| | 'passwordConfirm'; | ||
|
|
||
| interface UseValidationProps { | ||
| type: ValidationType; | ||
| compareValue?: string; | ||
| } | ||
|
|
||
| export function useValidation({ type, compareValue }: UseValidationProps) { | ||
| const [errorMessage, setErrorMessage] = useState<string | undefined>( | ||
| undefined | ||
| ); | ||
|
|
||
| const validateInput = (value: string) => { | ||
| if (!value) return undefined; | ||
|
|
||
| switch (type) { | ||
| case 'email': | ||
| if (!/\S+@\S+\.\S+/.test(value)) { | ||
| return '이메일 형식으로 작성해 주세요.'; | ||
| } | ||
| break; | ||
| case 'password': | ||
| if (value.length < 8) { | ||
| return '8자 이상 입력해주세요.'; | ||
| } | ||
| break; | ||
| case 'name': | ||
| if (value.length > 10) { | ||
| return '열 자 이하로 작성해주세요.'; | ||
| } | ||
| break; | ||
| case 'passwordConfirm': | ||
| if (compareValue !== undefined && value !== compareValue) { | ||
| return '비밀번호가 일치하지 않습니다.'; | ||
| } | ||
| break; | ||
| } | ||
| return undefined; | ||
| }; | ||
|
|
||
| const validate = (value: string) => { | ||
| const error = validateInput(value); | ||
| setErrorMessage(error); | ||
| return error; | ||
| }; | ||
|
|
||
| return { | ||
| errorMessage, | ||
| validate, | ||
| setErrorMessage, | ||
| }; | ||
| } |
This file contains hidden or 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,72 @@ | ||
| import { useState } from 'react'; | ||
|
|
||
| import InputField from '@/components/Input'; | ||
|
|
||
| const SignUp: React.FC = () => { | ||
| const [email, setEmail] = useState(''); | ||
| const [password, setPassword] = useState(''); | ||
| const [passwordConfirm, setPasswordConfirm] = useState(''); | ||
| const [name, setName] = useState(''); | ||
|
|
||
| const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setEmail(e.target.value); | ||
| }; | ||
|
|
||
| const handlePasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setPassword(e.target.value); | ||
| }; | ||
|
|
||
| const handlePasswordConfirmChange = ( | ||
| e: React.ChangeEvent<HTMLInputElement> | ||
| ) => { | ||
| setPasswordConfirm(e.target.value); | ||
| }; | ||
|
|
||
| const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setName(e.target.value); | ||
| }; | ||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| alert('가입이 완료되었습니다'); | ||
| }; | ||
|
|
||
| return ( | ||
| <form onSubmit={handleSubmit}> | ||
| <InputField | ||
| label="이름" | ||
| type="name" | ||
| value={name} | ||
| onChange={handleNameChange} | ||
| placeholder="이름을 입력해 주세요" | ||
| /> | ||
|
|
||
| <InputField | ||
| label="이메일" | ||
| type="email" | ||
| value={email} | ||
| onChange={handleEmailChange} | ||
| placeholder="이메일을 입력해 주세요" | ||
| /> | ||
|
|
||
| <InputField | ||
| label="비밀번호" | ||
| type="password" | ||
| value={password} | ||
| onChange={handlePasswordChange} | ||
| placeholder="비밀번호를 입력해 주세요" | ||
| /> | ||
|
|
||
| <InputField | ||
| label="비밀번호 확인" | ||
| type="passwordConfirm" | ||
| value={passwordConfirm} | ||
| onChange={handlePasswordConfirmChange} | ||
| placeholder="비밀번호를 다시 입력해 주세요" | ||
| compareValue={password} | ||
| /> | ||
| </form> | ||
| ); | ||
| }; | ||
|
|
||
| export default SignUp; |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.