Skip to content

Commit 77c1b39

Browse files
authored
Merge pull request #663 from vishv96/dev
feat(components): add password visibility toggle to Input
2 parents 571f161 + b98f482 commit 77c1b39

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

components/login-form.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { IconLogo } from '@/components/ui/icons'
1919
import { Input } from '@/components/ui/input'
2020
import { Label } from '@/components/ui/label'
2121

22+
import { PasswordInput } from './ui/password-input'
23+
2224
export function LoginForm({
2325
className,
2426
...props
@@ -129,7 +131,7 @@ export function LoginForm({
129131
Forgot password?
130132
</Link>
131133
</div>
132-
<Input
134+
<PasswordInput
133135
id="password"
134136
type="password"
135137
placeholder="********"

components/sign-up-form.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use client'
2-
32
import { useState } from 'react'
43
import Link from 'next/link'
54
import { useRouter } from 'next/navigation'
@@ -18,6 +17,7 @@ import {
1817
import { IconLogo } from '@/components/ui/icons'
1918
import { Input } from '@/components/ui/input'
2019
import { Label } from '@/components/ui/label'
20+
import { PasswordInput } from '@/components/ui/password-input'
2121

2222
export function SignUpForm({
2323
className,
@@ -92,7 +92,7 @@ export function SignUpForm({
9292
<div className="flex items-center">
9393
<Label htmlFor="password">Password</Label>
9494
</div>
95-
<Input
95+
<PasswordInput
9696
id="password"
9797
type="password"
9898
placeholder="********"
@@ -105,7 +105,7 @@ export function SignUpForm({
105105
<div className="flex items-center">
106106
<Label htmlFor="repeat-password">Repeat Password</Label>
107107
</div>
108-
<Input
108+
<PasswordInput
109109
id="repeat-password"
110110
type="password"
111111
placeholder="********"

components/ui/password-input.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as React from 'react'
2+
import { useState } from 'react'
3+
4+
import { Eye, EyeOff } from 'lucide-react'
5+
6+
import { Input, InputProps } from '@/components/ui/input'
7+
8+
import { Button } from './button'
9+
10+
const PasswordInput = React.forwardRef<HTMLInputElement, InputProps>(
11+
({ className, type = 'password', ...props }, ref) => {
12+
const [showPassword, setShowPassword] = useState(false)
13+
return (
14+
<div className="relative flex">
15+
<Input
16+
type={showPassword ? 'text' : type}
17+
className={className}
18+
ref={ref}
19+
{...props}
20+
/>
21+
<Button
22+
type="button"
23+
variant="ghost"
24+
size="icon"
25+
className="h-full px-3 py-2 hover:bg-transparent absolute right-0 flex items-center justify-center"
26+
onClick={() => setShowPassword(!showPassword)}
27+
>
28+
{showPassword ? (
29+
<EyeOff className="h-4 w-4" />
30+
) : (
31+
<Eye className="h-4 w-4" />
32+
)}
33+
</Button>
34+
</div>
35+
)
36+
}
37+
)
38+
39+
PasswordInput.displayName = 'PasswordInput'
40+
41+
export { PasswordInput }

0 commit comments

Comments
 (0)