🪢 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): Create design-system Input component (#17494)
Ben Bachemec2bd60bdcc6
diff --git a/web/eslint.config.mjs b/web/eslint.config.mjsindex 91c15cbf68..319760ef2f 100644--- a/web/eslint.config.mjs+++ b/web/eslint.config.mjs@@ -52,6 +52,12 @@ const sentryCapturePattern = {"Do not capture directly — route through the reportError seam (@/src/utils/reportError) or a helper that wraps it (captureUnknownError, reportParserWorkerError), so one seam owns error classification. See the reportError doc comment and .agents/skills/sentry-instrumentation/SKILL.md.",};+const designSystemInternalPattern = {+ regex: "(^|/)design-system/internal(?:/|$)",+ message:+ "Design-system internals may only be imported by other design-system components.",+};+// eslint-plugin-tailwindcss types this as Config | ConfigArray, but the// recommended export is a single flat config object with rules at runtime.const tailwindcssRecommendedConfig =@@ -207,11 +213,15 @@ export default [// Root design-system components follow `Name/Name.tsx`, optionally alongside// `Name/Name.stories.tsx`. Files must be directly inside a PascalCase folder,// match that folder's name, and expose a matching named runtime export. The- // table subtree is a domain-specific exception with its own structure.+ // table and internal subtrees are domain-specific exceptions with their own+ // structure.{name: "langfuse/web/design-system-component-structure",files: ["src/components/design-system/**/*.{ts,tsx}"],- ignores: ["src/components/design-system/table/**"],+ ignores: [+ "src/components/design-system/internal/**",+ "src/components/design-system/table/**",+ ],plugins: {"check-file": checkFile,},@@ -416,6 +426,23 @@ export default [// Restricted import paths (patterns defined at the top of this file).{name: "langfuse/web/restricted-imports",+ rules: {+ "no-restricted-imports": [+ "error",+ {+ patterns: [+ ...restrictedImportPatterns,+ sentryCapturePattern,+ designSystemInternalPattern,+ ],+ },+ ],+ },+ },++ {+ name: "langfuse/web/design-system-allow-internal-imports",+ files: ["src/components/design-system/**/*.{ts,tsx}"],rules: {"no-restricted-imports": ["error",@@ -426,6 +453,23 @@ export default [},},+ {+ name: "langfuse/web/design-system-internal-naming",+ files: ["src/components/design-system/internal/**/*.{ts,tsx}"],+ plugins: {+ "check-file": checkFile,+ },+ rules: {+ "check-file/folder-naming-convention": [+ "warn",+ {+ "src/components/design-system/*/": "KEBAB_CASE",+ "src/components/design-system/internal/*/": "PASCAL_CASE",+ },+ ],+ },+ },+// Sanctioned homes for raw Sentry capture APIs: the reportError seam itself// and the SDK init (`import * as Sentry` would otherwise trip the// importNames restriction). Last-match wins in flat config, so these files@@ -437,7 +481,7 @@ export default ["no-restricted-imports": ["error",{- patterns: restrictedImportPatterns,+ patterns: [...restrictedImportPatterns, designSystemInternalPattern],},],},diff --git a/web/src/components/design-system/Input/Input.stories.tsx b/web/src/components/design-system/Input/Input.stories.tsxnew file mode 100644index 0000000000..aa44c91522--- /dev/null+++ b/web/src/components/design-system/Input/Input.stories.tsx@@ -0,0 +1,51 @@+import { expect, userEvent, within } from "storybook/test";++import preview from "../../../../.storybook/preview";+import { Input } from "./Input";++const meta = preview.meta({+ component: Input,+});++export const Default = meta.story({+ args: {+ "aria-label": "Dataset name",+ placeholder: "Enter a dataset name",+ },+});++export const WithValue = meta.story({+ args: {+ "aria-label": "Dataset name",+ defaultValue: "production/evaluations",+ },+});++export const Invalid = meta.story({+ args: {+ "aria-label": "Dataset name",+ "aria-invalid": true,+ defaultValue: "Existing dataset",+ },+});++export const Disabled = meta.story({+ args: {+ "aria-label": "Dataset name",+ disabled: true,+ defaultValue: "production/evaluations",+ },+});++export const TestAcceptsText = meta.story({+ name: "(Test) Accepts Text",+ args: {+ "aria-label": "Dataset name",+ },+ play: async ({ canvasElement }) => {+ const input = within(canvasElement).getByLabelText("Dataset name");++ await userEvent.type(input, "production/evaluations");+ await expect(input).toHaveValue("production/evaluations");+ },+});diff --git a/web/src/components/design-system/Input/Input.tsx b/web/src/components/design-system/Input/Input.tsxnew file mode 100644index 0000000000..9dd10ca193--- /dev/null+++ b/web/src/components/design-system/Input/Input.tsx@@ -0,0 +1,43 @@+import { type InputHTMLAttributes, type Ref } from "react";+import { InputControl } from "../internal/InputControl/InputControl";++type InputProps = Pick<+ InputHTMLAttributes<HTMLInputElement>,+ | "aria-describedby"+ | "aria-invalid"+ | "aria-label"+ | "aria-labelledby"+ | "autoComplete"+ | "autoFocus"+ | "defaultValue"+ | "disabled"+ | "id"+ | "inputMode"+ | "maxLength"+ | "minLength"+ | "name"+ | "onBlur"+ | "onChange"+ | "onFocus"+ | "placeholder"+ | "readOnly"+ | "required"+ | "tabIndex"+ | "type"+ | "value"+> & {+ allowPasswordManager?: boolean;+ ref?: Ref<HTMLInputElement>;+};++export function Input({ allowPasswordManager, ref, ...props }: InputProps) {+ return (+ <InputControl contentLayout="text">+ <input+ {...props}+ {...(!allowPasswordManager && { "data-1p-ignore": true })}+ ref={ref}+ />+ </InputControl>+ );+}diff --git a/web/src/components/design-system/MultiSelectInput/MultiSelectInput.tsx b/web/src/components/design-system/MultiSelectInput/MultiSelectInput.tsxindex 740436c99d..7616af8972 100644--- a/web/src/components/design-system/MultiSelectInput/MultiSelectInput.tsx+++ b/web/src/components/design-system/MultiSelectInput/MultiSelectInput.tsx@@ -9,6 +9,7 @@ import { useScrollGradients } from "@/src/hooks/useScrollGradients";import { cn } from "@/src/utils/tailwind";import { useLayerContainer } from "@/src/context/LayerContext/LayerContext";import { stopScrollPropagation } from "@/src/hooks/stopScrollPropagation";+import { InputControl } from "../internal/InputControl/InputControl";type MultiSelectOption<V> = {value: V;@@ -50,28 +51,27 @@ function MultiSelectInputInner<V extends string>(return (<PopoverPrimitive.Root open={open} onOpenChange={setOpen}>- <PopoverPrimitive.Trigger asChild>- <button+ <InputControl contentLayout="spread">+ <PopoverPrimitive.Triggerref={ref}type="button"role="combobox"aria-controls={listId}aria-expanded={open}- className={cn(- "border-input bg-background ring-offset-background placeholder:text-foreground-tertiary focus:ring-ring disabled:bg-muted/50 flex h-8 w-full items-center justify-between gap-1 rounded-md border px-3 py-2 text-sm focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50",- value.length === 0 && "text-muted-foreground",- )}{...triggerProps}><span- className="min-w-0 flex-1 truncate text-left"+ className={cn(+ "min-w-0 flex-1 truncate text-left",+ value.length === 0 && "text-muted-foreground",+ )}title={value.length > 0 ? selectedLabel : undefined}>{value.length > 0 ? selectedLabel : placeholder}</span><ChevronDown className="size-4 shrink-0 opacity-50" />- </button>- </PopoverPrimitive.Trigger>+ </PopoverPrimitive.Trigger>+ </InputControl><PopoverPrimitive.Portal container={container}><PopoverPrimitive.Contentalign="start"diff --git a/web/src/components/design-system/PasswordInput/PasswordInput.tsx b/web/src/components/design-system/PasswordInput/PasswordInput.tsxindex abc6214da6..bc08b7f7a4 100644--- a/web/src/components/design-system/PasswordInput/PasswordInput.tsx+++ b/web/src/components/design-system/PasswordInput/PasswordInput.tsx@@ -1,5 +1,6 @@import { useState, type InputHTMLAttributes, type Ref } from "react";import { Eye, EyeOff } from "lucide-react";+import { InputControl } from "../internal/InputControl/InputControl";type PasswordInputProps = Pick<InputHTMLAttributes<HTMLInputElement>,@@ -27,36 +28,25 @@ type PasswordInputProps = Pick<export function PasswordInput({ ref, disabled, ...props }: PasswordInputProps) {const [isPasswordVisible, setIsPasswordVisible] = useState(false);+ const VisibilityIcon = isPasswordVisible ? EyeOff : Eye;return (- <div className="relative">+ <InputControl+ contentLayout="text"+ trailingAction={{+ label: isPasswordVisible ? "Hide password" : "Show password",+ icon: VisibilityIcon,+ disabled,+ pressed: isPasswordVisible,+ onClick: () => setIsPasswordVisible((visible) => !visible),+ }}+ ><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}- // Keep the reveal toggle out of the tab order so Tab moves between the- // form's inputs. It stays reachable for pointer and screen reader users.- tabIndex={-1}- 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>+ </InputControl>);}diff --git a/web/src/components/design-system/SelectInput/SelectInput.tsx b/web/src/components/design-system/SelectInput/SelectInput.tsxindex e87b30e004..f4f0d4f9f4 100644--- a/web/src/components/design-system/SelectInput/SelectInput.tsx+++ b/web/src/components/design-system/SelectInput/SelectInput.tsx@@ -9,6 +9,7 @@ import { useLayerContainer } from "@/src/context/LayerContext/LayerContext";import { Check, ChevronDown, ChevronUp } from "lucide-react";import { cn } from "@/src/utils/tailwind";import { useScrollGradients } from "@/src/hooks/useScrollGradients";+import { InputControl } from "../internal/InputControl/InputControl";type SelectOption<V> =| {@@ -123,22 +124,23 @@ function SelectInputInner<V extends string>(open={open}onOpenChange={setOpen}>- <SelectPrimitive.Trigger- ref={ref}- className="border-input bg-background ring-offset-background placeholder:text-foreground-tertiary focus:ring-ring disabled:bg-muted/50 flex h-8 w-full items-center justify-between gap-1 rounded-md border px-3 py-2 text-sm focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50"- title={selectedOption?.label}- {...triggerProps}- >- <span- className="min-w-0 flex-1 truncate text-left"+ <InputControl contentLayout="spread">+ <SelectPrimitive.Trigger+ ref={ref}title={selectedOption?.label}+ {...triggerProps}>- <SelectPrimitive.SelectValue placeholder={placeholder} />- </span>- <SelectPrimitive.Icon asChild>- <ChevronDown className="h-4 w-4 shrink-0 opacity-50" />- </SelectPrimitive.Icon>- </SelectPrimitive.Trigger>+ <span+ className="min-w-0 flex-1 truncate text-left"+ title={selectedOption?.label}+ >+ <SelectPrimitive.SelectValue placeholder={placeholder} />+ </span>+ <SelectPrimitive.Icon asChild>+ <ChevronDown className="h-4 w-4 shrink-0 opacity-50" />+ </SelectPrimitive.Icon>+ </SelectPrimitive.Trigger>+ </InputControl><SelectPrimitive.Portal container={container}><SelectPrimitive.Contentposition="popper"diff --git a/web/src/components/design-system/internal/InputControl/InputControl.tsx b/web/src/components/design-system/internal/InputControl/InputControl.tsxnew file mode 100644index 0000000000..0b0499e162--- /dev/null+++ b/web/src/components/design-system/internal/InputControl/InputControl.tsx@@ -0,0 +1,81 @@+import { Slot } from "@radix-ui/react-slot";+import { cva } from "class-variance-authority";+import { type LucideIcon } from "lucide-react";+import { type ComponentPropsWithoutRef } from "react";++const inputControlVariants = cva(+ "border-input bg-background ring-offset-background placeholder:text-foreground-tertiary focus-visible:ring-ring disabled:bg-muted/50 h-8 w-full rounded-md border px-3 py-2 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",+ {+ variants: {+ contentLayout: {+ text: "min-w-14",+ spread: "flex min-w-0 items-center justify-between gap-1",+ },+ trailingAction: {+ true: "pr-10",+ false: null,+ },+ },+ },+);++type InputControlProps = Omit<+ ComponentPropsWithoutRef<typeof Slot>,+ "className"+> & {+ contentLayout: "text" | "spread";+ trailingAction?: {+ label: string;+ icon: LucideIcon;+ disabled?: boolean;+ pressed?: boolean;+ onClick: () => void;+ };+};++/**+ * Applies the shared form-control appearance directly to one interactive child.+ * Use explicit variants for root layout differences. The control owns the+ * positioning and spacing of an optional trailing action; specialized inputs+ * own the action's behavior and inner content.+ */+export function InputControl({+ contentLayout,+ trailingAction,+ ...props+}: InputControlProps) {+ const control = (+ <Slot+ className={inputControlVariants({+ contentLayout,+ trailingAction: Boolean(trailingAction),+ })}+ {...props}+ />+ );++ if (!trailingAction) return control;++ const TrailingActionIcon = trailingAction.icon;++ return (+ <div className="relative">+ {control}+ <button+ type="button"+ aria-label={trailingAction.label}+ aria-pressed={trailingAction.pressed}+ disabled={trailingAction.disabled}+ // Keep the action out of the tab order so Tab moves between inputs.+ tabIndex={-1}+ className="absolute top-1/2 right-3 flex -translate-y-1/2 cursor-pointer items-center justify-center disabled:cursor-not-allowed"+ onClick={trailingAction.onClick}+ >+ <TrailingActionIcon+ aria-hidden="true"+ className="text-muted-foreground size-4"+ />+ </button>+ </div>+ );+}diff --git a/web/src/features/datasets/components/DatasetForm.tsx b/web/src/features/datasets/components/DatasetForm.tsxindex 8bdea85b9e..5445d04a45 100644--- a/web/src/features/datasets/components/DatasetForm.tsx+++ b/web/src/features/datasets/components/DatasetForm.tsx@@ -21,7 +21,7 @@ import {forwardRef,useImperativeHandle,} from "react";-import { Input } from "@/src/components/ui/input";+import { Input } from "@/src/components/design-system/Input/Input";import { CodeMirrorEditor } from "@/src/components/editor";import {DatasetNameSchema,