Skip to content

An AI-powered search engine with a generative UI

refactor(components): isolate password visibility in PasswordInput

vishnu vfb7fc481adff
diff --git a/components/sign-up-form.tsx b/components/sign-up-form.tsx
index 1042ac4b..e82e423f 100644
--- a/components/sign-up-form.tsx
+++ b/components/sign-up-form.tsx
@@ -1,8 +1,8 @@
'use client'
-import { useState } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
+import { useState } from 'react'
import { createClient } from '@/lib/supabase/client'
import { cn } from '@/lib/utils/index'
@@ -95,6 +95,7 @@ export function SignUpForm({
</div>
<PasswordInput
id="password"
+ type="password"
placeholder="********"
required
value={password}
diff --git a/components/ui/input.tsx b/components/ui/input.tsx
index ed81cc9f..d2511deb 100644
--- a/components/ui/input.tsx
+++ b/components/ui/input.tsx
@@ -3,25 +3,20 @@ import * as React from 'react'
import { cn } from '@/lib/utils/index'
export interface InputProps
- extends React.InputHTMLAttributes<HTMLInputElement> {
- rightElement?: React.ReactNode
-}
+ extends React.InputHTMLAttributes<HTMLInputElement> {}
const Input = React.forwardRef<HTMLInputElement, InputProps>(
- ({ className, type, rightElement, ...props }, ref) => {
+ ({ className, type, ...props }, ref) => {
return (
- <div className="relative flex items-center">
- <input
- type={type}
- className={cn(
- 'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
- className
- )}
- ref={ref}
- {...props}
- />
- {rightElement && <div className="absolute right-3">{rightElement}</div>}
- </div>
+ <input
+ type={type}
+ className={cn(
+ 'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
+ className
+ )}
+ ref={ref}
+ {...props}
+ />
)
}
)
diff --git a/components/ui/password-input.tsx b/components/ui/password-input.tsx
index 6b35d31d..aa3b9eaa 100644
--- a/components/ui/password-input.tsx
+++ b/components/ui/password-input.tsx
@@ -8,30 +8,30 @@ import { Input, InputProps } from '@/components/ui/input'
import { Button } from './button'
const PasswordInput = React.forwardRef<HTMLInputElement, InputProps>(
- ({ className, type = 'password', rightElement, ...props }, ref) => {
+ ({ className, type = 'password', ...props }, ref) => {
const [showPassword, setShowPassword] = useState(false)
return (
- <Input
- type={showPassword ? 'text' : type}
- className={className}
- ref={ref}
- {...props}
- rightElement={
- <Button
- type="button"
- variant="ghost"
- size="icon"
- className="h-full px-3 py-2 hover:bg-transparent"
- onClick={() => setShowPassword(!showPassword)}
- >
- {showPassword ? (
- <EyeOff className="h-4 w-4" />
- ) : (
- <Eye className="h-4 w-4" />
- )}
- </Button>
- }
- />
+ <div className="relative flex">
+ <Input
+ type={showPassword ? 'text' : type}
+ className={className}
+ ref={ref}
+ {...props}
+ />
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="h-full px-3 py-2 hover:bg-transparent absolute right-0 flex items-center justify-center"
+ onClick={() => setShowPassword(!showPassword)}
+ >
+ {showPassword ? (
+ <EyeOff className="h-4 w-4" />
+ ) : (
+ <Eye className="h-4 w-4" />
+ )}
+ </Button>
+ </div>
)
}
)