260722_01_ENH: 버그 수정 및 개선 사항 수정

This commit is contained in:
2026-07-22 16:53:00 +09:00
parent d8b565276d
commit 2dd5b88c6f
67 changed files with 1925 additions and 736 deletions

View File

@@ -1,23 +1,24 @@
'use client'
import { useId, useMemo, useState } from 'react'
import { forwardRef, useId, useImperativeHandle, useMemo, useRef, useState } from 'react'
import { CheckIcon, EyeIcon, EyeOffIcon, XIcon } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { cn } from '@/lib/utils'
export const ALLOWED_SPECIALS_TEXT = `! @ # $ % ^ & * ( ) _ + - = { } [ ] : ; " ' < > , . ? /`
export const ONLY_ALLOWED_REGEX = /^[A-Za-z\d!@#$%^&*()_+\-={}\[\]:;"'<>,.?/]+$/
export const KRI_PW_REGEX = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_+\-={}\[\]:;"'<>,.?/]{8,20}$/
import { KRI_PW_REGEX, ONLY_ALLOWED_PW_REGEX } from '@/const/validationConst'
const requirements = [
{ test: (value: string) => /[A-Za-z]/.test(value), text: '영문 1개 이상' },
{ test: (value: string) => /\d/.test(value), text: '숫자 1개 이상' },
{ test: (value: string) => value.length >= 8 && value.length <= 20, text: '8~20자' },
{ test: (value: string) => !value || ONLY_ALLOWED_REGEX.test(value), text: '허용 문자만 사용' },
{ test: (value: string) => !value || ONLY_ALLOWED_PW_REGEX.test(value), text: '허용 문자만 사용' },
]
export type KriPasswordRef = {
focus: () => void
}
export interface KriPasswordProps {
value: string
onChange: (value: string) => void
@@ -27,9 +28,10 @@ export interface KriPasswordProps {
disabled?: boolean
className?: string
showStrength?: boolean
'aria-invalid'?: boolean
}
export function KriPassword({
export const KriPassword = forwardRef<KriPasswordRef, KriPasswordProps>(function KriPassword({
value,
onChange,
id,
@@ -38,12 +40,17 @@ export function KriPassword({
disabled,
className,
showStrength = true,
}: KriPasswordProps) {
'aria-invalid': ariaInvalid,
}, forwardedRef) {
const inputRef = useRef<HTMLInputElement>(null)
useImperativeHandle(forwardedRef, () => ({
focus: () => inputRef.current?.focus(),
}), [])
const [isVisible, setIsVisible] = useState(false)
const autoId = useId()
const inputId = id ?? autoId
const isValid = useMemo(() => KRI_PW_REGEX.test(value), [value])
const hasOnlyAllowedChars = useMemo(() => (value ? ONLY_ALLOWED_REGEX.test(value) : true), [value])
const hasOnlyAllowedChars = useMemo(() => (value ? ONLY_ALLOWED_PW_REGEX.test(value) : true), [value])
const checks = useMemo(() => requirements.map((item) => ({ met: item.test(value), text: item.text })), [value])
const score = checks.filter((item) => item.met).length
@@ -60,6 +67,7 @@ export function KriPassword({
{label ? <Label htmlFor={inputId}>{label}</Label> : null}
<div className="relative">
<Input
ref={inputRef}
id={inputId}
type={isVisible ? 'text' : 'password'}
placeholder={placeholder}
@@ -68,6 +76,7 @@ export function KriPassword({
className="pr-9"
disabled={disabled}
autoComplete="new-password"
aria-invalid={ariaInvalid}
/>
<Button
type="button"
@@ -113,6 +122,6 @@ export function KriPassword({
) : null}
</div>
)
}
})
export default KriPassword