A layered account-card stack with a stitched pocket and a customizable balance summary.
Default
- Studio•• 0842
- Reserve•• 6109
- Available balance
- $24,680.00
Open walletClose wallet
- Studio•• 0842
- Reserve•• 6109
Outline
- Business
- Personal
- Savings•• 1630
- Joint account•• 9251
- Combined balance
- £12,450
Open walletClose wallet
- Business
- Personal
- Savings•• 1630
- Joint account•• 9251
Empty
- No linked accounts
- $0.00
No Motion
- Studio
- Reserve
- Available balance
- $24,680.00
Hide Balance
- Everyday•• 4028
- Reserve
- Available balance
- $24,680.00
Open walletClose wallet
- Everyday•• 4028
- Reserve
Purpose
A wallet card presents cards in a compact wallet-style layout so people can browse and access them from one place.
Parts & Composition
Order: WalletCard → WalletCardStack (ul, WalletCardAccount li children only) → WalletCardPocket (figcaption).
Disclosure (optional): WalletCardTrigger (summary) then WalletCardAccounts / WalletCardAccountItem. Two lists—stack shows up to two cards visually; accounts list is the full set when open; map the same data to both.
Omit disclosure for a static wallet. Omit stack when no card preview row is needed.
| Part | Role | Notes |
|---|---|---|
WalletCard | figure root | variant, material, motion; width via className |
WalletCardSummary, Label, Balance | dl / dt / dd | Label first in DOM; balance first visually |
WalletCardAccountName, Reference | Text | Truncate in stack; wrap in list |
WalletCardAccountIcon | Wrapper | Decorative |
WalletCardTrigger | summary | openLabel / closeLabel (Open / Close wallet) |
WalletCardFooter | Region | Consumer actions—outside summary |
Parts forward native props, refs, className, and style.
API & Props
| Prop | Purpose |
|---|---|
variant | solid or outline pocket |
material | leather (grain, lip) or flat |
motion | auto or none for stack fan/hover |
State & forms
<details> owns open state and keyboard. Use open for SSR defaults; onToggle on the client without a conflicting controlled open. Footer toggles (e.g. balance visibility) are consumer state.
Theming, Layout & Responsiveness
Semantic theme colors on shell and cards. Pocket variables: --wallet-radius, --wallet-shell-background, --wallet-shell-border, --wallet-pocket-background, --wallet-pocket-foreground, --wallet-pocket-border, --wallet-pocket-highlight, --wallet-grain-opacity. Align body and lip pocket values for clean edges. Per-account className / style on account items.
Width scales down in narrow parents. Opening disclosure grows height with the account list.
Motion & Accessibility
motion="auto": stack fan and hover; also respects reduced motion. motion="none": no translation/rotation; disclosure still toggles. Opening fans stack cards.
Set aria-label on each account list when it has items. Trigger labels should stay meaningful when localized. Decorative account icons should not replace account names in the list.
Guidance for Coding Agents
Compose cards within the wallet parts and use the component’s existing layout and motion options. Keep sensitive card details out of previews and provide named controls for any action that reveals, copies, or uses a card.
Set aria-label on WalletCardAccounts and keep trigger labels descriptive; use motion="none" to disable stack fan/hover motion when needed. Keep each account name visible.
Start from the closest Preview → Usage example and use this page’s API table for component parts and options.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/wallet-cardimport { cva } from 'class-variance-authority';
import { ChevronDown } from 'lucide-react';
import type { ComponentProps, CSSProperties } from 'react';
import type { StandardControlSize } from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const walletCardSizes = cva(
'group/wallet relative isolate m-0 grid max-w-full has-[[data-slot=wallet-card-stack]]:grid-rows-[var(--wallet-stack-height)_auto] text-foreground [--wallet-stack-height:4.25rem] has-[[data-slot=wallet-card-account]]:[--wallet-stack-height:5.75rem] has-[[data-slot=wallet-card-account]:nth-child(2)]:[--wallet-stack-height:8.25rem]',
{
variants: {
size: {
xs: 'w-60',
sm: 'w-64',
md: 'w-72',
lg: 'w-80',
} satisfies Record<StandardControlSize, string>,
},
defaultVariants: { size: 'md' },
},
);
const leatherGrain = `url("data:image/svg+xml,${encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" width="160" height="160" viewBox="0 0 160 160"><filter id="grain" x="0" y="0" width="100%" height="100%"><feTurbulence type="fractalNoise" baseFrequency=".24 .32" numOctaves="4" stitchTiles="stitch" result="noise"/><feDiffuseLighting in="noise" lighting-color="white" surfaceScale="1.8" diffuseConstant=".75"><feDistantLight azimuth="225" elevation="48"/></feDiffuseLighting></filter><path fill="#808080" filter="url(#grain)" d="M0 0h160v160H0z"/></svg>',
)}")`;
const pocketLipMask = `url("data:image/svg+xml,${encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 40" preserveAspectRatio="none"><path fill="black" d="M0 40V23C0 10 8 4 23 4C103 4 163 36 278 36C291 36 300 36 300 40V41H0Z"/></svg>',
)}"), linear-gradient(#000, #000)`;
type WalletCardProps = ComponentProps<'figure'> & {
size?: StandardControlSize;
motion?: 'auto' | 'none';
material?: 'leather' | 'flat';
variant?: 'solid' | 'outline';
};
/** Native display composition; root settings flow through CSS, not React context. */
function WalletCard({
size = 'md',
motion = 'auto',
material = 'leather',
variant = 'solid',
className,
style,
...props
}: WalletCardProps) {
return (
<figure
{...props}
data-slot="wallet-card"
data-size={size}
data-variant={variant}
data-motion={motion}
data-material={material}
style={
{
'--wallet-radius': 'var(--radius-lg,0.5rem)',
'--wallet-pocket-foreground':
variant === 'solid' ? 'var(--primary-foreground)' : 'var(--foreground)',
'--wallet-pocket-background':
variant === 'solid'
? 'oklch(from var(--primary) min(l, 0.86) c h)'
: 'oklch(from var(--background) min(l, 0.9) c h)',
'--wallet-pocket-border':
variant === 'solid'
? 'color-mix(in oklab, var(--primary) 70%, transparent)'
: 'var(--border)',
'--wallet-lip-stroke':
material === 'leather'
? 'var(--wallet-pocket-highlight, rgb(255 255 255 / 0.2))'
: 'var(--wallet-pocket-border)',
...style,
} as CSSProperties
}
className={cn(walletCardSizes({ size }), className)}
/>
);
}
/** Put at most two visible account cards here. Later entries remain available as text. */
function WalletCardStack({ className, ...props }: ComponentProps<'ul'>) {
return (
<ul
{...props}
data-slot="wallet-card-stack"
className={cn(
'relative mx-2 mt-2 min-w-0 list-none p-0 empty:rounded-t-[max(0px,calc(var(--wallet-radius)-0.2rem))] empty:border empty:border-dashed empty:border-border',
className,
)}
/>
);
}
function WalletCardAccount({ className, children, ...props }: ComponentProps<'li'>) {
return (
<li
{...props}
data-slot="wallet-card-account"
className={cn(
'absolute isolate inset-x-0 flex h-40 min-w-0 items-start gap-2 rounded-[max(0px,calc(var(--wallet-radius)-0.2rem))] border border-border/40 px-3 py-3 text-xs shadow-sm',
'first:top-0 first:z-1 first:[--wallet-account-background:var(--primary)] first:[--wallet-account-foreground:var(--primary-foreground)] nth-2:top-10 nth-2:z-2 nth-2:[--wallet-account-background:var(--secondary)] nth-2:[--wallet-account-foreground:var(--secondary-foreground)] bg-[var(--wallet-account-background,var(--primary))] text-[color:var(--wallet-account-foreground,var(--primary-foreground))] [&:nth-child(n+3)]:sr-only [&:nth-child(n+3)]:p-0 [&:nth-child(n+3)]:border-0',
'[--wallet-card-rise:-0.5rem] [--wallet-card-angle:2deg] first:[--wallet-card-rise:-1.25rem] first:[--wallet-card-angle:-3deg] only:[--wallet-card-rise:-0.5rem] only:[--wallet-card-angle:0deg]',
'origin-bottom group-data-[motion=auto]/wallet:transition-[transform,translate,rotate,box-shadow] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:group-data-[motion=auto]/wallet:group-hover/wallet:-translate-y-1 motion-safe:group-data-[motion=auto]/wallet:group-has-[details[data-wallet-disclosure][open]]/wallet:translate-y-[var(--wallet-card-rise)] motion-safe:group-data-[motion=auto]/wallet:group-has-[details[data-wallet-disclosure][open]]/wallet:rotate-[var(--wallet-card-angle)] motion-safe:group-data-[motion=auto]/wallet:group-has-[details[data-wallet-disclosure][open]]/wallet:shadow-md motion-reduce:transition-none motion-reduce:translate-y-0 motion-reduce:rotate-0',
'group-data-[material=leather]/wallet:shadow-[inset_0_1px_0_rgb(255_255_255/0.42),inset_0_-1px_0_rgb(0_0_0/0.2),0_2px_4px_rgb(0_0_0/0.18)]',
className,
)}
>
<WalletCardFinish />
{children}
</li>
);
}
function WalletCardAccountIcon({ className, ...props }: ComponentProps<'span'>) {
return (
<span
aria-hidden="true"
{...props}
data-slot="wallet-card-account-icon"
className={cn(
'relative z-10 flex size-4 shrink-0 items-center justify-center [&>svg]:size-4',
className,
)}
/>
);
}
function WalletCardAccountName({ className, ...props }: ComponentProps<'span'>) {
return (
<span
{...props}
data-slot="wallet-card-name"
className={cn('relative z-10 min-w-0 flex-1 truncate font-medium', className)}
/>
);
}
function WalletCardAccountReference({ className, ...props }: ComponentProps<'span'>) {
return (
<span
{...props}
data-slot="wallet-card-reference"
className={cn(
'relative z-10 max-w-[40%] truncate text-xs leading-4 tabular-nums opacity-75',
className,
)}
/>
);
}
function WalletCardPocket({ className, children, style, ...props }: ComponentProps<'figcaption'>) {
return (
<figcaption
{...props}
data-slot="wallet-card-pocket"
style={
{
'--wallet-stitch-inset': 'calc(3.333333% - 1px)',
...style,
} as CSSProperties
}
className={cn(
'relative isolate z-10 flex min-w-0 flex-col justify-end rounded-b-[var(--wallet-radius)] border border-t-0 border-[var(--wallet-pocket-border)] bg-[var(--wallet-pocket-background)] text-[color:var(--wallet-pocket-foreground)] shadow-sm',
'min-h-36 p-5',
'group-data-[motion=auto]/wallet:transition-transform duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:group-data-[motion=auto]/wallet:group-has-[details[data-wallet-disclosure][open]]/wallet:translate-y-1 motion-reduce:transition-none motion-reduce:translate-y-0',
'group-data-[material=leather]/wallet:shadow-[inset_0_-2px_3px_rgb(0_0_0/0.28),0_3px_6px_rgb(0_0_0/0.16)]',
className,
)}
>
<svg
aria-hidden="true"
focusable="false"
data-slot="wallet-card-lip"
viewBox="0 0 300 40"
preserveAspectRatio="none"
className={cn(
'pointer-events-none absolute -top-[39px] -start-px h-10 w-[calc(100%+2px)] overflow-visible',
)}
>
<path
d="M0 40V23C0 10 8 4 23 4C103 4 163 36 278 36C291 36 300 36 300 40V41H0Z"
fill="var(--wallet-pocket-background)"
/>
<path
d="M0.5 40V23C0.5 10 8 4.5 23 4.5C103 4.5 163 36.5 278 36.5C291 36.5 299.5 36.5 299.5 40"
fill="none"
stroke="var(--wallet-lip-stroke)"
vectorEffect="non-scaling-stroke"
/>
<path
d="M10 48V24C10 17 14 14 25 14C103 14 163 46 290 46V48"
fill="none"
stroke="currentColor"
strokeDasharray="2 3"
className="opacity-15 group-data-[material=leather]/wallet:opacity-30"
vectorEffect="non-scaling-stroke"
/>
</svg>
<WalletLeatherSurface />
<span
aria-hidden="true"
data-slot="wallet-card-stitch"
className={cn(
'pointer-events-none absolute inset-y-2 inset-x-[var(--wallet-stitch-inset)] z-10 rounded-b-[max(0px,calc(var(--wallet-radius)-0.2rem))] border border-t-0 border-dashed border-current',
'opacity-15 group-data-[material=leather]/wallet:opacity-30 group-data-[material=leather]/wallet:[filter:drop-shadow(0_1px_0_rgb(0_0_0/0.3))]',
)}
/>
<span
aria-hidden="true"
className="absolute start-5 top-4 z-10 h-1 w-7 rounded-full bg-current opacity-20 shadow-[0_1px_0_rgb(255_255_255/0.1)]"
/>
{children}
</figcaption>
);
}
/** One label/value pair; the visible amount comes first without changing dl semantics. */
function WalletCardSummary({ className, ...props }: ComponentProps<'dl'>) {
return (
<dl
{...props}
data-slot="wallet-card-summary"
className={cn(
'relative z-10 m-0 flex min-w-0 flex-col gap-1 pt-3 group-has-[[data-wallet-disclosure]]/wallet:pt-8',
className,
)}
/>
);
}
function WalletCardLabel({ className, ...props }: ComponentProps<'dt'>) {
return (
<dt
{...props}
data-slot="wallet-card-label"
className={cn('order-2 text-xs leading-relaxed opacity-75', className)}
/>
);
}
function WalletCardBalance({ className, ...props }: ComponentProps<'dd'>) {
return (
<dd
{...props}
data-slot="wallet-card-balance"
className={cn(
'order-1 m-0 min-w-0 break-words text-3xl font-medium leading-tight tracking-tight tabular-nums',
className,
)}
/>
);
}
/** Native details owns open state. Omit it entirely for a display-only wallet. */
function WalletCardDisclosure({ className, ...props }: ComponentProps<'details'>) {
return (
<details
{...props}
data-wallet-disclosure=""
data-slot="wallet-card-disclosure"
className={cn('group/wallet-disclosure', className)}
/>
);
}
function WalletCardTrigger({
openLabel = 'Open wallet',
closeLabel = 'Close wallet',
className,
children,
...props
}: ComponentProps<'summary'> & { openLabel?: string; closeLabel?: string }) {
return (
<summary
{...props}
data-slot="wallet-card-toggle"
className={cn(
'absolute end-4 top-2 z-20 flex min-h-5 cursor-pointer list-none items-center gap-1.5 rounded-full px-2 text-xs font-medium outline-none transition-colors hover:bg-current/10 focus-visible:ring-3 focus-visible:ring-current/30 active:bg-current/15 motion-reduce:transition-none [&::-webkit-details-marker]:hidden',
className,
)}
>
{children ?? (
<>
<span className="group-open/wallet-disclosure:hidden">{openLabel}</span>
<span className="hidden group-open/wallet-disclosure:inline">{closeLabel}</span>
<ChevronDown
aria-hidden="true"
className="size-3 group-data-[motion=auto]/wallet:transition-[rotate] group-data-[motion=auto]/wallet:duration-300 motion-safe:group-data-[motion=auto]/wallet:group-open/wallet-disclosure:rotate-180 motion-reduce:transition-none"
/>
</>
)}
</summary>
);
}
function WalletCardAccounts({ className, children, ...props }: ComponentProps<'ul'>) {
return (
<ul
{...props}
data-slot="wallet-card-accounts"
className={cn(
'relative z-10 mt-4 flex list-none flex-col gap-2 border-t border-dashed border-current/10 pt-3 text-xs group-data-[material=leather]/wallet:border-current/20',
'-mx-[calc(1.25rem-var(--wallet-stitch-inset))] px-[calc(1.25rem-var(--wallet-stitch-inset))]',
className,
)}
>
{children}
</ul>
);
}
function WalletCardAccountItem({ className, ...props }: ComponentProps<'li'>) {
return (
<li
{...props}
data-slot="wallet-card-account-item"
className={cn(
'flex min-w-0 flex-wrap items-baseline justify-between gap-x-3 gap-y-1 [&>[data-slot=wallet-card-name]]:whitespace-normal [&>[data-slot=wallet-card-name]]:break-words [&>[data-slot=wallet-card-name]]:overflow-visible [&>[data-slot=wallet-card-reference]]:max-w-full [&>[data-slot=wallet-card-reference]]:whitespace-normal [&>[data-slot=wallet-card-reference]]:break-words',
className,
)}
/>
);
}
function WalletCardFooter({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="wallet-card-footer"
className={cn(
'relative z-10 mt-6 flex min-w-0 flex-wrap items-center justify-between gap-2 text-xs',
className,
)}
/>
);
}
function WalletLeatherSurface() {
return (
<span
aria-hidden="true"
data-slot="wallet-card-grain"
className={cn(
'hidden group-data-[material=leather]/wallet:block pointer-events-none absolute -inset-x-px -top-[39px] bottom-0 z-0 rounded-b-[inherit] mix-blend-soft-light',
)}
style={{
backgroundImage: `${leatherGrain}, radial-gradient(ellipse at 18% 0%, rgb(255 255 255 / 0.28), transparent 60%), linear-gradient(135deg, rgb(255 255 255 / 0.1), transparent 45%, rgb(0 0 0 / 0.24))`,
backgroundSize: '128px 128px, 100% 100%, 100% 100%',
opacity: 'var(--wallet-grain-opacity, 0.6)',
maskImage: pocketLipMask,
maskSize: '100% 40px, calc(100% - 2px) calc(100% - 40px)',
maskPosition: 'top, bottom',
maskRepeat: 'no-repeat',
WebkitMaskImage: pocketLipMask,
WebkitMaskSize: '100% 40px, calc(100% - 2px) calc(100% - 40px)',
WebkitMaskPosition: 'top, bottom',
WebkitMaskRepeat: 'no-repeat',
}}
/>
);
}
function WalletCardFinish() {
return (
<span
aria-hidden="true"
data-slot="wallet-card-finish"
className={cn(
'hidden group-data-[material=leather]/wallet:block pointer-events-none absolute inset-0 z-0 overflow-hidden rounded-[inherit] bg-[linear-gradient(145deg,rgb(255_255_255/0.12),transparent_38%,rgb(0_0_0/0.12))]',
)}
>
<span
className={cn(
'absolute -inset-x-1/2 inset-y-0 bg-[linear-gradient(115deg,transparent_24%,rgb(255_255_255/0.04)_35%,rgb(255_255_255/0.2)_43%,rgb(255_255_255/0.04)_50%,transparent_63%)]',
'group-data-[motion=auto]/wallet:transition-transform duration-700 ease-out motion-safe:group-data-[motion=auto]/wallet:group-hover/wallet:translate-x-[12%] motion-safe:group-data-[motion=auto]/wallet:group-has-[details[data-wallet-disclosure][open]]/wallet:translate-x-[22%] motion-reduce:transition-none',
)}
/>
</span>
);
}
export {
WalletCard,
WalletCardAccount,
WalletCardAccountIcon,
WalletCardAccountItem,
WalletCardAccountName,
WalletCardAccountReference,
WalletCardAccounts,
WalletCardBalance,
WalletCardDisclosure,
WalletCardFooter,
WalletCardLabel,
WalletCardPocket,
type WalletCardProps,
WalletCardStack,
WalletCardSummary,
WalletCardTrigger,
};
'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';