Compound semantic list surface with aligned header and footer regions, shared Separator row dividers, and sliding highlight.
Default
Infrastructure services
Live status across your production cluster.
- Edge CDN32 global PoPs activeHealthy Healthy
- Object Storage142.8 GB of 500 GB usedSynced Synced
- Secrets VaultLast rotated 4 hours agoEncrypted Encrypted
- Deploy PipelineAuto-deploys on main branchReady Ready
Sizes
Workspace activity
- Release notes published
- Design review scheduled
Variants & Empty State
Inset surface
Muted secondary container for grouped metadata.
- Deployment regionPrimary compute availability zoneus-east-1
- Node runtimeActive container runtime targetv22.11.0
Archived releases
Empty list fallback with custom icon and copy.
No archived releases
Completed deployments moved to archive will appear here.
Interactive & Highlight
Workspace navigation
Use Arrow Up/Down or hover across rows. Alert channels is disabled.
Purpose
A list groups related items into easy-to-scan rows. Each row can include a label, supporting details, and actions.
Parts & Composition
| Part | Role / native element | Notes |
|---|---|---|
List | <section> | Surface root (card, inset, or plain) |
ListHeader | <header> | Inset-aligned top region with optional separator |
ListTitle | <h2> / <h3> / <h4> | Section heading (defaults to <h3>) |
ListDescription | <p> | Supporting description (mt-1 below title) |
ListItems | <ul> / <ol> | Row container with useSlidingHighlight and Separator dividers |
ListItem | <li> | Flex row container (disabled) with automatic Separator |
ListItemMedia | <div> (aria-hidden) | Leading 36px icon, avatar, or thumbnail frame |
ListItemContent | <div> | Flexible column for ListItemTitle and ListItemDescription |
ListItemTitle | <div> | Primary row label (text-sm font-medium) |
ListItemDescription | <div> | Secondary row detail (text-xs text-muted-foreground) |
ListItemMeta | <div> | Trailing tabular metadata (text-xs tabular-nums) |
ListItemAction | <div> | Trailing controls or badges |
ListSeparator | <li aria-hidden> | Valid <ul> divider wrapping shared Separator |
ListFooter | <footer> | Inset-aligned bottom row with separator (default true) |
ListEmpty | <div> | Empty-state slot when zero items are rendered |
API & Props
Use size (xs, sm, md or lg) on card and inset lists to scale width and region insets. Plain lists fill the parent width.
| Part | Prop | Type / Default | Purpose |
|---|---|---|---|
List | variant | 'card' / 'inset' / 'plain' ('card') | Surface container framing and padding |
ListHeader | separator | boolean (false) | 1px horizontal bottom divider |
ListTitle | as | 'h2' / 'h3' / 'h4' ('h3') | Semantic heading level |
ListItems | as | 'ul' / 'ol' ('ul') | List semantics |
ListItems | divided | boolean (true) | Divides consecutive ListItem rows using Separator |
ListItems | slidingHighlight | boolean (true) | Enables zero-rerender hover/focus sliding highlight |
ListItem | disabled | boolean (false) | Dims the row and makes its content inert |
ListOptions | value / defaultValue | T | null or T[] with multiple | Controls the current selection or sets the initial selection |
ListOptions | onValueChange | (value, details) => void | Receives changes to the selection. Call details.cancel() to prevent the change |
ListOptions | multiple | boolean (false) | Allows selecting multiple options |
ListOptions | slidingHighlight | boolean (true) | Enables sliding focus feedback. Turning it off uses a stationary highlight |
ListOption | value | T | Identifies the option in the selection |
ListOption | label | string | Supplies the option label for typeahead when using rich content |
ListOption | disabled | boolean (false) | Makes the option unavailable for selection |
ListFooter | separator | boolean (true) | 1px horizontal top divider |
Theming, Layout & Responsiveness
Uses card, card-foreground, muted, muted-foreground, border, accent, and ring tokens. Surface padding scales via --surface-padding (1rem on phones, 1.5rem from tablet upward on card). Header, items, and footer share surfaceRegionInset for outer edge insets and derived rounded-lg inner corner radii.
Phone (<768px), tablet (md:), desktop (lg:). card and inset surfaces use max-w-lg and min-w-0 so long titles/descriptions wrap cleanly without horizontal overflow. Embedded buttons and badges use their own control/compact size tokens (Button sm / md, Badge sm).
ListItem transitions background color over 150ms. ListItems animates the shared sliding highlight (transform, width, height, opacity) over 200ms ease-out via CSS custom properties with motion-reduce:transition-none.
Motion & Accessibility
Preserves native <ul>/<ol> and <li> semantics for static lists (ListItems / ListItem), and full WAI-ARIA listbox / option semantics with Up/Down/Home/End/typeahead keyboard navigation for interactive lists (ListOptions / ListOption). ListSeparator and ListOptionSeparator wrap Separator so markup stays valid. Decorative ListItemMedia is aria-hidden="true". ListItem disabled makes the entire row inert, while ListOption disabled keeps the option readable to assistive technology.
Guidance for Coding Agents
Install using the command in the Install tab. Read this Info page before implementing.
Compose the list and item parts to retain list semantics and shared spacing. Put actions in their own labeled controls inside each item. Use stable item keys and apply the sliding highlight only where it helps users track a row.
Place interactive controls (Button, Switch, links) inside ListItemAction, or use ListOptions + ListOption (backed by @ui-sdk/react/listbox) for full-row keyboard-navigable lists.
Start from the closest Preview → Usage example and use this page’s API table for component parts and options.
Registry
Client component ('use client'). Bundles use-sliding-highlight.ts, separator, and class-variance-authority.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/list'use client';
import {
Listbox as SDKListbox,
ListboxItem as SDKListboxItem,
type ListboxProps as SDKListboxProps,
ListboxSeparator as SDKListboxSeparator,
} from '@ui-sdk/react/listbox';
import { cva, type VariantProps } from 'class-variance-authority';
import type { ComponentProps } from 'react';
import { Separator } from '@/components/devvarena-ui/separator';
import { useSlidingHighlight } from '@/hooks/use-sliding-highlight';
import {
concentricRadius,
partClass,
type StandardControlSize,
slidingHighlight as slidingHighlightClass,
surfaceFooterRadius,
surfaceHeaderRadius,
surfacePadding,
surfaceRegionInset,
} from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const listVariants = cva('group/list relative isolate flex w-full min-w-0 flex-col', {
variants: {
variant: {
card: cn(
'gap-3.5 rounded-lg border border-border bg-card text-card-foreground shadow-sm',
surfacePadding,
),
inset:
'gap-3 rounded-lg border border-border/70 bg-muted/35 p-1 md:p-1.5 md:[--concentric-inset:0.375rem] text-foreground [--surface-padding:1.3rem] md:[--surface-padding:1.35rem]',
plain: 'gap-3 p-0 text-foreground [--surface-padding:1.3rem]',
},
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]',
},
},
defaultVariants: {
variant: 'card',
size: 'md',
},
});
type ListProps = ComponentProps<'section'> &
Omit<VariantProps<typeof listVariants>, 'size'> & { size?: StandardControlSize };
/**
* Compound list surface with aligned header/footer regions, shared `Separator`
* row dividers, and zero-rerender sliding highlight via `useSlidingHighlight`.
*/
function List({ variant = 'card', size = 'md', className, ...props }: ListProps) {
return (
<section
{...props}
data-slot="list"
data-variant={variant}
data-size={size}
className={cn(listVariants({ variant, size: variant === 'plain' ? null : size }), className)}
/>
);
}
function ListHeader({
separator = false,
className,
children,
...props
}: ComponentProps<'header'> & { separator?: boolean }) {
return (
<header
{...props}
data-slot="list-header"
className={cn(
'relative flex flex-col',
surfaceHeaderRadius,
'[&.sticky]:top-0',
surfaceRegionInset,
className,
)}
>
{children}
{separator ? <Separator className="absolute inset-x-0 bottom-0 w-auto" /> : null}
</header>
);
}
function ListTitle({
as: Heading = 'h3',
className,
...props
}: ComponentProps<'h3'> & { as?: 'h2' | 'h3' | 'h4' }) {
return (
<Heading
{...props}
data-slot="list-title"
className={cn(
'm-0 break-words text-xl font-semibold leading-[1.25] tracking-tight text-balance',
className,
)}
/>
);
}
function ListDescription({ className, ...props }: ComponentProps<'p'>) {
return (
<p
{...props}
data-slot="list-description"
className={cn('m-0 mt-1 text-sm leading-relaxed text-muted-foreground', className)}
/>
);
}
type ListItemsProps = Omit<ComponentProps<'ul'>, 'ref'> & {
/** Semantic list element (`ul` by default, or `ol` for ordered lists). */
as?: 'ul' | 'ol';
/** Divides consecutive `ListItem` rows with the shared `Separator`. Defaults to true. */
divided?: boolean;
/** Enables zero-rerender pointer and focus sliding highlight across items. Defaults to true. */
slidingHighlight?: boolean;
};
function ListItems({
as = 'ul',
divided = true,
slidingHighlight = true,
className,
children,
...props
}: ListItemsProps) {
const { containerRef, highlightStyle } = useSlidingHighlight({
itemSelector:
'[data-slot=list-item]:not([data-disabled]):not([aria-disabled=true]):not([inert]), [data-highlight-item]:not(:disabled):not([data-disabled]):not([aria-disabled=true]):not([inert])',
disabled: !slidingHighlight,
});
const listClasses = cn(
'group/list-items relative m-0 flex list-none flex-col gap-0.5 p-0',
divided && '[&>[data-slot=list-item]+[data-slot=list-item]>[data-slot=separator]]:block',
className,
);
return (
<div
ref={containerRef}
data-slot="list-items-container"
data-sliding-highlight={slidingHighlight || undefined}
className={cn(surfaceRegionInset, 'relative isolate py-0')}
>
{slidingHighlight && (
<span aria-hidden="true" style={highlightStyle} className={slidingHighlightClass} />
)}
{as === 'ol' ? (
<ol
{...props}
data-slot="list-items"
data-divided={divided || undefined}
data-sliding-highlight={slidingHighlight || undefined}
className={listClasses}
>
{children}
</ol>
) : (
<ul
{...props}
data-slot="list-items"
data-divided={divided || undefined}
data-sliding-highlight={slidingHighlight || undefined}
className={listClasses}
>
{children}
</ul>
)}
</div>
);
}
type ListItemProps = ComponentProps<'li'> & {
/** Makes the entire row unavailable, including any actions inside it. */
disabled?: boolean;
};
function ListItem({ disabled = false, inert, className, children, ...props }: ListItemProps) {
return (
<li
{...props}
data-slot="list-item"
data-disabled={disabled ? '' : undefined}
inert={disabled || inert}
className={cn(
`group/list-item relative -mx-2.5 flex min-w-0 items-center gap-3 ${concentricRadius} px-2.5 py-2.5 transition-colors duration-150 motion-reduce:transition-none`,
disabled && 'opacity-50',
className,
)}
>
<Separator className="pointer-events-none absolute inset-x-2.5 -top-px hidden w-auto" />
{children}
</li>
);
}
type ListOptionsProps<
Value = string,
Multiple extends boolean | undefined = false,
> = SDKListboxProps<Value, Multiple> & {
/** Enables zero-rerender pointer and keyboard sliding highlight across options. Defaults to true. */
slidingHighlight?: boolean;
};
/** Interactive listbox rows with UI SDK Up/Down/Home/End keyboard navigation and selection. */
function ListOptions<Value = string, Multiple extends boolean | undefined = false>({
slidingHighlight = true,
className,
children,
...props
}: ListOptionsProps<Value, Multiple>) {
const { containerRef, highlightStyle } = useSlidingHighlight({
itemSelector: '[data-slot=listbox-item]:not([data-disabled]):not([aria-disabled=true])',
activeAttribute: 'data-highlighted',
disabled: !slidingHighlight,
});
return (
<div
ref={containerRef}
data-slot="list-items-container"
data-sliding-highlight={slidingHighlight || undefined}
className={cn(surfaceRegionInset, 'relative isolate py-0')}
>
{slidingHighlight && (
<span aria-hidden="true" style={highlightStyle} className={slidingHighlightClass} />
)}
<SDKListbox<Value, Multiple>
{...(props as SDKListboxProps<Value, Multiple>)}
data-sliding-highlight={slidingHighlight || undefined}
className={partClass(
'group/list-options relative m-0 flex flex-col gap-0.5 p-0 outline-none',
className,
)}
>
{children}
</SDKListbox>
</div>
);
}
function ListOption<Value = string>({
className,
...props
}: ComponentProps<typeof SDKListboxItem<Value>>) {
return (
<SDKListboxItem<Value>
{...props}
className={partClass(
`group/list-item relative -mx-2.5 flex min-w-0 cursor-pointer touch-manipulation items-center gap-3 ${concentricRadius} px-2.5 py-2.5 text-start outline-none select-none transition-colors duration-150 motion-reduce:transition-none group-not-data-sliding-highlight/list-options:data-highlighted:bg-accent data-disabled:cursor-not-allowed data-disabled:opacity-50`,
className,
)}
/>
);
}
function ListOptionSeparator({ className, ...props }: ComponentProps<typeof SDKListboxSeparator>) {
return (
<SDKListboxSeparator
{...props}
render={<Separator />}
className={partClass('my-1', className)}
/>
);
}
function ListItemMedia({ className, ...props }: ComponentProps<'div'>) {
return (
<div
aria-hidden="true"
{...props}
data-slot="list-item-media"
className={cn(
'flex size-9 shrink-0 items-center justify-center rounded-lg border border-border/70 bg-muted/50 text-muted-foreground [&>svg]:size-4 [&>img]:size-full [&>img]:rounded-[inherit] [&>img]:object-cover',
className,
)}
/>
);
}
function ListItemContent({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="list-item-content"
className={cn('flex min-w-0 flex-1 flex-col', className)}
/>
);
}
function ListItemTitle({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="list-item-title"
className={cn(
'min-w-0 break-words text-sm font-medium leading-snug text-foreground',
className,
)}
/>
);
}
function ListItemDescription({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="list-item-description"
className={cn(
'mt-0.5 min-w-0 break-words text-xs leading-relaxed text-muted-foreground',
className,
)}
/>
);
}
function ListItemMeta({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="list-item-meta"
className={cn('shrink-0 text-xs tabular-nums text-muted-foreground', className)}
/>
);
}
function ListItemAction({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="list-item-action"
className={cn('flex shrink-0 items-center gap-2', className)}
/>
);
}
/** Semantically valid list divider wrapped in `li[aria-hidden]` around shared `Separator`. */
function ListSeparator({ className, ...props }: ComponentProps<'li'>) {
return (
<li
aria-hidden="true"
data-slot="list-separator"
className={cn('my-1 list-none', className)}
{...props}
>
<Separator />
</li>
);
}
function ListFooter({
separator = true,
className,
children,
...props
}: ComponentProps<'footer'> & { separator?: boolean }) {
return (
<footer
{...props}
data-slot="list-footer"
className={cn(
'relative mt-0 flex items-center justify-between gap-3 text-xs text-muted-foreground',
surfaceFooterRadius,
'[&.sticky]:bottom-0',
surfaceRegionInset,
className,
)}
>
{separator ? <Separator className="absolute inset-x-0 top-0 w-auto" /> : null}
{children}
</footer>
);
}
function ListEmpty({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="list-empty"
className={cn(
surfaceRegionInset,
'flex flex-col items-center justify-center py-8 text-center text-sm text-muted-foreground',
className,
)}
/>
);
}
export type { ListItemProps, ListItemsProps, ListOptionsProps, ListProps };
export {
List,
ListDescription,
ListEmpty,
ListFooter,
ListHeader,
ListItem,
ListItemAction,
ListItemContent,
ListItemDescription,
ListItemMedia,
ListItemMeta,
ListItems,
ListItemTitle,
ListOption,
ListOptionSeparator,
ListOptions,
ListSeparator,
ListTitle,
};
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 };
'use client';
import { type CSSProperties, useCallback, useMemo } from 'react';
export type UseSlidingHighlightOptions = {
/** Mark eligible descendants with this selector. */
itemSelector?: string;
/** Resolve a row when the primitive focuses its parent instead of the row itself. */
focusItemSelector?: string;
disabled?: boolean;
/** Follow a primitive-owned state attribute on eligible items. */
activeAttribute?: string;
};
function highlightProperties(activeAttribute?: string) {
const prefix = activeAttribute ? `--sliding-highlight-${activeAttribute}` : '--sliding-highlight';
return {
left: `${prefix}-left`,
top: `${prefix}-top`,
width: `${prefix}-width`,
height: `${prefix}-height`,
opacity: `${prefix}-opacity`,
};
}
type Clipper = { el: Element; x: boolean; y: boolean };
/** Decorative hover/focus feedback; zero React state or useEffect. */
export function useSlidingHighlight({
itemSelector = '[data-highlight-item]',
focusItemSelector,
disabled = false,
activeAttribute,
}: UseSlidingHighlightOptions = {}) {
const properties = useMemo(() => highlightProperties(activeAttribute), [activeAttribute]);
const highlightStyle = useMemo<CSSProperties>(
() => ({
position: 'absolute',
top: 0,
left: 0,
width: `var(${properties.width}, 0px)`,
height: `var(${properties.height}, 0px)`,
transform: `translate3d(var(${properties.left}, 0px), var(${properties.top}, 0px), 0)`,
opacity: `var(${properties.opacity}, 0)`,
pointerEvents: 'none',
}),
[properties],
);
const containerRef = useCallback(
(container: HTMLElement | null) => {
if (!container || disabled) return;
const activeSelector = activeAttribute ? `${itemSelector}[${activeAttribute}]` : null;
const style = container.style;
let hovered: HTMLElement | null = null;
let focused: HTMLElement | null = null;
let observed: HTMLElement | null = null;
let clippers: Clipper[] = [];
let visible: boolean | null = null;
let pLeft = NaN;
let pTop = NaN;
let pWidth = NaN;
let pHeight = NaN;
const findItem = (target: EventTarget | null) => {
const item = target instanceof Element ? target.closest<HTMLElement>(itemSelector) : null;
return item && item !== container && container.contains(item) ? item : null;
};
// Programmatic/pointer focus must not pin a popover's initially focused row.
const findFocusedItem = (target: EventTarget | null) => {
if (!(target instanceof Element) || !target.matches(':focus-visible')) return null;
const inner = focusItemSelector ? target.querySelector(focusItemSelector) : null;
return findItem(inner ?? target);
};
const setVisible = (next: boolean) => {
if (visible === next) return;
visible = next;
style.setProperty(properties.opacity, next ? '1' : '0');
};
// Runs only when the tracked item changes, so getComputedStyle is not called per frame.
const track = (item: HTMLElement | null) => {
if (observed === item) return;
if (observed) resize?.unobserve(observed);
if (item) resize?.observe(item);
observed = item;
clippers = [];
for (let el = item?.parentElement; el && el !== container; el = el.parentElement) {
const { overflowX, overflowY } = getComputedStyle(el);
const x = overflowX !== 'visible';
const y = overflowY !== 'visible';
if (x || y) clippers.push({ el, x, y });
}
};
const measure = () => {
const item = activeSelector
? container.querySelector<HTMLElement>(activeSelector)
: focused?.matches(itemSelector) && container.contains(focused)
? focused
: hovered;
const valid = item && container.contains(item) && item.matches(itemSelector);
track(valid ? item : null);
if (!valid) return setVisible(false);
const outer = container.getBoundingClientRect();
const inner = item.getBoundingClientRect();
if (!outer.width || !outer.height || !inner.width || !inner.height) {
return setVisible(false);
}
let { left: cLeft, top: cTop, right: cRight, bottom: cBottom } = inner;
for (const { el, x, y } of clippers) {
const r = el.getBoundingClientRect();
if (x) {
cLeft = Math.max(cLeft, r.left);
cRight = Math.min(cRight, r.right);
}
if (y) {
cTop = Math.max(cTop, r.top);
cBottom = Math.min(cBottom, r.bottom);
}
}
if (cRight <= cLeft || cBottom <= cTop) return setVisible(false);
const scaleX = container.offsetWidth / outer.width;
const scaleY = container.offsetHeight / outer.height;
const left = (cLeft - outer.left) * scaleX - container.clientLeft + container.scrollLeft;
const top = (cTop - outer.top) * scaleY - container.clientTop + container.scrollTop;
const width = (cRight - cLeft) * scaleX;
const height = (cBottom - cTop) * scaleY;
if (left !== pLeft) {
pLeft = left;
style.setProperty(properties.left, `${left}px`);
}
if (top !== pTop) {
pTop = top;
style.setProperty(properties.top, `${top}px`);
}
if (width !== pWidth) {
pWidth = width;
style.setProperty(properties.width, `${width}px`);
}
if (height !== pHeight) {
pHeight = height;
style.setProperty(properties.height, `${height}px`);
}
setVisible(true);
};
const resize = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : null;
const mutation = new MutationObserver(measure);
const onPointer = (e: PointerEvent) => {
if (e.pointerType === 'touch') return;
const next = findItem(e.type === 'pointerout' ? e.relatedTarget : e.target);
if (next === hovered) return;
hovered = next;
measure();
};
const onPointerLeave = (e: PointerEvent) => {
if (e.pointerType === 'touch') return;
hovered = null;
measure();
};
const onFocus = (e: FocusEvent) => {
focused = findFocusedItem(e.type === 'focusin' ? e.target : e.relatedTarget);
measure();
};
resize?.observe(container);
mutation.observe(container, {
childList: true,
subtree: true,
...(activeAttribute && {
attributeFilter: [activeAttribute, 'data-disabled', 'aria-disabled'],
}),
});
container.addEventListener('scroll', measure, { capture: true, passive: true });
if (!activeSelector) {
focused = findFocusedItem(document.activeElement);
container.addEventListener('pointerover', onPointer);
container.addEventListener('pointermove', onPointer);
container.addEventListener('pointerout', onPointer);
container.addEventListener('pointerleave', onPointerLeave);
container.addEventListener('pointercancel', onPointerLeave);
container.addEventListener('focusin', onFocus);
container.addEventListener('focusout', onFocus);
}
measure();
return () => {
resize?.disconnect();
mutation.disconnect();
container.removeEventListener('scroll', measure, true);
if (!activeSelector) {
container.removeEventListener('pointerover', onPointer);
container.removeEventListener('pointermove', onPointer);
container.removeEventListener('pointerout', onPointer);
container.removeEventListener('pointerleave', onPointerLeave);
container.removeEventListener('pointercancel', onPointerLeave);
container.removeEventListener('focusin', onFocus);
container.removeEventListener('focusout', onFocus);
}
for (const v of Object.values(properties)) style.removeProperty(v);
};
},
[itemSelector, focusItemSelector, disabled, activeAttribute, properties],
);
return { containerRef, highlightStyle };
}
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';