The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
chore: Add password visibility toggle to input component
Kiran K5e50db9bf4bc
diff --git a/packages/ui/src/input.tsx b/packages/ui/src/input.tsxindex 79755c76d9..2b1c2adbb8 100644--- a/packages/ui/src/input.tsx+++ b/packages/ui/src/input.tsx@@ -1,5 +1,6 @@import { cn } from "@dub/utils";-import * as React from "react";+import { EyeIcon, EyeOffIcon } from "lucide-react";+import React, { useCallback, useState } from "react";export interface InputPropsextends React.InputHTMLAttributes<HTMLInputElement> {@@ -8,10 +9,17 @@ export interface InputPropsconst Input = React.forwardRef<HTMLInputElement, InputProps>(({ className, type, ...props }, ref) => {+ const [isPasswordVisible, setIsPasswordVisible] = useState(false);++ const toggleIsPasswordVisible = useCallback(+ () => setIsPasswordVisible(!isPasswordVisible),+ [isPasswordVisible, setIsPasswordVisible],+ );+return (- <>+ <div className="relative"><input- type={type}+ type={isPasswordVisible ? "text" : type}className={cn("w-full max-w-md rounded-md border border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm",className,@@ -19,6 +27,25 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(ref={ref}{...props}/>++ {type === "password" && (+ <button+ className="absolute inset-y-0 right-0 flex items-center rounded-lg px-2.5"+ type="button"+ onClick={() => toggleIsPasswordVisible()}+ aria-label={isPasswordVisible ? "Hide password" : "Show Password"}+ >+ {isPasswordVisible ? (+ <EyeOffIcon+ className="h-5 w-5 flex-none transition"+ aria-hidden+ />+ ) : (+ <EyeIcon className="h-5 w-5 flex-none transition" aria-hidden />+ )}+ </button>+ )}+{props.error && (<spanclassName="block text-sm text-red-500"@@ -28,7 +55,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>({props.error}</span>)}- </>+ </div>);},);