🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
refactor(web): clean up `PasswordInput` (#16585)
Ben Bachemc05b36cf1291
diff --git a/web/.storybook/main.ts b/web/.storybook/main.tsindex 156109959b..83dc99e67b 100644--- a/web/.storybook/main.ts+++ b/web/.storybook/main.ts@@ -17,6 +17,7 @@ const DESIGN_COMPONENT_STORIES = ["Dropzone/Dropzone","LangfuseIcon/LangfuseIcon","LangfuseLogo/LangfuseLogo",+ "PasswordInput/PasswordInput","Progress/Progress","SearchInput/SearchInput","Spinner/Spinner",diff --git a/web/src/components/design-system/PasswordInput/PasswordInput.stories.tsx b/web/src/components/design-system/PasswordInput/PasswordInput.stories.tsxnew file mode 100644index 0000000000..18bb9ce87c--- /dev/null+++ b/web/src/components/design-system/PasswordInput/PasswordInput.stories.tsx@@ -0,0 +1,60 @@+import { expect, userEvent, within } from "storybook/test";+import preview from "../../../../.storybook/preview";+import { PasswordInput } from "./PasswordInput";++const meta = preview.meta({+ component: PasswordInput,+});++export const Default = meta.story({+ args: {+ "aria-label": "Password",+ placeholder: "Enter your password",+ },+});++export const Disabled = meta.story({+ args: {+ "aria-label": "Password",+ disabled: true,+ placeholder: "Enter your password",+ },+});++export const TestTogglesVisibility = meta.story({+ name: "(Test) Toggles Visibility",+ args: {+ "aria-label": "Password",+ defaultValue: "secret",+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const input = canvas.getByLabelText("Password");+ const toggle = canvas.getByRole("button", { name: "Show password" });++ await expect(input).toHaveAttribute("type", "password");+ await userEvent.click(toggle);+ await expect(input).toHaveAttribute("type", "text");+ await expect(toggle).toHaveAccessibleName("Hide password");+ await expect(toggle).toHaveAttribute("aria-pressed", "true");++ await userEvent.click(toggle);+ await expect(input).toHaveAttribute("type", "password");+ },+});++export const TestDisablesVisibilityToggle = meta.story({+ name: "(Test) Disables Visibility Toggle",+ args: {+ "aria-label": "Password",+ disabled: true,+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const input = canvas.getByLabelText("Password");+ const toggle = canvas.getByRole("button", { name: "Show password" });++ await userEvent.click(toggle);+ await expect(input).toHaveAttribute("type", "password");+ },+});diff --git a/web/src/components/design-system/PasswordInput/PasswordInput.tsx b/web/src/components/design-system/PasswordInput/PasswordInput.tsxnew file mode 100644index 0000000000..b428dc9749--- /dev/null+++ b/web/src/components/design-system/PasswordInput/PasswordInput.tsx@@ -0,0 +1,59 @@+import { useState, type InputHTMLAttributes, type Ref } from "react";+import { Eye, EyeOff } from "lucide-react";++type PasswordInputProps = Pick<+ InputHTMLAttributes<HTMLInputElement>,+ | "aria-describedby"+ | "aria-invalid"+ | "aria-label"+ | "aria-labelledby"+ | "autoComplete"+ | "autoFocus"+ | "defaultValue"+ | "disabled"+ | "id"+ | "name"+ | "onBlur"+ | "onChange"+ | "onFocus"+ | "placeholder"+ | "readOnly"+ | "required"+ | "tabIndex"+ | "value"+> & {+ ref?: Ref<HTMLInputElement>;+};++export function PasswordInput({ ref, disabled, ...props }: PasswordInputProps) {+ const [isPasswordVisible, setIsPasswordVisible] = useState(false);++ return (+ <div className="relative">+ <input+ {...props}+ ref={ref}+ type={isPasswordVisible ? "text" : "password"}+ disabled={disabled}+ className="border-input bg-background ring-offset-background placeholder:text-foreground-tertiary focus-visible:ring-ring flex h-8 w-full rounded-md border px-3 py-2 pr-10 text-sm file:border-0 file:bg-transparent file:text-sm file:font-bold focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50"+ />+ <button+ type="button"+ aria-label={isPasswordVisible ? "Hide password" : "Show password"}+ aria-pressed={isPasswordVisible}+ disabled={disabled}+ className="absolute top-1/2 right-3 -translate-y-1/2 transform cursor-pointer disabled:cursor-not-allowed"+ onClick={() => setIsPasswordVisible((visible) => !visible)}+ >+ {isPasswordVisible ? (+ <EyeOff+ aria-hidden="true"+ className="text-muted-foreground h-5 w-5"+ />+ ) : (+ <Eye aria-hidden="true" className="text-muted-foreground h-5 w-5" />+ )}+ </button>+ </div>+ );+}diff --git a/web/src/components/ui/password-input.tsx b/web/src/components/ui/password-input.tsxdeleted file mode 100644index 7b3f68e4e9..0000000000--- a/web/src/components/ui/password-input.tsx+++ /dev/null@@ -1,42 +0,0 @@-/* eslint-disable @repo/no-style-props */-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(- "border-input bg-background ring-offset-background placeholder:text-foreground-tertiary focus-visible:ring-ring flex h-8 w-full rounded-md border px-3 py-2 pr-10 text-sm file:border-0 file:bg-transparent file:text-sm file:font-bold focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50",- className,- )}- ref={ref}- {...props}- />- <button- type="button"- className="absolute top-1/2 right-3 -translate-y-1/2 transform cursor-pointer"- onClick={() => setShowPassword(!showPassword)}- title={showPassword ? "Hide password" : "Show password"}- >- {showPassword ? (- <EyeOff className="text-muted-foreground h-5 w-5" />- ) : (- <Eye className="text-muted-foreground h-5 w-5" />- )}- </button>- </div>- );- },-);--PasswordInput.displayName = "PasswordInput";--export { PasswordInput };diff --git a/web/src/features/auth-credentials/components/ResetPasswordPage.tsx b/web/src/features/auth-credentials/components/ResetPasswordPage.tsxindex 6bc7d2056a..aad7ce11c8 100644--- a/web/src/features/auth-credentials/components/ResetPasswordPage.tsx+++ b/web/src/features/auth-credentials/components/ResetPasswordPage.tsx@@ -13,7 +13,7 @@ import {FormMessage,} from "@/src/components/ui/form";import { Input } from "@/src/components/ui/input";-import { PasswordInput } from "@/src/components/ui/password-input";+import { PasswordInput } from "@/src/components/design-system/PasswordInput/PasswordInput";import { LangfuseIcon } from "@/src/components/design-system/LangfuseIcon/LangfuseIcon";import { useSession } from "next-auth/react";import { ArrowLeft, ShieldCheck } from "lucide-react";diff --git a/web/src/features/blobstorage-integration/components/StorageProviderFields.tsx b/web/src/features/blobstorage-integration/components/StorageProviderFields.tsxindex df822b0c1b..d28443df31 100644--- a/web/src/features/blobstorage-integration/components/StorageProviderFields.tsx+++ b/web/src/features/blobstorage-integration/components/StorageProviderFields.tsx@@ -8,7 +8,7 @@ import {FormMessage,} from "@/src/components/ui/form";import { Input } from "@/src/components/ui/input";-import { PasswordInput } from "@/src/components/ui/password-input";+import { PasswordInput } from "@/src/components/design-system/PasswordInput/PasswordInput";import { Switch } from "@/src/components/design-system/Switch/Switch";import {Select,diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsxindex 6d87a8e3b5..e839badf4f 100644--- a/web/src/pages/auth/sign-in.tsx+++ b/web/src/pages/auth/sign-in.tsx@@ -33,7 +33,7 @@ import { useForm } from "react-hook-form";import * as z from "zod";import { CloudPrivacyNotice } from "@/src/features/auth/components/AuthCloudPrivacyNotice";import { CloudRegionSwitch } from "@/src/features/auth/components/AuthCloudRegionSwitch";-import { PasswordInput } from "@/src/components/ui/password-input";+import { PasswordInput } from "@/src/components/design-system/PasswordInput/PasswordInput";import { isAnySsoConfigured } from "@/src/ee/features/multi-tenant-sso/utils";import { isEmailVerificationRequired } from "@/src/features/auth-credentials/lib/credentialsUtils";import { Code, Key } from "lucide-react";diff --git a/web/src/pages/auth/sign-up.tsx b/web/src/pages/auth/sign-up.tsxindex ad487172fb..b0747f6602 100644--- a/web/src/pages/auth/sign-up.tsx+++ b/web/src/pages/auth/sign-up.tsx@@ -26,7 +26,7 @@ import {useHuggingFaceRedirect,type PageProps,} from "@/src/pages/auth/sign-in";-import { PasswordInput } from "@/src/components/ui/password-input";+import { PasswordInput } from "@/src/components/design-system/PasswordInput/PasswordInput";import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";import { useRouter } from "next/router";import { getSafeRedirectPath } from "@/src/utils/redirect";diff --git a/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx b/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsxindex 63e042066b..fe3e03ec4f 100644--- a/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx+++ b/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx@@ -12,7 +12,7 @@ import {FormLabel,FormMessage,} from "@/src/components/ui/form";-import { PasswordInput } from "@/src/components/ui/password-input";+import { PasswordInput } from "@/src/components/design-system/PasswordInput/PasswordInput";import { Switch } from "@/src/components/design-system/Switch/Switch";import {Select,diff --git a/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx b/web/src/pages/project/[projectId]/settings/integrations/posthog.tsxindex 1c45b2b64b..3e7077543b 100644--- a/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx+++ b/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx@@ -13,7 +13,7 @@ import {FormMessage,} from "@/src/components/ui/form";import { Input } from "@/src/components/ui/input";-import { PasswordInput } from "@/src/components/ui/password-input";+import { PasswordInput } from "@/src/components/design-system/PasswordInput/PasswordInput";import { Switch } from "@/src/components/design-system/Switch/Switch";import {Select,