One native input with consistent surfaces, CSS floating labels, and wave motion.
Variants
The name your teammates will see.
Sizes
h-7 — 28px control height.
h-8 — 32px control height.
h-10 — 40px control height.
h-12 — 48px control height.
Labels
Focus or enter a value to lift the label.
Prefilled values keep their label raised.
Validation
0/24 characters. Letters, numbers, and punctuation are welcome.
This value is managed by your organization.
Your administrator has paused invitations.
Groups and Controllers
Only digits are accepted.
Form
Purpose
An input lets people enter or edit one line of text, such as a name, email address, or search term.
Parts & Composition
Use Input on its own for a labeled field. Use InputGroup when the field shares a row with InputClear or an action button. The input manages its label and description through its own props.
API & Props
| Part / Prop | Purpose |
|---|---|
Input | Control (variant: filled | outline | ghost | underline, size: xs | sm | md | lg, label, labelVariant: standard | floating | wave, icon, iconPosition: start | end, waveDelay, description, htmlSize, containerProps, value, defaultValue, onValueChange, controller) |
InputGroup | Wrapper (data-slot="input-group", group/control) that flexes child Input alongside InputClear or action buttons |
InputClear | Clears the grouped input and returns focus (variant / size via buttonVariants, defaults to ghost / icon-sm with <DvClose />) |
InputLabel, InputDescription, InputControlShell | Semantic label, helper/error copy (aria-describedby), and control chrome wrapper |
createInputController() | Programmatic getValue(), setValue(), clear(), and focus() |
Common props in detail
| Prop / part | Purpose |
|---|---|
value / defaultValue | Use a controlled string or supply its initial uncontrolled value. |
onValueChange | Receives the next string and SDK change details. Update the controlled value in this callback. |
name / form | Identify the serialized value and optionally associate the input with an external form. |
Interaction states
| State | Behavior |
|---|---|
| Rest | filled renders border-input bg-card text-card-foreground shadow-sm; outline uses bg-transparent; ghost uses border-transparent bg-muted; underline uses border-b-2 border-input. |
| Focus | Applies focusRing (border-ring/30 ring-3 ring-ring/15 + light/dark brightness shift); underline suppresses the box ring (ring-0) and animates its 2px bg-primary bottom bar (scale-x-100). |
| Floating / Wave | :focus or :not(:placeholder-shown) lifts the label from top-1/2 to top-0 (scale(0.85)) with a var(--background) border notch; wave staggers each grapheme up to 300ms total. |
| Invalid | aria-invalid / data-invalid applies border-destructive ring-3 ring-destructive/25 (underline suppresses the box ring with ring-0 and turns the bottom bar bg-destructive), and turns labels, icons, and descriptions text-destructive. |
| Disabled / Read-only | disabled / data-disabled sets opacity-50 and cursor-not-allowed; readOnly sets cursor-default. |
Theming, Layout & Responsiveness
Uses shadcn semantic tokens (secondary, secondary-foreground, foreground, muted, muted-foreground, input, ring, primary, destructive, background) across light, dark, and custom themes.
| Attribute | Meaning |
|---|---|
data-slot="input-container" | Outer container (input-control, input-label, input-description, input-group on subparts). |
data-variant, data-size | Reflects filled | outline | ghost | underline and xs | sm | md | lg (controlHeights). |
data-invalid, data-disabled | Propagated to container and shell for styling labels, icons, and underline bars. |
Input heights follow controlHeights (xs 28px, sm 32px, md 40px, lg 48px) at every breakpoint. Includes touch-manipulation via focusRing, logical ps- / pe- adornment padding for dir="rtl", and min-w-0 flex-1 inside InputGroup. Reduced motion disables label, icon, and underline transitions.
Motion & Accessibility
InputLabel links to the native <input> via htmlFor/id, and description merges into aria-describedby alongside any caller-supplied IDs. Non-text input types (date, file, etc.) automatically fall back to standard labels. Give icon-less inputs without a visible label an explicit aria-label, and compose with @ui-sdk/react/field when form-level validation messages are needed.
Guidance for Coding Agents
Use Input with a visible label or an explicit accessible name. Pass outer layout props through containerProps and field props to the input. Keep controlled text in onValueChange and use the input’s native form semantics.
Pass className / ref for the <input> itself and containerProps for outer layout (w-full, max-w-sm, etc.). Use standard labels for native non-text controls such as dates.
Start from the closest Preview → Usage example and use this page’s API table for component parts and options. For inherited props, callbacks, keyboard behavior, and rendering options, consult UI SDK Input.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/input'use client';
import {
createInputController,
type InputController,
type InputState,
type InputValueChangeReason,
Input as SDKInput,
InputClear as SDKInputClear,
InputGroup as SDKInputGroup,
} from '@ui-sdk/react/input';
import { cva, type VariantProps } from 'class-variance-authority';
import { X } from 'lucide-react';
import { type ComponentProps, type ReactNode, useId } from 'react';
import { type ButtonProps, buttonVariants } from '@/components/devvarena-ui/button';
import {
clampWaveDelay,
controlHeights,
controlTextSizes,
focusRing,
getTextFieldIconPadding,
partClass,
type StandardControlSize,
textFieldLabelSegmenter,
textFieldLayout,
textFieldSurfaces,
textFieldUnderlineMotion,
} from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const inputVariants = cva(
`w-full min-w-0 rounded-lg border py-2 shadow-sm transition-[border-color,background-color,box-shadow,filter] duration-200 ${focusRing} disabled:cursor-not-allowed disabled:opacity-50 read-only:cursor-default motion-reduce:transition-none`,
{
variants: {
variant: {
...textFieldSurfaces,
underline: `${textFieldSurfaces.underline} ${textFieldUnderlineMotion}`,
},
size: {
xs: `${controlHeights.xs} px-2 text-xs`,
sm: `${controlHeights.sm} px-2.5 text-xs`,
md: `${controlHeights.md} px-3 text-sm`,
lg: `${controlHeights.lg} px-4 text-base`,
},
},
defaultVariants: { variant: 'filled', size: 'md' },
},
);
type InputSize = StandardControlSize;
type NativeInputProps = Omit<ComponentProps<typeof SDKInput>, 'children' | 'size'>;
type InputProps = NativeInputProps &
VariantProps<typeof inputVariants> & {
/** Native input size attribute, in characters. */
htmlSize?: number;
label?: string;
labelVariant?: 'standard' | 'floating' | 'wave';
icon?: ReactNode;
iconPosition?: 'start' | 'end';
/** Per-grapheme delay in milliseconds; total staggering is capped at 300ms. */
waveDelay?: number;
description?: ReactNode;
/** Native props/ref for the outer layout; className/ref target the input itself. */
containerProps?: Omit<ComponentProps<'div'>, 'children'>;
};
const animatedLabelTypes = new Set(['text', 'email', 'password', 'search', 'tel', 'url', 'number']);
const labelActive =
'has-[input:focus]:[--field-label-scale:0.85] has-[input:not(:placeholder-shown)]:[--field-label-scale:0.85]';
const labelPatch =
'group-has-[input:focus]/input:bg-[linear-gradient(to_bottom,transparent_20%,var(--background)_40%,var(--background)_65%,transparent_85%)] group-has-[input:not(:placeholder-shown)]/input:bg-[linear-gradient(to_bottom,transparent_20%,var(--background)_40%,var(--background)_65%,transparent_85%)]';
const labelMotion =
'inline-block origin-left scale-[var(--field-label-scale,1)] transition-[scale,color] duration-200 ease-out group-has-[input:focus]/input:text-primary group-data-invalid/input:text-destructive motion-reduce:transition-none rtl:origin-right';
function InputLabel({ className, ...props }: ComponentProps<'label'>) {
// biome-ignore lint/a11y/noLabelWithoutControl: htmlFor and label children are supplied by callers via props.
return <label {...props} data-slot="input-label" className={className} />;
}
function InputDescription({ className, ...props }: ComponentProps<'p'>) {
return <p {...props} data-slot="input-description" className={cn('m-0 mt-1', className)} />;
}
/** Chrome wrapper for icons, floating labels, and underline affordances. */
function InputControlShell({ className, ...props }: ComponentProps<'div'>) {
return <div data-slot="input-control" className={className} {...props} />;
}
/** One native input contract; label position comes from CSS, including autofilled values. */
function Input({
label,
labelVariant = 'standard',
variant = 'filled',
size = 'md',
htmlSize,
icon,
iconPosition = 'start',
waveDelay = 24,
description,
containerProps,
id,
type = 'text',
placeholder,
className,
'aria-describedby': describedBy,
...props
}: InputProps) {
const generatedId = useId();
const inputId = id ?? generatedId;
const descriptionId = `${inputId}-description`;
const animated = Boolean(label) && labelVariant !== 'standard' && animatedLabelTypes.has(type);
const hasDescription = description !== undefined && description !== null && description !== false;
const invalid = Boolean(props['aria-invalid']) && props['aria-invalid'] !== 'false';
const graphemes =
animated && labelVariant === 'wave' && label
? Array.from(textFieldLabelSegmenter.segment(label), (part) => ({
text: part.segment,
offset: part.index,
}))
: [];
const delay = clampWaveDelay(waveDelay, graphemes.length);
const underline = variant === 'underline';
const resolvedSize: InputSize = size ?? 'md';
const paddingForIcon = icon ? getTextFieldIconPadding(iconPosition, underline) : undefined;
return (
<div
{...containerProps}
data-slot="input-container"
data-disabled={props.disabled ? '' : undefined}
data-invalid={invalid || undefined}
className={cn('w-full min-w-0', animated && 'pt-2', containerProps?.className)}
>
{label && !animated && (
<InputLabel
htmlFor={inputId}
className={cn(
'mb-2 block font-medium leading-5',
controlTextSizes[resolvedSize],
invalid && 'text-destructive',
props.disabled && 'opacity-50',
)}
>
{label}
</InputLabel>
)}
<InputControlShell
data-variant={variant}
data-size={resolvedSize}
data-invalid={invalid || undefined}
className={cn('group/input relative', animated && labelActive)}
>
<SDKInput
{...props}
id={id ?? (label ? inputId : undefined)}
type={type}
size={htmlSize}
placeholder={animated ? ' ' : placeholder}
aria-describedby={
[describedBy, hasDescription ? descriptionId : undefined].filter(Boolean).join(' ') ||
undefined
}
className={(state) =>
cn(
inputVariants({ variant, size: resolvedSize }),
paddingForIcon,
typeof className === 'function' ? className(state) : className,
)
}
/>
{animated && label && (
<InputLabel
htmlFor={inputId}
className={cn(
'pointer-events-none absolute top-1/2 -translate-y-1/2 leading-5 text-muted-foreground transition-[top] duration-200 ease-out group-has-[input:focus]/input:top-0 group-has-[input:not(:placeholder-shown)]/input:top-0 motion-reduce:transition-none',
'max-w-[calc(100%-1.5rem)]',
controlTextSizes[resolvedSize],
icon && iconPosition === 'start'
? underline
? textFieldLayout.floatingUnderlineIcon
: textFieldLayout.floatingWithIcon
: underline
? '-start-1'
: textFieldLayout.floatingStart,
icon && 'max-w-[calc(100%-3.25rem)]',
props.disabled && 'opacity-50',
)}
>
<span className="sr-only">{label}</span>
<span
aria-hidden="true"
className="-my-6 block overflow-hidden text-ellipsis whitespace-pre px-1 py-6"
>
{labelVariant === 'wave' ? (
graphemes.map(({ text, offset }, index) => (
<span
key={`${label}-${offset}`}
className={cn(labelMotion, labelPatch)}
style={{ transitionDelay: `${index * delay}ms` }}
>
{text}
</span>
))
) : (
<span className={cn(labelMotion, labelPatch)}>{label}</span>
)}
</span>
</InputLabel>
)}
{icon && (
<span
aria-hidden="true"
className={cn(
'pointer-events-none absolute top-1/2 inline-flex -translate-y-1/2 items-center justify-center text-muted-foreground transition-colors duration-200 group-has-[input:focus]/input:text-primary group-data-invalid/input:text-destructive motion-reduce:transition-none [&>svg]:size-full',
textFieldLayout.icon,
iconPosition === 'start'
? underline
? 'start-0'
: textFieldLayout.iconStart
: underline
? 'end-0'
: textFieldLayout.iconEnd,
props.disabled && 'opacity-50',
)}
>
{icon}
</span>
)}
</InputControlShell>
{hasDescription && (
<InputDescription
id={descriptionId}
className={cn(
'mt-1 text-xs leading-relaxed',
invalid ? 'text-destructive' : 'text-muted-foreground',
)}
>
{description}
</InputDescription>
)}
</div>
);
}
function InputGroup({ className, ...props }: ComponentProps<typeof SDKInputGroup>) {
return (
<SDKInputGroup
{...props}
data-slot="input-group"
className={(state) =>
cn(
'group/control relative flex min-w-0 items-center gap-2 [&>[data-slot=input]]:min-w-0 [&>[data-slot=input]]:flex-1',
typeof className === 'function' ? className(state) : className,
)
}
/>
);
}
type InputClearProps = ComponentProps<typeof SDKInputClear> & {
variant?: ButtonProps['variant'];
size?: ButtonProps['size'];
};
function InputClear({
children,
variant = 'ghost',
size = 'icon-sm',
className,
...props
}: InputClearProps) {
return (
<SDKInputClear
aria-label="Clear input"
{...props}
className={partClass(buttonVariants({ variant, size }), className)}
>
{children ?? <X aria-hidden="true" />}
</SDKInputClear>
);
}
export {
createInputController,
Input,
InputClear,
type InputController,
InputControlShell,
InputDescription,
InputGroup,
InputLabel,
type InputProps,
type InputSize,
type InputState,
type InputValueChangeReason,
inputVariants,
};
import type { ButtonOptions } from '@ui-sdk/core/button';
import { Button as ButtonPrimitive } from '@ui-sdk/react/button';
import { cva, type VariantProps } from 'class-variance-authority';
import { Loader2 } from 'lucide-react';
import type { ComponentProps, ReactNode } from 'react';
import { controlHeights, controlTextSizes, focusRing } from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
/*
* Clean tactile button surfaces with a subtle top highlight, contact shadow,
* and 2% press scale using pure Tailwind/theme tokens.
*/
const flatPress = 'motion-safe:not-data-disabled:not-data-pending:active:scale-[0.985]';
const activeInsetShadow =
'active:shadow-[inset_0_1px_3px_rgb(0_0_0/0.12),0_1px_2px_rgb(0_0_0/0.06)] dark:active:shadow-[inset_0_1px_3px_rgb(0_0_0/0.18),0_1px_2px_rgb(0_0_0/0.1)]';
const tactileFilled =
'bg-[linear-gradient(180deg,rgb(255_255_255/0.16),rgb(255_255_255/0)_75%)] shadow-[inset_0_1.5px_0_rgb(255_255_255/0.22),inset_0_-1px_0_rgb(0_0_0/0.12),0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)] active:shadow-[inset_0_1px_3px_rgb(0_0_0/0.18),0_1px_2px_rgb(0_0_0/0.1)]';
const tactileNeutral = `bg-[linear-gradient(180deg,rgb(255_255_255/0.35),transparent_48%,rgb(0_0_0/0.025)_100%)] shadow-[inset_0_1px_0_rgb(255_255_255/0.65),inset_0_-1px_0_rgb(0_0_0/0.06),0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)] dark:bg-[linear-gradient(180deg,rgb(255_255_255/0.06),transparent_48%,rgb(0_0_0/0.12)_100%)] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.1),inset_0_-1px_0_rgb(0_0_0/0.12),0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)] ${activeInsetShadow}`;
/** Surface map for button variants, shared with Toggle, Tabs, Radio, Checkbox, and Switch. */
const buttonSurfaces = {
primary: `border-[color-mix(in_oklch,var(--primary),black_8%)] bg-primary text-primary-foreground ${tactileFilled} ${flatPress}`,
secondary: ` bg-popover text-popover-foreground border-[color-mix(in_oklch,var(--muted),black_5%)] ${tactileNeutral} ${flatPress}`,
outline: `border-input bg-accent/10 text-foreground shadow-sm hover:text-accent-foreground ${activeInsetShadow} ${flatPress}`,
ghost: `border-transparent text-foreground hover:bg-muted ${activeInsetShadow} ${flatPress}`,
destructive: `border-[color-mix(in_oklch,var(--destructive),black_8%)] bg-destructive text-[color:var(--destructive-foreground,white)] ${tactileFilled} ${flatPress}`,
tertiary: `border-transparent bg-accent text-accent-foreground ${activeInsetShadow} ${flatPress}`,
'destructive-soft': `border-transparent bg-destructive/10 text-destructive dark:bg-destructive/20 ${activeInsetShadow} ${flatPress}`,
link: 'border-transparent text-primary underline-offset-4 hover:underline',
} as const;
type ButtonVariant = keyof typeof buttonSurfaces;
const buttonBase = cva(
[
// layout
'group/button relative isolate inline-flex shrink-0 items-center justify-center whitespace-nowrap rounded-lg border text-sm font-medium',
// interaction
'cursor-pointer select-none touch-manipulation',
'transition-[background-color,border-color,box-shadow,translate,scale,filter] duration-150 ease-out motion-reduce:transition-none',
focusRing,
// 44px touch target on coarse pointers without changing the visual size
'[@media(pointer:coarse)]:after:absolute [@media(pointer:coarse)]:after:inset-1/2 [@media(pointer:coarse)]:after:min-h-11 [@media(pointer:coarse)]:after:min-w-11 [@media(pointer:coarse)]:after:-translate-1/2',
// states
'disabled:cursor-not-allowed aria-disabled:opacity-50 data-disabled:cursor-not-allowed data-disabled:opacity-50 data-pending:cursor-wait',
// icons
"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-(--icon-size,1rem) [&>span:has(>svg):not([class*='size-'])]:size-(--icon-size,1rem)",
],
{
variants: {
size: {
md: `${controlHeights.md} ${controlTextSizes.md} gap-2 px-4 [--icon-size:1.2rem]`,
xs: `${controlHeights.xs} ${controlTextSizes.xs} gap-1 px-2.5 [--icon-size:0.875rem]`,
sm: `${controlHeights.sm} ${controlTextSizes.sm} gap-1.5 px-3 [--icon-size:1rem]`,
lg: `${controlHeights.lg} ${controlTextSizes.lg} gap-2 px-6 [--icon-size:1.25rem]`,
icon: `${controlHeights.md} aspect-square [--icon-size:1.2rem]`,
'icon-xs': `${controlHeights.xs} aspect-square [--icon-size:0.875rem]`,
'icon-sm': `${controlHeights.sm} aspect-square [--icon-size:1rem]`,
'icon-lg': `${controlHeights.lg} aspect-square [--icon-size:1.25rem]`,
},
},
defaultVariants: { size: 'md' },
},
);
type ButtonVariantProps = VariantProps<typeof buttonBase> & {
variant?: ButtonVariant;
};
function buttonVariants({
variant = 'primary',
size,
className,
}: ButtonVariantProps & { className?: string } = {}) {
return cn(buttonBase({ size }), buttonSurfaces[variant], className);
}
type ButtonProps = Omit<
ComponentProps<typeof ButtonPrimitive>,
keyof ButtonOptions | 'className' | 'children'
> &
ButtonOptions &
ButtonVariantProps & {
children?: ReactNode;
className?: string;
/** Prevent repeated activation and display an inline spinner without replacing the label. */
loading?: boolean;
};
const spinner = (
<Loader2
aria-hidden="true"
data-slot="spinner"
className="hidden size-(--icon-size,1rem) animate-spin in-data-pending:inline-block in-data-loading:inline-block motion-reduce:animate-none"
/>
);
function Button({
className,
variant = 'primary',
size = 'md',
loading = false,
disabled,
children,
'aria-busy': ariaBusy,
...props
}: ButtonProps) {
return (
<ButtonPrimitive
{...props}
className={buttonVariants({ variant, size, className })}
data-size={size}
data-variant={variant}
data-loading={loading || undefined}
disabled={disabled || loading}
aria-busy={loading || ariaBusy}
>
{spinner}
{children}
</ButtonPrimitive>
);
}
export { Button, type ButtonProps, type ButtonVariant, buttonSurfaces, buttonVariants };
import { cn } from '@/lib/utils';
type ClassValue = string | false | null | undefined;
type PartClassValue<State> = ClassValue | ((state: State) => ClassValue);
/** Composes static class names and UI-SDK state class functions into a single `className` prop. */
export function partClass<State>(...parts: PartClassValue<State>[]) {
if (parts.some((part) => typeof part === 'function')) {
return (state: State) =>
cn(...parts.map((part) => (typeof part === 'function' ? part(state) : part)));
}
return cn(...(parts as ClassValue[]));
}
export const surfacePadding = 'p-1 [--surface-padding:1.5rem] [--concentric-inset:0.25rem]';
export const surfaceRegionInset = 'p-[calc(var(--surface-padding,1rem)-0.5rem)]';
export const surfaceHeaderRadius = 'rounded-t-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
export const surfaceFooterRadius = 'rounded-b-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
/** Concentric inner radius (`outer - inset`); set `[--concentric-inset:0.125rem]` on `p-0.5` rails (defaults to `0.25rem` for `p-1`). */
export const concentricRadius =
'rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))]';
export const surfaceBodyPadding =
'py-[max(0px,calc(var(--surface-padding,1rem)-1rem))] has-[>[data-slot=list]:not([data-variant=plain])]:p-0 has-[>[data-slot=list-items-container]]:p-0';
export type StandardControlSize = 'xs' | 'sm' | 'md' | 'lg';
/** Standard control heights (`28px / 32px / 40px / 48px`) for buttons, inputs, selects, tabs, and sliders. */
export const controlHeights = {
xs: 'h-7',
sm: 'h-8',
md: 'h-10',
lg: 'h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard minimum control heights (`28px / 32px / 40px / 48px`) for expandable controls and menu items. */
export const controlMinHeights = {
xs: 'min-h-7',
sm: 'min-h-8',
md: 'min-h-10',
lg: 'min-h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard control text sizes (`xs / xs / sm / base`) paired with `StandardControlSize`. */
export const controlTextSizes = {
xs: 'text-xs',
sm: 'text-xs',
md: 'text-sm',
lg: 'text-base',
} as const satisfies Record<StandardControlSize, string>;
/** Compact control heights (`1.25rem / 1.3rem / 1.625rem / 1.75rem`), one step smaller than standard, for switches and compact controls. */
export const compactControlHeights = {
xs: 'h-[1.3rem]',
sm: 'h-[1.4rem]',
md: 'h-[1.5rem]',
lg: 'h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Compact minimum control heights (`1rem / 1.25rem / 1.5rem / 1.75rem`) for badges and tooltips. */
export const compactControlMinHeights = {
xs: 'min-h-[1.3rem]',
sm: 'min-h-[1.4rem]',
md: 'min-h-[1.5rem]',
lg: 'min-h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Universal keyboard focus + invalid ring/border styles shared across controls. */
export const focusRing =
'touch-manipulation outline-none focus-visible:border-ring/30 transition-ring focus-visible:ring-3 focus-visible:ring-ring/15 focus-visible:brightness-[0.97] dark:focus-visible:brightness-[1.15] has-[:focus-visible]:border-ring/30 has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/15 has-[:focus-visible]:brightness-[0.97] dark:has-[:focus-visible]:brightness-[1.15] data-active:border-ring/30 data-active:ring-3 data-active:ring-ring/15 data-active:brightness-[0.97] dark:data-active:brightness-[1.15] data-open:border-ring/30 data-open:ring-3 data-open:ring-ring/15 data-open:brightness-[0.97] dark:data-open:brightness-[1.15] data-disabled:cursor-not-allowed data-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/25 data-invalid:border-destructive data-invalid:ring-3 data-invalid:ring-destructive/25 has-[[data-invalid]]:border-destructive has-[[data-invalid]]:ring-3 has-[[data-invalid]]:ring-destructive/25 group-aria-invalid/control:border-destructive group-aria-invalid/control:ring-3 group-aria-invalid/control:ring-destructive/25 group-data-invalid/control:border-destructive group-data-invalid/control:ring-3 group-data-invalid/control:ring-destructive/25 group-has-[input[aria-invalid=true]]/control:border-destructive group-has-[input[aria-invalid=true]]/control:ring-3 group-has-[input[aria-invalid=true]]/control:ring-destructive/25 hover:brightness-[0.97] dark:hover:brightness-[1.15]';
/** Shared sliding highlight indicator base (pointer-safe, concentric inner radius inside rounded-lg containers, 200ms transition). */
export const slidingHighlight =
'pointer-events-none -z-10 rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))] bg-primary/10 [clip-path:inset(0px_round_max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem))))] transition-[transform,width,height,opacity] duration-200 ease-out motion-reduce:transition-none';
export const textFieldSurfaces = {
filled: 'border-input bg-card text-card-foreground',
outline: 'border-input bg-transparent text-foreground dark:bg-transparent',
ghost: 'border-transparent bg-muted text-foreground shadow-none',
underline:
'rounded-none border-0 border-b-2 border-input bg-transparent px-0 text-foreground shadow-none focus-visible:border-ring focus-visible:ring-0 aria-invalid:ring-0 data-invalid:ring-0 dark:bg-transparent',
} as const;
export const textFieldUnderlineMotion =
'border-transparent! bg-origin-border bg-bottom bg-no-repeat [--underline-color:var(--primary)] [background-image:linear-gradient(var(--underline-color),var(--underline-color)),linear-gradient(var(--input),var(--input))] [background-size:0%_2px,100%_2px] focus:[background-size:100%_2px,100%_2px] aria-invalid:[--underline-color:var(--destructive)] data-invalid:[--underline-color:var(--destructive)] transition-[border-color,background-color,box-shadow,filter,background-size] duration-200 motion-reduce:transition-none';
/** Generic balanced icon & floating-label layout tokens shared across all text-field sizes. */
export const textFieldLayout = {
icon: 'size-4',
iconStart: 'start-3',
iconEnd: 'end-3',
padStart: 'ps-9',
padEnd: 'pe-9',
underlinePadStart: 'ps-7',
underlinePadEnd: 'pe-7',
floatingStart: 'start-2.5',
floatingWithIcon: 'start-8',
floatingUnderlineIcon: 'start-6',
} as const;
export const textFieldLabelSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
/** Clamps per-grapheme wave delay (ms) so total staggering stays within 300ms. */
export function clampWaveDelay(waveDelay: number, count: number): number {
return Math.max(
0,
Math.min(Number.isFinite(waveDelay) ? waveDelay : 24, 80, 300 / Math.max(1, count - 1)),
);
}
/** Shared scale/color transition for floating labels inside a `group/field` wrapper. */
export const textFieldLabelMotion =
'inline-block origin-left backdrop-blur-xs transition-[scale,color] duration-200 ease-out group-has-[input:focus]/field:scale-85 group-has-[input:not(:placeholder-shown)]/field:scale-85 rtl:origin-right motion-reduce:transition-none';
/** Resolves start/end padding for a text field when a leading or trailing icon is present. */
export function getTextFieldIconPadding(iconPosition: 'start' | 'end', underline: boolean): string {
if (iconPosition === 'start') {
return underline ? textFieldLayout.underlinePadStart : textFieldLayout.padStart;
}
return underline ? textFieldLayout.underlinePadEnd : textFieldLayout.padEnd;
}
/** Shared per-grapheme ripple transition for wave labels inside a `group/field` wrapper. */
export const textFieldWaveMotion =
'inline-block origin-left backdrop-blur-xs transition-[translate,scale,color] duration-200 ease-out group-has-[input:focus]/field:-translate-y-5 group-has-[input:focus]/field:scale-85 group-has-[input:focus]/field:text-primary group-has-[input:not(:placeholder-shown)]/field:-translate-y-5 group-has-[input:not(:placeholder-shown)]/field:scale-85 group-has-[input[aria-invalid=true]]/field:text-destructive rtl:origin-right motion-reduce:transition-none';