Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(ui): add toggle to show/hide password on sign in/up form (#796)

18feb06704ea7b6caaa
diff --git a/src/components/layouts/layout.tsx b/src/components/layouts/layout.tsx
index a6e96197e3..1e8deae343 100644
--- a/src/components/layouts/layout.tsx
+++ b/src/components/layouts/layout.tsx
@@ -210,7 +210,10 @@ export default function Layout(props: PropsWithChildren) {
<li>
<ul role="list" className="-mx-2 space-y-1">
{navigation.map((item) => (
- <li key={item.name} onClick={() => setSidebarOpen(false)}>
+ <li
+ key={item.name}
+ onClick={() => setSidebarOpen(false)}
+ >
<Link
href={item.href}
className={clsx(
diff --git a/src/components/ui/password-input.tsx b/src/components/ui/password-input.tsx
new file mode 100644
index 0000000000..3af2f6e31e
--- /dev/null
+++ b/src/components/ui/password-input.tsx
@@ -0,0 +1,42 @@
+import * as React from "react";
+import { cn } from "@/src/utils/tailwind";
+import { Eye, EyeOff } from "lucide-react";
+
+export interface PasswordInputProps
+ extends React.InputHTMLAttributes<HTMLInputElement> {}
+
+const PasswordInput = React.forwardRef<HTMLInputElement, PasswordInputProps>(
+ ({ className, ...props }, ref) => {
+ const [showPassword, setShowPassword] = React.useState(false);
+
+ return (
+ <div className="relative">
+ <input
+ type={showPassword ? "text" : "password"}
+ className={cn(
+ "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 pr-10 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}
+ />
+ <button
+ type="button"
+ className="absolute right-3 top-1/2 -translate-y-1/2 transform cursor-pointer"
+ onClick={() => setShowPassword(!showPassword)}
+ title={showPassword ? "Hide password" : "Show password"}
+ >
+ {showPassword ? (
+ <EyeOff className="h-5 w-5 text-gray-400" />
+ ) : (
+ <Eye className="h-5 w-5 text-gray-400" />
+ )}
+ </button>
+ </div>
+ );
+ },
+);
+
+PasswordInput.displayName = "PasswordInput";
+
+export { PasswordInput };
diff --git a/src/components/ui/separator.tsx b/src/components/ui/separator.tsx
index 3103b3d8f2..5efc2e4535 100644
--- a/src/components/ui/separator.tsx
+++ b/src/components/ui/separator.tsx
@@ -1,9 +1,9 @@
-"use client"
+"use client";
-import * as React from "react"
-import * as SeparatorPrimitive from "@radix-ui/react-separator"
+import * as React from "react";
+import * as SeparatorPrimitive from "@radix-ui/react-separator";
-import { cn } from "@/src/utils/tailwind"
+import { cn } from "@/src/utils/tailwind";
const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>,
@@ -11,7 +11,7 @@ const Separator = React.forwardRef<
>(
(
{ className, orientation = "horizontal", decorative = true, ...props },
- ref
+ ref,
) => (
<SeparatorPrimitive.Root
ref={ref}
@@ -20,12 +20,12 @@ const Separator = React.forwardRef<
className={cn(
"shrink-0 bg-border",
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
- className
+ className,
)}
{...props}
/>
- )
-)
-Separator.displayName = SeparatorPrimitive.Root.displayName
+ ),
+);
+Separator.displayName = SeparatorPrimitive.Root.displayName;
-export { Separator }
+export { Separator };
diff --git a/src/pages/auth/sign-in.tsx b/src/pages/auth/sign-in.tsx
index 3e8c306790..f12c1d57d6 100644
--- a/src/pages/auth/sign-in.tsx
+++ b/src/pages/auth/sign-in.tsx
@@ -25,6 +25,7 @@ import { usePostHog } from "posthog-js/react";
import { Divider } from "@tremor/react";
import { CloudPrivacyNotice } from "@/src/features/auth/components/AuthCloudPrivacyNotice";
import { CloudRegionSwitch } from "@/src/features/auth/components/AuthCloudRegionSwitch";
+import { PasswordInput } from "@/src/components/ui/password-input";
const credentialAuthForm = z.object({
email: z.string().email(),
@@ -196,7 +197,7 @@ export default function SignIn({ authProviders }: PageProps) {
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl>
- <Input type="password" {...field} />
+ <PasswordInput {...field} />
</FormControl>
<FormMessage />
</FormItem>
diff --git a/src/pages/auth/sign-up.tsx b/src/pages/auth/sign-up.tsx
index 186f51c69d..046fe09f86 100644
--- a/src/pages/auth/sign-up.tsx
+++ b/src/pages/auth/sign-up.tsx
@@ -22,6 +22,7 @@ import { usePostHog } from "posthog-js/react";
import { CloudPrivacyNotice } from "@/src/features/auth/components/AuthCloudPrivacyNotice";
import { CloudRegionSwitch } from "@/src/features/auth/components/AuthCloudRegionSwitch";
import { SSOButtons, type PageProps } from "@/src/pages/auth/sign-in";
+import { PasswordInput } from "@/src/components/ui/password-input";
// Use the same getServerSideProps function as src/pages/auth/sign-in.tsx
export { getServerSideProps } from "@/src/pages/auth/sign-in";
@@ -135,7 +136,7 @@ export default function SignIn({ authProviders }: PageProps) {
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl>
- <Input type="password" {...field} />
+ <PasswordInput {...field} />
</FormControl>
<FormMessage />
</FormItem>