-
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
Feat: #5 회원가입 페이지 생성 및 Validation 작성 #37
Changes from 14 commits
12554da
d758f80
5517b4b
23cf695
99bd536
32c9850
54630e1
393ba68
3f771ba
52cca55
02eaa76
fb66247
1616be5
8d34d71
dd56760
9929f00
a3d0c13
76172b0
ee5dfea
12ad055
96e9c8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { useState } from 'react'; | ||
import { UseFormRegisterReturn } from 'react-hook-form'; | ||
import { RiEyeFill, RiEyeOffFill } from 'react-icons/ri'; | ||
|
||
/** | ||
* ValidationInput 컴포넌트 params, 모든 params는 optional | ||
* | ||
* @params {string} [label] - 입력 필드의 label 텍스트 | ||
* @params {string} [errors] - 유효성 검증 후 오류 발생 시 표시할 오류 메시지 | ||
* @params {UseFormRegisterReturn} [register] - react-hook-form의 resister 함수. | ||
* register('password', {required: ...})부분을 그대로 파라미터에 넣으면 됩니다. | ||
* @params {string} [type] - 입력 필드의 유형(ex: text, password). 기본값은 'text' | ||
* @params {string} [placeholder] - 입력 필드의 placeholder 텍스트 | ||
* @params {boolean} [isButtonInput] - 버튼이 포함된 입력 필드인지 여부. 기본값은 'false' | ||
* @params {React.ReactNode} [buttonLabel] - 버튼에 표시할 텍스트 또는 아이콘 | ||
* @params {() => void} [onButtonClick] - 버튼 클릭 시 호출할 함수 | ||
* | ||
* 예시) | ||
* <ValidationInput | ||
label="비밀번호 확인" | ||
errors={errors.checkPassword?.message} | ||
register={register('checkPassword', { | ||
required: '비밀번호를 한 번 더 입력해 주세요.', | ||
validate: (value) => value === watch('password') || '비밀번호가 일치하지 않습니다.', | ||
})} | ||
type="password" | ||
/> | ||
*/ | ||
|
||
type ValidationInputProps = { | ||
label?: string; | ||
errors?: string; | ||
register?: UseFormRegisterReturn; | ||
type?: string; | ||
placeholder?: string; | ||
isButtonInput?: boolean; | ||
buttonLabel?: React.ReactNode; | ||
onButtonClick?: () => void; | ||
}; | ||
|
||
export default function ValidationInput({ | ||
label, | ||
errors, | ||
register, | ||
type = 'text', | ||
placeholder, | ||
isButtonInput = false, | ||
buttonLabel, | ||
onButtonClick, | ||
}: ValidationInputProps) { | ||
const [showPassword, setShowPassword] = useState(false); | ||
|
||
const handleTogglePassword = () => { | ||
setShowPassword((prev) => !prev); | ||
}; | ||
|
||
return ( | ||
<div className="relative"> | ||
{label && ( | ||
<label htmlFor={label} className="font-bold"> | ||
{label} | ||
</label> | ||
)} | ||
<div | ||
className={`flex h-30 items-center rounded-lg border px-6 text-sm ${ | ||
errors ? 'border-2 border-[#FF0000]' : 'border-input' | ||
}`} | ||
> | ||
<div className="flex h-full w-full flex-row items-center gap-8"> | ||
<input | ||
id={label} | ||
{...register} | ||
type={type === 'password' && showPassword ? 'text' : type} | ||
placeholder={placeholder} | ||
className={`h-full bg-inherit outline-none placeholder:text-emphasis ${isButtonInput ? 'w-[90%]' : 'w-full'}`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 버튼 유무로 크기를 지정하기보다 부모 요소를 flex로 설정하고, flex-grow 속성을 이용하여 공간을 알아서 차지하도록 해보는게 어떨까요? 버튼의 크기와 패스워드 눈(?)의 아이콘 크기를 지정하면, 나머지 넓이를 알아서 차지해줍니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 flex-grow 쓰는 방법이 있었네요! 그렇게 변경하면 조건문 없애도 되겠어요. 한번 바꿔보겠습니다. 감사합니다.👍 |
||
/> | ||
{isButtonInput && ( | ||
<button | ||
type="button" | ||
className="flex h-20 w-90 items-center justify-center rounded bg-sub px-8 font-bold shadow-md" | ||
onClick={onButtonClick} | ||
> | ||
{buttonLabel} | ||
</button> | ||
)} | ||
</div> | ||
{type === 'password' && ( | ||
<div className="absolute right-0 flex items-center pr-8 text-gray-400"> | ||
{showPassword ? ( | ||
<RiEyeFill className="h-15 w-15 cursor-pointer" onClick={handleTogglePassword} /> | ||
) : ( | ||
<RiEyeOffFill className="h-15 w-15 cursor-pointer" onClick={handleTogglePassword} /> | ||
)} | ||
</div> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</div> | ||
{errors && <p className="mt-[.5rem] text-sm text-[#FF0000]">{errors}</p>} | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이메일 정규표현식
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
export const PASSWORD_REGEX = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,16}$/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 패스워드 정규표현식
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사실 정규표현식은 제가 잘 몰라서 구글링으로 따왔는데...ㅋㅋ 찾아보니까 앞부분은 저희가 영문자, 숫자, 기호 각각 하나씩을 반드시 포함하기로 비밀번호 패턴을 정했었잖아요? 그 부분이라고 합니다@ 특수기호는 더 포함하고 싶은 게 있으면 추가해도 될 거 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 다 같이 이야기해보면 좋을 것 같습니다!😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 대화 요약 : 키보드에 있는 특수문자는 모두 허용하기 😆 |
||
export const PHONE_REGEX = /^01([0|1|6|7|8|9])-?([0-9]{3,4})-?([0-9]{4})$/; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. global.css에 다 추가되어 있는 내용이라 삭제하는게 좋을 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 이 파일 삭제하는 걸 깜빡 잊었어요. 삭제해두겠습니다! |
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.
해당 옵션 33번 라인에도 똑같이 설정되어 있어서 삭제하시는게 좋을 것 같아요!
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.
그러네요 왜 두 번이나 들어갔지?😳 삭제해 두겠습니다!