Skip to content

Commit

Permalink
feat: 비밀번호 입력 컴포넌트 수정 (#19)
Browse files Browse the repository at this point in the history
* refactor: eye svg 파일 이름 변경

* feat: 눈 아이콘 클릭 이벤트 추가
  • Loading branch information
hayamaster authored Nov 1, 2023
1 parent 5bcdd11 commit 5a02fc4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/assets/icons/eye-off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/assets/icons/eye-on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 19 additions & 11 deletions src/components/PasswordInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
import { ChangeEvent, ComponentPropsWithoutRef } from 'react'
import { ChangeEvent, useState } from 'react'
import { EyeOffIcon, EyeOnIcon } from '@/assets/icons'

interface PasswordInputProps
extends Omit<ComponentPropsWithoutRef<'input'>, 'onChange'> {
type: 'password' | 'confirmation'
interface PasswordInputProps {
handlePasswordChange?: (e: ChangeEvent<HTMLInputElement>) => void
disabled?: boolean
placeholder?: string
}

const PasswordInput = ({
type,
placeholder,
placeholder = '비밀번호를 입력하세요.',
disabled,
handlePasswordChange,
...rest
}: PasswordInputProps) => {
const [showPassword, setShowPassword] = useState(false)

const handleEyeClick = () => {
setShowPassword((prev) => !prev)
}

return (
<div className="items-center2 relative flex h-fit w-fit flex-row content-center justify-center gap-2 border-2 border-black">
<div className="flex h-fit w-fit flex-row items-center justify-center border-2 border-black">
<input
className="input border-0 bg-white pl-8 text-black"
placeholder={placeholder ?? '새 비밀번호 입력'}
className="input border-0 bg-white p-0 pl-3 text-black"
placeholder={placeholder}
disabled={disabled}
onChange={handlePasswordChange}
type={showPassword ? 'text' : 'password'}
{...rest}
/>
<i className="flex items-center">
{type === 'password' ? <EyeOffIcon /> : <EyeOnIcon />}
<i className="mx-2 cursor-pointer">
{showPassword ? (
<EyeOnIcon onClick={handleEyeClick} />
) : (
<EyeOffIcon onClick={handleEyeClick} />
)}
</i>
</div>
)
Expand Down

0 comments on commit 5a02fc4

Please sign in to comment.