Open a panel from a screen edge for filters, settings, or details.
Default
Snap Points
Sides & Nested Stack
Open Account, then open Change password to see stacking.
Outlet & Draft Guard
Inès Moreau
The proofs are back from the printer.
Kofi Mensah
Pushed the fix for the release build.
Wren Takahashi
Can you review the launch checklist?
Drag the sheet or type a draft and press Escape.
Shared Controller
Q4-Roadmap.pdf
2.4 MB
Tokens-v3.json
180 KB
Launch-Reel.mp4
Uploading…
Share any file or open Q4-Roadmap.pdf programmatically.
Purpose
Open a panel from a screen edge for filters, settings, or details.
Parts & Composition
Place the trigger, optional backdrop, and content under the root. Use DrawerHeader for title and description, DrawerBody for scrollable content, and DrawerFooter for actions. Add DrawerHandle when the panel uses snap points.
API & Props
| Prop or part | Purpose |
|---|---|
side | Choose a physical edge or logical start and end. |
open, defaultOpen, onOpenChange | Control or initialize visibility. |
snapPoints, defaultSnapPoint, expandOnScroll | Configure resting heights and how scrolling expands a sheet. |
modal, dismissible | Control outside interaction and dismissal through SDK options. |
Drawer.size / DrawerContent.size | xs, sm, md (default), or lg. Scales trigger size, panel width limit, and region insets together. |
DrawerHeader, DrawerBody, DrawerFooter | Structured regions (separator defaults to false on header, true on footer) with thin-scrollbar body. |
DrawerTrigger, DrawerClose, DrawerShortcut | SDK buttons with size and variant props (empty DrawerClose renders a corner close icon) and keycap shortcut hints. |
Theming, Layout & Responsiveness
Drawer uses shared surface insets. The body scrolls independently from the heading and actions. Size the content to accommodate the largest snap point.
Motion & Accessibility
UI SDK owns the drag, snap, focus, dismissal, and reduced-motion behavior. Use a title to name the drawer and an accessible label on the handle.
Guidance for Coding Agents
Install Drawer using the command in the Install tab and read this Info page. Begin with the closest Preview example, then consult the UI SDK Drawer reference for inherited props, state callbacks, and custom rendering.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/drawer'use client';
import {
Drawer as SDKDrawer,
DrawerBackdrop as SDKDrawerBackdrop,
DrawerClose as SDKDrawerClose,
DrawerContent as SDKDrawerContent,
DrawerDescription as SDKDrawerDescription,
DrawerHandle as SDKDrawerHandle,
type DrawerProps as SDKDrawerProps,
DrawerShortcut as SDKDrawerShortcut,
DrawerTitle as SDKDrawerTitle,
DrawerTrigger as SDKDrawerTrigger,
} from '@ui-sdk/react/drawer';
import { cva } from 'class-variance-authority';
import { X } from 'lucide-react';
import { type ComponentProps, createContext, useContext } from 'react';
import { type ButtonProps, buttonVariants } from '@/components/devvarena-ui/button';
import { Separator } from '@/components/devvarena-ui/separator';
import {
compactControlMinHeights,
focusRing,
partClass,
type StandardControlSize,
surfaceBodyPadding,
surfaceFooterRadius,
surfaceHeaderRadius,
surfacePadding,
surfaceRegionInset,
} from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const DrawerSizeContext = createContext<StandardControlSize>('md');
const drawerSurface = cva(
cn(
'group/drawer-content relative flex w-full min-h-0 max-h-[100dvh] flex-col overflow-visible border border-border bg-popover text-popover-foreground shadow-sm',
surfacePadding,
'after:pointer-events-none after:absolute after:bg-popover after:content-[""]',
'data-[side=bottom]:mx-auto data-[side=bottom]:rounded-t-lg data-[side=bottom]:border-b-0 data-[side=bottom]:pb-[max(0.5rem,env(safe-area-inset-bottom))] data-[side=bottom]:after:-inset-x-px data-[side=bottom]:after:top-full data-[side=bottom]:after:h-[50dvh] data-[side=bottom]:after:border-x data-[side=bottom]:after:border-border',
'data-[side=top]:mx-auto data-[side=top]:rounded-b-lg data-[side=top]:border-t-0 data-[side=top]:after:-inset-x-px data-[side=top]:after:bottom-full data-[side=top]:after:h-[50dvh] data-[side=top]:after:border-x data-[side=top]:after:border-border',
'data-[side=left]:h-full data-[side=left]:rounded-r-lg data-[side=left]:border-l-0 data-[side=left]:has-[[data-slot=drawer-handle]]:pe-6 data-[side=left]:after:-inset-y-px data-[side=left]:after:right-full data-[side=left]:after:w-[50vw] data-[side=left]:after:border-y data-[side=left]:after:border-border',
'data-[side=right]:h-full data-[side=right]:rounded-l-lg data-[side=right]:border-r-0 data-[side=right]:has-[[data-slot=drawer-handle]]:ps-6 data-[side=right]:after:-inset-y-px data-[side=right]:after:left-full data-[side=right]:after:w-[50vw] data-[side=right]:after:border-y data-[side=right]:after:border-border',
'motion-safe:[scale:calc(1-var(--drawer-stack,0)*0.04)] transition-[scale] duration-200 ease-out motion-reduce:transition-none',
),
{
variants: {
size: {
xs: 'max-w-xs [--surface-padding:1.3rem]',
sm: 'max-w-sm [--surface-padding:1.35rem]',
md: 'max-w-lg',
lg: 'max-w-2xl [--surface-padding:1.75rem]',
} satisfies Record<StandardControlSize, string>,
},
defaultVariants: { size: 'md' },
},
);
const closeIcon = <X aria-hidden="true" />;
type DrawerProps = SDKDrawerProps & { size?: StandardControlSize };
function Drawer({ size = 'md', ...props }: DrawerProps) {
return (
<DrawerSizeContext value={size}>
<SDKDrawer {...props} />
</DrawerSizeContext>
);
}
type DrawerContentProps<Payload = unknown> = ComponentProps<typeof SDKDrawerContent<Payload>> & {
size?: StandardControlSize;
};
function DrawerContent<Payload = unknown>({
size,
className,
...props
}: DrawerContentProps<Payload>) {
const contextSize = useContext(DrawerSizeContext);
const contentSize = size ?? contextSize;
return (
<SDKDrawerContent<Payload>
{...props}
data-size={contentSize}
className={partClass(drawerSurface({ size: contentSize }), className)}
/>
);
}
function DrawerHeader({
separator = false,
className,
children,
...props
}: ComponentProps<'header'> & { separator?: boolean }) {
return (
<header
{...props}
data-slot="drawer-header"
className={cn(
surfaceRegionInset,
surfaceHeaderRadius,
'relative grid shrink-0 gap-1 has-[>[data-slot=drawer-close]]:pe-10',
className,
)}
>
{children}
{separator ? <Separator className="absolute inset-x-0 bottom-0 w-auto" /> : null}
</header>
);
}
function DrawerBody({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="drawer-body"
className={cn(
surfaceRegionInset,
surfaceBodyPadding,
'scroll-fade min-h-0 flex-1 overflow-y-auto overscroll-contain [scrollbar-width:thin] [scrollbar-color:var(--border)_transparent]',
className,
)}
/>
);
}
function DrawerFooter({
separator = true,
className,
children,
...props
}: ComponentProps<'footer'> & { separator?: boolean }) {
return (
<footer
{...props}
data-slot="drawer-footer"
className={cn(
'relative',
surfaceRegionInset,
surfaceFooterRadius,
'flex shrink-0 flex-wrap items-center justify-end gap-2',
className,
)}
>
{separator ? <Separator className="absolute inset-x-0 top-0 w-auto" /> : null}
{children}
</footer>
);
}
type DrawerTriggerProps = ComponentProps<typeof SDKDrawerTrigger> &
Pick<ButtonProps, 'size' | 'variant'>;
function DrawerTrigger({
size,
variant = 'secondary',
className,
children,
...props
}: DrawerTriggerProps) {
const contextSize = useContext(DrawerSizeContext);
const triggerSize = size ?? contextSize;
return (
<SDKDrawerTrigger
{...props}
data-size={triggerSize}
data-variant={variant}
className={partClass(buttonVariants({ size: triggerSize, variant }), className)}
>
{children}
</SDKDrawerTrigger>
);
}
type DrawerCloseProps = ComponentProps<typeof SDKDrawerClose> &
Pick<ButtonProps, 'size' | 'variant'>;
function DrawerClose({
size,
variant,
className,
children,
'aria-label': label,
...props
}: DrawerCloseProps) {
const contextSize = useContext(DrawerSizeContext);
const isCornerClose = children == null && props.render === undefined;
const resolvedVariant = variant ?? (isCornerClose ? 'ghost' : 'secondary');
const resolvedSize = size ?? (isCornerClose ? 'icon-xs' : contextSize);
return (
<SDKDrawerClose
{...props}
aria-label={label ?? (isCornerClose ? 'Close drawer' : undefined)}
data-size={resolvedSize}
data-variant={resolvedVariant}
className={partClass(
cn(
buttonVariants({ size: resolvedSize, variant: resolvedVariant }),
isCornerClose &&
'absolute end-2.5 top-2.5 z-10 text-muted-foreground hover:text-foreground',
),
className,
)}
>
{children ?? (props.render ? undefined : closeIcon)}
</SDKDrawerClose>
);
}
function DrawerBackdrop({ className, ...props }: ComponentProps<typeof SDKDrawerBackdrop>) {
return (
<SDKDrawerBackdrop
{...props}
className={partClass('bg-foreground/30 dark:bg-background/60', className)}
/>
);
}
function DrawerTitle({ className, ...props }: ComponentProps<typeof SDKDrawerTitle>) {
return (
<SDKDrawerTitle
{...props}
className={partClass(
'm-0 text-base font-semibold leading-tight tracking-tight text-popover-foreground',
className,
)}
/>
);
}
function DrawerDescription({ className, ...props }: ComponentProps<typeof SDKDrawerDescription>) {
return (
<SDKDrawerDescription
{...props}
className={partClass('m-0 text-sm leading-relaxed text-muted-foreground', className)}
/>
);
}
function DrawerHandle({ className, ...props }: ComponentProps<typeof SDKDrawerHandle>) {
return (
<SDKDrawerHandle
{...props}
className={partClass(
`mx-auto my-1.5 grid h-7 w-12 shrink-0 cursor-grab touch-manipulation place-items-center rounded-md before:h-1 before:w-8 before:rounded-full before:bg-muted-foreground/40 before:content-[""] active:cursor-grabbing ${focusRing}`,
'group-data-[side=left]/drawer-content:absolute group-data-[side=left]/drawer-content:end-1 group-data-[side=left]/drawer-content:top-1/2 group-data-[side=left]/drawer-content:my-0 group-data-[side=left]/drawer-content:h-12 group-data-[side=left]/drawer-content:w-5 group-data-[side=left]/drawer-content:-translate-y-1/2 group-data-[side=left]/drawer-content:before:h-8 group-data-[side=left]/drawer-content:before:w-1',
'group-data-[side=right]/drawer-content:absolute group-data-[side=right]/drawer-content:start-1 group-data-[side=right]/drawer-content:top-1/2 group-data-[side=right]/drawer-content:my-0 group-data-[side=right]/drawer-content:h-12 group-data-[side=right]/drawer-content:w-5 group-data-[side=right]/drawer-content:-translate-y-1/2 group-data-[side=right]/drawer-content:before:h-8 group-data-[side=right]/drawer-content:before:w-1',
className,
)}
/>
);
}
function DrawerShortcut({ className, ...props }: ComponentProps<typeof SDKDrawerShortcut>) {
return (
<SDKDrawerShortcut
{...props}
data-slot="drawer-shortcut"
className={partClass(
compactControlMinHeights.sm,
'ms-auto inline-flex min-w-6 items-center justify-center rounded-lg border border-border/60 bg-muted/60 px-1.5 font-sans text-xs text-muted-foreground',
className,
)}
/>
);
}
export { createDrawerController, DrawerOutlet, sheetPhysics } from '@ui-sdk/react/drawer';
export {
Drawer,
DrawerBackdrop,
DrawerBody,
DrawerClose,
type DrawerCloseProps,
DrawerContent,
type DrawerContentProps,
DrawerDescription,
DrawerFooter,
DrawerHandle,
DrawerHeader,
type DrawerProps,
DrawerShortcut,
DrawerTitle,
DrawerTrigger,
type DrawerTriggerProps,
};
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 { Separator as SDKSeparator } from '@ui-sdk/react/separator';
import type { ComponentProps } from 'react';
import { partClass } from '@/lib/devvarena-ui';
type SeparatorProps = ComponentProps<typeof SDKSeparator> & { variant?: 'fade' | 'solid' };
/** Theme-derived fading rule built on `@ui-sdk/react/separator`. */
function Separator({
orientation = 'horizontal',
decorative = true,
variant = 'fade',
className,
...props
}: SeparatorProps) {
return (
<SDKSeparator
{...props}
orientation={orientation}
decorative={decorative}
data-variant={variant}
className={partClass(
'pointer-events-none shrink-0',
orientation === 'horizontal' ? 'h-px w-full' : 'w-px self-stretch',
variant === 'solid'
? 'bg-[var(--separator-color,var(--border))]'
: orientation === 'horizontal'
? 'bg-[linear-gradient(to_right,transparent,var(--separator-color,var(--border))_18%,var(--separator-color,var(--border))_82%,transparent)]'
: 'bg-[linear-gradient(to_bottom,transparent,var(--separator-color,var(--border))_18%,var(--separator-color,var(--border))_82%,transparent)]',
className,
)}
/>
);
}
export type { SeparatorProps };
export { Separator };
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';