A themed slider for adjusting a value or range with pointer, touch, and keyboard input.
Default
Sizes
Variants
Ranges and Multiple Thumbs
Forms and Commit
Last committed range: $250 – $750 $250 – $750
Submitted range: Not submitted
Custom Thumb Output
Vertical Orientation
States
Purpose
Slider lets people adjust a numeric value or range by moving one or more thumbs along a track.
Parts & Composition
Slider uses UI SDK’s Slider primitive and composes this default tree when children are omitted:
Slider → optional label and SliderValue; SliderControl → SliderTrack → SliderIndicator and one SliderThumb per value.
The the library wrapper exports the root, each part, SliderOptions, and createSliderController. Use children to compose the parts yourself when the default label/value layout does not fit. The wrapper retains the SDK’s own parts, render props, state callbacks, value handling, and accessibility behavior.
API & Props
Slider forwards the UI SDK Slider options and root element props. value and defaultValue accept a number for one thumb or a number array for multiple thumbs.
| Prop / slot | Purpose |
|---|---|
value, defaultValue | Controlled value or initial uncontrolled value. The default is min. |
onValueChange | Called for each value change. Its details include the interaction reason and changed thumb; details.cancel() can reject a change. |
onValueCommit | Called once when a changed drag, key interaction, or assistive-technology adjustment ends. |
min, max, step, largeStep | Numeric bounds and key increments; defaults are 0, 100, 1, and 10 steps. |
minStepsBetweenThumbs | Minimum step distance between adjacent thumbs. |
format, locale | Format the visible value and each thumb’s spoken value with Intl.NumberFormat options or a formatter function. |
orientation | horizontal (default) or vertical. Vertical sliders grow upward. |
disabled, readOnly, required | Disable interaction, allow focus/submission without edits, or expose the required state. |
name, form | Associate the slider with a form. A range submits as start/end. |
controller | Imperatively read, set, or focus the slider using createSliderController. |
label | the library shorthand for a visible label that names the default thumb composition. |
marks | Optional decorative track marks; finite values inside min and max are shown. |
thumbLabels | Accessible names for thumbs in the default composition; otherwise names them “Thumb 1”, etc. |
size | xs, sm, md, or lg; defaults to md. |
variant | pill (default) or cell. |
children | Replaces the default composition with UI SDK Slider parts. |
SliderControl, SliderTrack, SliderIndicator, SliderThumb, and SliderValue accept the corresponding UI SDK part props, including render, className, and state-based children. SliderThumb accepts index to identify its value in a multi-thumb slider. SliderValue displays UI SDK’s formatted text by default; custom children can use its state. SliderOptions is the upstream option type.
Use thumbLabels for accessible names and minStepsBetweenThumbs for minimum spacing. UI SDK keeps thumbs in order and fills between the first and last values.
| Attribute | Meaning |
|---|---|
data-slot="slider" and part slots | Stable identifiers for the root and each composed part. |
data-size, data-variant | the library size and presentation on the root. |
data-orientation, data-disabled, data-dragging, data-required | UI SDK state on the root and corresponding parts. |
aria-invalid="true" | The shared focus styling applies destructive feedback to the control. |
Theming, Layout & Responsiveness
The pill presentation uses a compact track and a primary-colored fill with a bordered thumb. cell uses the muted track and a foreground-tinted fill with a narrow handle. Both use semantic theme tokens and the shared rounded container treatment.
The component fills its parent width horizontally. cell uses the standard control height scale (xs 28px, sm 32px, md 40px, lg 48px). pill derives its track height from the compact size scale (12px, 16px, 20px, 24px). Vertical orientation fills the available height and has a minimum track length.
Motion & Accessibility
UI SDK owns pointer and touch dragging, keyboard interaction, value snapping, thumb ordering, and change/commit callbacks. Arrow keys adjust by step; Home and End move to the bounds; Page Up/Down and Shift+Arrow use largeStep. The thumb contains the focusable range input, and the shared focus styling is applied to its control. The cell handle subtly responds to hover and drag; displayed values transition without delaying thumb movement and respect reduced motion.
Give each thumb an accessible name. Use label when using the default composition, or name thumbs directly when composing parts. The visible SliderValue is not a live region; the thumb’s range input announces its own formatted value. disabled removes the control from interaction, while readOnly keeps it focusable and submitted. Set dir="rtl" on the slider or an ancestor for right-to-left layouts.
Guidance for Coding Agents
Before implementing a slider, read this Info reference and the upstream UI SDK Slider documentation. If UI SDK is missing from the project, install @ui-sdk/react and @ui-sdk/core with the project package manager. Import the the library wrapper and parts from @/components/library/slider; use its pill or cell variant and xs, sm, md, or lg size rather than recreating the track or thumb. Keep values numeric, use format for display and spoken values, and pass an array for multiple thumbs with an accessible name for each. Use onValueChange for immediate UI updates and onValueCommit for work that should happen after interaction settles. Prefer the default composition unless the layout needs the exported parts; when composing parts, preserve UI SDK’s Slider → SliderControl → SliderTrack hierarchy, render an indicator and a thumb for every value, and use the thumb’s index for ranges. Use marks for decorative steps and the SDK controller only when an external control needs to inspect or change the slider. Keep additional behavior and styling in the the library wrapper or an example instead of spreading low-level setup through consuming screens. Read the upstream Slider docs for inherited options, callbacks, keyboard behavior, form behavior, and part render state before adding wrapper props.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/slider'use client';
import type { SliderOptions } from '@ui-sdk/core/slider';
import {
createSliderController,
Slider as SDKSlider,
SliderControl as SDKSliderControl,
SliderIndicator as SDKSliderIndicator,
SliderThumb as SDKSliderThumb,
SliderTrack as SDKSliderTrack,
SliderValue as SDKSliderValue,
} from '@ui-sdk/react/slider';
import { cva, type VariantProps } from 'class-variance-authority';
import {
type ComponentProps,
createContext,
Fragment,
type ReactNode,
useContext,
useId,
useMemo,
} from 'react';
import { ValueTransition } from '@/hooks/use-value-transition';
import {
compactControlHeights,
controlHeights,
controlTextSizes,
focusRing,
partClass,
type StandardControlSize,
} from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const SliderContext = createContext<{ pill: boolean; size: StandardControlSize }>({
pill: true,
size: 'md',
});
/** Unique, finite marks strictly inside (min, max). */
function resolveMarks(marks: readonly number[] | undefined, min: number, max: number) {
if (!marks?.length || !Number.isFinite(min) || !Number.isFinite(max) || max <= min) return [];
return [...new Set(marks)].filter((mark) => Number.isFinite(mark) && mark > min && mark < max);
}
// `variant` is declared after `size` so its overlay padding wins on conflicts.
const sliderVariants = cva(
'group/control relative grid min-w-0 rounded-lg text-foreground not-data-[orientation=vertical]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-fit data-[orientation=vertical]:grid-rows-[minmax(0,1fr)_auto] data-[orientation=vertical]:justify-items-center',
{
variants: {
size: {
xs: `${controlTextSizes.xs} [&_[data-slot=slider-overlay]]:gap-1 [&_[data-slot=slider-overlay]]:px-2.5 [&_[data-slot=slider-thumb]:not([data-orientation=vertical])]:after:h-3 [&_[data-slot=slider-mark]]:size-0.5`,
sm: `${controlTextSizes.sm} [&_[data-slot=slider-overlay]]:gap-1.5 [&_[data-slot=slider-overlay]]:px-3 [&_[data-slot=slider-thumb]:not([data-orientation=vertical])]:after:h-4 [&_[data-slot=slider-mark]]:size-0.5`,
md: `${controlTextSizes.md} leading-5 [&_[data-slot=slider-overlay]]:gap-3 [&_[data-slot=slider-overlay]]:px-3.5 [&_[data-slot=slider-thumb]:not([data-orientation=vertical])]:after:h-5 [&_[data-slot=slider-mark]]:size-1`,
lg: `${controlTextSizes.lg} leading-6 [&_[data-slot=slider-overlay]]:gap-3 [&_[data-slot=slider-overlay]]:px-4 [&_[data-slot=slider-thumb]:not([data-orientation=vertical])]:after:h-6 [&_[data-slot=slider-mark]]:size-1.5`,
},
variant: {
cell: 'bg-muted',
pill: 'gap-2 bg-transparent data-dragging:shadow-none [&_[data-slot=slider-overlay]]:px-0',
},
},
defaultVariants: { size: 'md', variant: 'pill' },
},
);
const controlBase =
'relative flex w-full cursor-ew-resize touch-pan-y border border-border/50 transition-[box-shadow,border-color] duration-150 ease-out data-[orientation=vertical]:h-full data-[orientation=vertical]:cursor-ns-resize data-[orientation=vertical]:touch-pan-x data-disabled:cursor-not-allowed has-[[aria-readonly=true]]:cursor-default motion-reduce:transition-none';
const pillControl =
'not-data-[orientation=vertical]:h-[calc(100%-0.5rem)] rounded-lg bg-muted data-[orientation=vertical]:w-4 [@media(pointer:coarse)]:before:absolute [@media(pointer:coarse)]:before:inset-x-0 [@media(pointer:coarse)]:before:top-1/2 [@media(pointer:coarse)]:before:min-h-11 [@media(pointer:coarse)]:before:-translate-y-1/2';
const cellControl = 'rounded-[inherit] data-[orientation=vertical]:w-10';
const indicatorBase = 'not-data-[orientation=vertical]:h-full data-[orientation=vertical]:w-full';
const pillIndicator =
'rounded-s-[inherit] rounded-e-none bg-primary data-[orientation=vertical]:rounded-b-[inherit] data-[orientation=vertical]:rounded-t-none';
const cellIndicator =
'rounded-[inherit] bg-foreground/10 transition-colors duration-150 ease-out group-hover/control:bg-foreground/15 data-dragging:bg-foreground/20 group-data-disabled/control:bg-foreground/10 motion-reduce:transition-none';
const pillThumb =
'not-data-[orientation=vertical]:h-[calc(100%+0.25rem)] data-[orientation=vertical]:w-[calc(100%+0.25rem)] aspect-square rounded-lg border-2 border-primary bg-background shadow-sm transition-shadow duration-150 has-focus:ring-5 has-focus:ring-primary/30 outline-none motion-reduce:transition-none';
const cellThumb =
'flex h-full w-1 items-center justify-center outline-none before:absolute before:inset-y-0 before:-inset-x-3 data-[orientation=vertical]:before:inset-x-0 data-[orientation=vertical]:before:-inset-y-3 after:w-0.5 after:origin-center after:rounded-full after:bg-foreground/35 after:transition-[background-color,scale] after:duration-150 after:ease-[cubic-bezier(0.22,1,0.36,1)] data-[orientation=vertical]:h-1 data-[orientation=vertical]:w-full data-[orientation=vertical]:after:h-0.5 data-[orientation=vertical]:after:w-5 motion-safe:hover:not-data-disabled:not-data-readonly:not-data-dragging:after:scale-x-125 group-hover/control:after:bg-foreground/75 group-focus-within/control:after:bg-foreground motion-safe:data-dragging:after:scale-x-150 motion-safe:data-dragging:after:scale-y-110 data-dragging:after:bg-foreground group-data-disabled/control:after:bg-foreground/35 motion-reduce:after:transition-none';
function SliderControl({ className, ...props }: ComponentProps<typeof SDKSliderControl>) {
const { pill, size } = useContext(SliderContext);
return (
<div
className={cn(
'col-start-1 flex w-full items-center justify-center rounded-[inherit] group-data-[orientation=vertical]/control:h-full',
pill
? [
'row-start-2 group-data-[orientation=vertical]/control:row-start-1 group-data-[orientation=vertical]/control:w-7',
compactControlHeights[size],
]
: 'row-start-1 group-data-[orientation=vertical]/control:w-auto',
)}
>
<SDKSliderControl
{...props}
className={partClass(
cn(controlBase, focusRing, pill ? pillControl : [cellControl, controlHeights[size]]),
className,
)}
/>
</div>
);
}
function SliderTrack({ className, ...props }: ComponentProps<typeof SDKSliderTrack>) {
return (
<SDKSliderTrack
{...props}
className={partClass('w-full self-stretch rounded-[inherit]', className)}
/>
);
}
function SliderIndicator({ className, ...props }: ComponentProps<typeof SDKSliderIndicator>) {
const { pill } = useContext(SliderContext);
return (
<SDKSliderIndicator
{...props}
className={partClass(cn(indicatorBase, pill ? pillIndicator : cellIndicator), className)}
/>
);
}
function SliderThumb({
index = 0,
className,
...props
}: Omit<ComponentProps<typeof SDKSliderThumb>, 'index'> & { index?: number }) {
const { pill } = useContext(SliderContext);
return (
<SDKSliderThumb
{...props}
index={index}
className={partClass(pill ? pillThumb : cellThumb, className)}
/>
);
}
function SliderValue({ className, children, ...props }: ComponentProps<typeof SDKSliderValue>) {
return (
<SDKSliderValue
{...props}
className={partClass(
'max-w-1/2 shrink-0 break-words text-end font-medium tabular-nums text-foreground data-disabled:opacity-50',
className,
)}
>
{children ?? (({ text }) => <ValueTransition value={text} />)}
</SDKSliderValue>
);
}
type SliderProps<Value extends number | number[] = number> = ComponentProps<
typeof SDKSlider<Value>
> &
VariantProps<typeof sliderVariants> & {
/** Visible label, also used as the accessible name of the slider. */
label?: ReactNode;
/** Optional decorative marks, expressed as values within min/max. */
marks?: readonly number[];
thumbLabels?: readonly string[];
};
function Slider<Value extends number | number[] = number>({
label,
size: sizeProp,
variant: variantProp,
orientation = 'horizontal',
marks,
thumbLabels,
className,
children,
min = 0,
max = 100,
...props
}: SliderProps<Value>) {
const labelId = useId();
const size = sizeProp ?? 'md';
const variant = variantProp ?? 'pill';
const pill = variant === 'pill';
const contextValue = useMemo(() => ({ pill, size }), [pill, size]);
const validMarks = useMemo(() => resolveMarks(marks, min, max), [marks, min, max]);
return (
<SliderContext value={contextValue}>
<SDKSlider<Value>
{...props}
min={min}
max={max}
orientation={orientation}
data-size={size}
data-variant={variant}
className={partClass(sliderVariants({ size, variant }), className)}
>
{children ?? (
<>
<SliderControl>
<SliderTrack>
{({ value }) => {
const multiple = Array.isArray(value);
const values = ([] as number[]).concat(value);
const rangeStart = multiple ? values[0] : min;
const rangeEnd = values[values.length - 1];
const indicator = <SliderIndicator />;
return (
<>
{pill ? (
indicator
) : (
<div className="pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit]">
{indicator}
</div>
)}
{validMarks.map((mark) => (
<span
key={mark}
aria-hidden="true"
data-slot="slider-mark"
className={cn(
'pointer-events-none absolute top-1/2 -translate-y-1/2 rounded-lg transition-colors duration-150 motion-reduce:transition-none',
pill && mark >= rangeStart && mark <= rangeEnd
? 'bg-primary-foreground/40'
: 'bg-foreground/10 group-data-dragging/control:bg-foreground/20',
)}
style={{ insetInlineStart: `${((mark - min) / (max - min)) * 100}%` }}
/>
))}
{values.map((_, index) => {
const thumbId = `${labelId}-thumb-${index}`;
return (
<Fragment key={thumbId}>
{multiple && (
<span id={thumbId} className="sr-only">
{thumbLabels?.[index] ?? `Thumb ${index + 1}`}
</span>
)}
<SliderThumb
index={index}
aria-labelledby={
label ? (multiple ? `${labelId} ${thumbId}` : labelId) : undefined
}
/>
</Fragment>
);
})}
</>
);
}}
</SliderTrack>
</SliderControl>
{label && (
<div
data-slot="slider-overlay"
className="pointer-events-none relative col-start-1 row-start-1 flex min-w-0 items-center justify-between"
>
<span
id={labelId}
data-slot="slider-label"
className="min-w-0 break-words text-muted-foreground transition-colors duration-150 group-data-disabled/control:opacity-50 group-data-dragging/control:text-foreground/80 motion-reduce:transition-none"
>
{label}
</span>
<SliderValue />
</div>
)}
</>
)}
</SDKSlider>
</SliderContext>
);
}
export {
createSliderController,
Slider,
SliderControl,
SliderIndicator,
type SliderOptions,
SliderThumb,
SliderTrack,
SliderValue,
};
'use client';
import { type ComponentProps, useState } from 'react';
import { cn } from '@/lib/utils';
export type UseValueTransitionOptions = {
/** Whether characters animate when the value changes. Defaults to `true`. */
enabled?: boolean;
/** Roll direction. `auto` rolls up when a number grows (or for text), down when it shrinks. */
direction?: 'auto' | 'up' | 'down';
/** Delay in ms between consecutive changed characters. Defaults to `28`. */
stagger?: number;
/**
* Animation granularity:
* - `auto` (default): per-character for numeric values, whole-string for text.
* - `char`: always animate per-character.
* - `whole`: always animate the entire value as one unit.
*/
mode?: 'auto' | 'char' | 'whole';
};
export type TransitionChar = {
key: string;
char: string;
/** The character being replaced. Only set when this character should roll. */
prev?: string;
/** Transition delay in ms. */
delay: number;
};
const MAX_DELAY = 140;
const hasDigit = (text: string) => /\d/.test(text);
const isNumeric = (text: string) => hasDigit(text) && !/[a-zA-Z]/.test(text);
const toNumber = (text: string) => Number.parseFloat(text.replace(/[^\d.-]/g, ''));
/**
* Diffs `value` against its previous value and returns per-character data, so
* only the characters that actually changed roll, one after another.
*
* - Numbers align from the right (the ones digit stays the ones digit),
* text aligns from the left.
* - Pure derivation from state, with no effects or DOM reads, so it works for
* any value: numbers, formatted numbers, labels, statuses.
*/
export function useValueTransition(
value: string | number | null | undefined,
{
enabled = true,
direction = 'auto',
stagger = 28,
mode = 'auto',
}: UseValueTransitionOptions = {},
) {
const text = value == null ? '' : String(value);
const [state, setState] = useState({ text, prev: text });
if (state.text !== text) setState({ text, prev: state.text });
const numeric = isNumeric(state.text);
const perChar = mode === 'char' || (mode === 'auto' && numeric);
const dir: 1 | -1 =
direction === 'up'
? 1
: direction === 'down'
? -1
: numeric && hasDigit(state.prev) && toNumber(state.text) < toNumber(state.prev)
? -1
: 1;
if (!perChar) {
const changed = enabled && state.prev !== state.text;
const chars: TransitionChar[] = state.text
? [
{
key: `whole-${state.text}`,
char: state.text,
prev: changed ? state.prev : undefined,
delay: 0,
},
]
: [];
return { text: state.text, chars, dir };
}
const next = [...state.text];
const old = [...state.prev];
const offset = numeric ? old.length - next.length : 0;
const fromEmpty = state.prev === '' && state.text !== '';
// Stagger starts at the least significant end: ones digit first for numbers.
let rank = 0;
const chars: TransitionChar[] = new Array(next.length);
for (let step = 0; step < next.length; step++) {
const i = numeric ? next.length - 1 - step : step;
const char = next[i];
const prevChar = old[i + offset];
const shouldRoll = enabled && (fromEmpty || (prevChar !== undefined && prevChar !== char));
chars[i] = {
// Keyed by position + char: a changed character remounts (replaying the
// animation, even on rapid changes) while untouched ones stay mounted.
key: `${numeric ? next.length - i : i}-${char}`,
char,
prev: shouldRoll ? (prevChar ?? '') : undefined,
delay: shouldRoll ? Math.min(rank++ * stagger, MAX_DELAY) : 0,
};
}
return { text: state.text, chars, dir };
}
const motion =
'transition-[translate,opacity,filter] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none';
export type ValueTransitionProps = Omit<ComponentProps<'span'>, 'children'> &
UseValueTransitionOptions & {
value: string | number | null | undefined;
/** Whether to apply a subtle blur during the transition. Defaults to `true`. */
blur?: boolean;
};
/**
* Drop-in display for any value: `<ValueTransition value={count} />`.
* Inherits font, size and color from its parent.
*/
export function ValueTransition({
value,
enabled,
direction,
stagger,
mode,
blur = true,
className,
...props
}: ValueTransitionProps) {
const { text, chars, dir } = useValueTransition(value, { enabled, direction, stagger, mode });
return (
<span
{...props}
className={cn(
'inline-flex overflow-hidden tabular-nums [mask-image:linear-gradient(to_bottom,transparent,#000_14%,#000_88%,transparent)]',
className,
)}
>
<span className="sr-only"> {text} </span>
<span aria-hidden="true" className="inline-flex">
{chars.map(({ key, char, prev, delay }) => (
<span
key={key}
className={cn(
'relative inline-block whitespace-pre leading-normal',
dir > 0 ? '[--d:1]' : '[--d:-1]',
)}
>
{prev === undefined ? (
char
) : (
<>
<span
style={{ transitionDelay: `${delay}ms` }}
className={cn(
'inline-block starting:translate-y-[calc(var(--d)*100%)] starting:opacity-0',
blur && 'starting:blur-[2px]',
motion,
)}
>
{char}
</span>
<span
aria-hidden="true"
style={{ transitionDelay: `${delay}ms` }}
className={cn(
'absolute inset-0 translate-y-[calc(var(--d)*-100%)] opacity-0 starting:translate-y-0 starting:opacity-100 motion-reduce:hidden',
blur && 'blur-[2px] starting:blur-none',
motion,
)}
>
{prev}
</span>
</>
)}
</span>
))}
</span>
</span>
);
}
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';