Ask for confirmation before an important or irreversible action.
Default
Sizes
Programmatic Confirmation
Purpose
An alert dialog asks people to make a decision before continuing. Use it for important confirmations, such as deleting a project.
Parts & Composition
Put AlertDialogTrigger, AlertDialogBackdrop, and AlertDialogContent inside AlertDialog. Put a title and description inside the content and use AlertDialogClose for each answer. Use the optional header, body, and footer parts for consistent spacing.
API & Props
| Part | Options |
|---|---|
AlertDialog | Use defaultOpen for initial visibility or open with onOpenChange for controlled visibility. Supports controller, dismissal callbacks, and pendingAnnouncement. |
AlertDialogTrigger | Accepts Button variant and size alongside SDK props such as payload, shortcut, and controller. |
AlertDialogContent | Supports xs, sm, md (default), and lg, plus SDK focus, mount, and container options. |
AlertDialogClose | Accepts Button variant and size. Set value to identify the answer. Return a Promise from action to keep the dialog open until it resolves. |
| Controllers | Use createAlertDialogController() for programmatic opening, or createConfirm() and confirm for confirmation flows. Calls to the same createConfirm() function queue in order. The shared confirm helper requires UI SDK’s OverlayHost. |
Theming, Layout & Responsiveness
The surface uses Card’s padding scale. The shared inset tokens derive region padding from --surface-padding at xs (1.3rem), sm (1.35rem), md (1.5rem), and lg (1.75rem).
The panel uses shared surface insets, semantic colors, and a viewport-bounded width. The header and footer retain their spacing while the body can scroll.
Motion & Accessibility
The panel and backdrop respect reduced motion. UI SDK provides modal focus management, the alert dialog role, and title and description associations. Outside clicks leave it open. Provide a clear cancel action and localize the pending announcement for slow actions.
Guidance for Coding Agents
Install Alert Dialog using the command in the Install tab. Read this Info page and the UI SDK Alert Dialog reference before implementing. Start from the closest preview and keep the decision labels explicit. Use value="confirm" for the affirmative choice when using createConfirm(). Let the SDK handle dismissal, pending state, and focus.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/alert-dialog'use client';
import {
AlertDialog,
AlertDialogShortcut,
confirm,
createAlertDialogController,
createConfirm,
AlertDialogBackdrop as SDKAlertDialogBackdrop,
AlertDialogClose as SDKAlertDialogClose,
AlertDialogContent as SDKAlertDialogContent,
AlertDialogDescription as SDKAlertDialogDescription,
AlertDialogTitle as SDKAlertDialogTitle,
AlertDialogTrigger as SDKAlertDialogTrigger,
} from '@ui-sdk/react/alert-dialog';
import { cva } from 'class-variance-authority';
import { Loader2 } from 'lucide-react';
import type { ComponentProps } from 'react';
import { type ButtonProps, buttonVariants } from '@/components/devvarena-ui/button';
import { DialogBody, DialogFooter, DialogHeader } from '@/components/devvarena-ui/dialog';
import { partClass, type StandardControlSize, surfacePadding } from '@/lib/devvarena-ui';
const contentStyles = cva(
'fixed inset-0 m-auto isolate flex h-fit max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] flex-col rounded-lg border border-border bg-background text-foreground shadow-sm outline-none transition-[opacity,scale,filter] duration-200 ease-out data-starting-style:opacity-0 data-ending-style:opacity-0 motion-safe:data-starting-style:scale-95 motion-safe:data-ending-style:scale-[0.98] motion-safe:data-starting-style:blur-xs motion-safe:data-ending-style:blur-xs 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-md',
lg: 'max-w-lg [--surface-padding:1.75rem]',
},
},
},
);
type TriggerAppearance = Pick<ButtonProps, 'size' | 'variant'>;
function AlertDialogTrigger({
variant = 'secondary',
size = 'md',
className,
...props
}: ComponentProps<typeof SDKAlertDialogTrigger> & TriggerAppearance) {
return (
<SDKAlertDialogTrigger
{...props}
data-size={size}
data-variant={variant}
className={partClass(buttonVariants({ variant, size }), className)}
/>
);
}
function AlertDialogBackdrop({
className,
...props
}: ComponentProps<typeof SDKAlertDialogBackdrop>) {
return (
<SDKAlertDialogBackdrop
{...props}
className={partClass(
'fixed inset-0 bg-black/60 backdrop-blur-xs transition-opacity duration-200 data-starting-style:opacity-0 data-ending-style:opacity-0 motion-reduce:transition-none',
className,
)}
/>
);
}
function AlertDialogContent<Payload = unknown>({
size = 'md',
className,
...props
}: ComponentProps<typeof SDKAlertDialogContent<Payload>> & { size?: StandardControlSize }) {
return (
<SDKAlertDialogContent<Payload>
{...props}
data-size={size}
className={partClass(surfacePadding, contentStyles({ size }), className)}
/>
);
}
function AlertDialogTitle({ className, ...props }: ComponentProps<typeof SDKAlertDialogTitle>) {
return (
<SDKAlertDialogTitle
{...props}
className={partClass('m-0 text-lg font-semibold text-balance', className)}
/>
);
}
function AlertDialogDescription({
className,
...props
}: ComponentProps<typeof SDKAlertDialogDescription>) {
return (
<SDKAlertDialogDescription
{...props}
className={partClass('m-0 mt-1 text-sm leading-relaxed text-muted-foreground', className)}
/>
);
}
const actionSpinner = (
<Loader2
aria-hidden="true"
className="hidden animate-spin in-data-pending:inline-block motion-reduce:animate-none"
/>
);
function AlertDialogClose({
variant = 'secondary',
size = 'md',
className,
action,
children,
...props
}: ComponentProps<typeof SDKAlertDialogClose> & TriggerAppearance) {
return (
<SDKAlertDialogClose
{...props}
action={action}
data-size={size}
data-variant={variant}
className={partClass(buttonVariants({ variant, size }), className)}
>
{(state) => (
<>
{action && actionSpinner}
{typeof children === 'function' ? children(state) : children}
</>
)}
</SDKAlertDialogClose>
);
}
export type { AlertDialogController, AlertDialogOptions } from '@ui-sdk/react/alert-dialog';
export {
AlertDialog,
AlertDialogBackdrop,
AlertDialogClose,
AlertDialogContent,
AlertDialogDescription,
AlertDialogShortcut,
AlertDialogTitle,
AlertDialogTrigger,
confirm,
createAlertDialogController,
createConfirm,
DialogBody as AlertDialogBody,
DialogFooter as AlertDialogFooter,
DialogHeader as AlertDialogHeader,
};
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 };
'use client';
import type { DialogOptions } from '@ui-sdk/core/dialog';
import {
Dialog as SDKDialog,
DialogBackdrop as SDKDialogBackdrop,
DialogClose as SDKDialogClose,
DialogContent as SDKDialogContent,
DialogDescription as SDKDialogDescription,
DialogTitle as SDKDialogTitle,
DialogTrigger as SDKDialogTrigger,
} from '@ui-sdk/react/dialog';
import { cva } from 'class-variance-authority';
import { X } from 'lucide-react';
import { type ComponentProps, createContext, type ReactNode, useContext, useMemo } from 'react';
import { Button, type ButtonProps, buttonVariants } from '@/components/devvarena-ui/button';
import { Separator } from '@/components/devvarena-ui/separator';
import {
partClass,
type StandardControlSize,
surfaceBodyPadding,
surfaceFooterRadius,
surfaceHeaderRadius,
surfacePadding,
surfaceRegionInset,
} from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
type DialogSize = StandardControlSize | 'fullscreen';
type DialogAnimation =
| 'scale'
| 'slide-up'
| 'slide-down'
| 'zoom'
| 'perspective'
| 'fade'
| 'none';
type DialogConfig = {
size: DialogSize;
animation: DialogAnimation;
};
const DialogConfigContext = createContext<DialogConfig>({
size: 'md',
animation: 'scale',
});
const dialogPopupVariants = cva(
'group/dialog not-prose relative isolate flex w-full flex-col rounded-lg border border-border bg-background text-foreground shadow-sm outline-none origin-center data-starting-style:will-change-[opacity,transform,filter] data-ending-style:will-change-[opacity,transform,filter] before:pointer-events-none before:absolute before:inset-x-0 before:top-0 before:h-px before:rounded-t-[inherit] before:bg-linear-to-r before:from-transparent before:via-white/25 before:to-transparent dark:before:via-white/12',
{
variants: {
size: {
xs: 'max-w-sm [--surface-padding:1.3rem]',
sm: 'max-w-md [--surface-padding:1.35rem]',
md: 'max-w-lg',
lg: 'max-w-2xl [--surface-padding:1.75rem]',
fullscreen:
'max-w-none w-screen h-[100dvh] rounded-none border-0 p-1 md:p-2 [--surface-padding:1.3rem] md:[--surface-padding:2rem] before:hidden',
},
animation: {
scale:
'transition-[opacity,translate,scale,filter] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] data-ending-style:duration-200 data-ending-style:ease-[cubic-bezier(0.4,0,1,1)] data-starting-style:opacity-0 data-ending-style:opacity-0 motion-safe:data-starting-style:translate-y-1.5 motion-safe:data-starting-style:scale-[0.96] motion-safe:data-starting-style:blur-[2px] motion-safe:data-ending-style:translate-y-1 motion-safe:data-ending-style:scale-[0.97] motion-safe:data-ending-style:blur-[2px] motion-reduce:transition-none',
'slide-up':
'transition-[opacity,translate,scale] duration-320 ease-[cubic-bezier(0.22,1,0.36,1)] data-ending-style:duration-200 data-ending-style:ease-[cubic-bezier(0.4,0,1,1)] data-starting-style:opacity-0 data-ending-style:opacity-0 motion-safe:data-starting-style:translate-y-8 motion-safe:data-starting-style:scale-[0.98] motion-safe:data-ending-style:translate-y-6 motion-safe:data-ending-style:scale-[0.98] motion-reduce:transition-none',
'slide-down':
'transition-[opacity,translate,scale] duration-320 ease-[cubic-bezier(0.22,1,0.36,1)] data-ending-style:duration-200 data-ending-style:ease-[cubic-bezier(0.4,0,1,1)] data-starting-style:opacity-0 data-ending-style:opacity-0 motion-safe:data-starting-style:-translate-y-8 motion-safe:data-starting-style:scale-[0.98] motion-safe:data-ending-style:-translate-y-6 motion-safe:data-ending-style:scale-[0.98] motion-reduce:transition-none',
zoom: 'transition-[opacity,scale,filter] duration-320 ease-[cubic-bezier(0.16,1,0.3,1)] data-ending-style:duration-200 data-ending-style:ease-[cubic-bezier(0.4,0,1,1)] data-starting-style:opacity-0 data-ending-style:opacity-0 motion-safe:data-starting-style:scale-[0.88] motion-safe:data-starting-style:blur-[5px] motion-safe:data-ending-style:scale-[0.94] motion-safe:data-ending-style:blur-[3px] motion-reduce:transition-none',
perspective:
'transition-[opacity,transform,filter] duration-350 ease-[cubic-bezier(0.22,1,0.36,1)] data-ending-style:duration-200 data-ending-style:ease-[cubic-bezier(0.4,0,1,1)] motion-safe:[transform:perspective(1200px)_rotateX(0deg)_translate3d(0,0,0)_scale(1)] data-starting-style:opacity-0 data-ending-style:opacity-0 motion-safe:data-starting-style:[transform:perspective(1200px)_rotateX(8deg)_translate3d(0,20px,0)_scale(0.95)] motion-safe:data-starting-style:blur-[2px] motion-safe:data-ending-style:[transform:perspective(1200px)_rotateX(4deg)_translate3d(0,12px,0)_scale(0.97)] motion-safe:data-ending-style:blur-[2px] motion-reduce:transition-none',
fade: 'transition-[opacity,filter] duration-280 ease-out data-ending-style:duration-200 data-ending-style:ease-in data-starting-style:opacity-0 data-ending-style:opacity-0 motion-safe:data-starting-style:blur-[4px] motion-safe:data-ending-style:blur-[3px] motion-reduce:transition-none',
none: 'transition-none motion-reduce:transition-none',
},
},
defaultVariants: {
size: 'md',
animation: 'scale',
},
},
);
type DialogProps = DialogOptions & {
children?: ReactNode;
size?: DialogSize;
animation?: DialogAnimation;
};
function Dialog({
size = 'md',
animation = 'scale',
presentation = 'dialog',
...props
}: DialogProps) {
const config = useMemo(() => ({ size, animation }), [size, animation]);
return (
<DialogConfigContext value={config}>
<SDKDialog {...props} presentation={presentation} />
</DialogConfigContext>
);
}
function DialogBackdrop({ className, ...props }: ComponentProps<typeof SDKDialogBackdrop>) {
const { animation } = useContext(DialogConfigContext);
return (
<SDKDialogBackdrop
{...props}
className={partClass(
cn(
'fixed inset-0 bg-black/60 backdrop-blur-xs',
animation !== 'none' &&
'transition-opacity duration-300 ease-out data-ending-style:duration-200 data-starting-style:opacity-0 data-ending-style:opacity-0 motion-reduce:transition-none',
),
className,
)}
/>
);
}
type DialogContentProps<Payload = unknown> = ComponentProps<typeof SDKDialogContent<Payload>> & {
size?: DialogSize;
animation?: DialogAnimation;
showClose?: boolean;
closeLabel?: string;
};
function DialogContent<Payload = unknown>({
showClose = true,
closeLabel = 'Close dialog',
size,
animation,
className,
children,
...props
}: DialogContentProps<Payload>) {
const config = useContext(DialogConfigContext);
const effectiveSize = size ?? config.size;
const effectiveAnimation = animation ?? config.animation;
return (
<SDKDialogContent
{...props}
data-show-close={showClose ? '' : undefined}
data-size={effectiveSize}
data-animation={effectiveAnimation}
className={(state) =>
cn(
surfacePadding,
dialogPopupVariants({
size: effectiveSize,
animation: state.presentation === 'sheet' ? 'none' : effectiveAnimation,
}),
'[--sheet-backdrop:rgb(0_0_0/0.6)]',
'data-[presentation=dialog]:fixed data-[presentation=dialog]:inset-0 data-[presentation=dialog]:m-auto data-[presentation=dialog]:overflow-y-auto',
state.modal === true &&
'data-[presentation=dialog]:backdrop:bg-black/60 data-[presentation=dialog]:backdrop:backdrop-blur-xs',
effectiveSize !== 'fullscreen' &&
'data-[presentation=dialog]:h-fit data-[presentation=dialog]:w-[calc(100%-2rem)] data-[presentation=dialog]:max-h-[calc(var(--visual-viewport-height,100dvh)-2rem)]',
'data-[presentation=sheet]:w-full data-[presentation=sheet]:max-w-none data-[presentation=sheet]:max-h-[85dvh] data-[presentation=sheet]:overflow-y-auto data-[presentation=sheet]:overscroll-contain data-[presentation=sheet]:rounded-b-none data-[presentation=sheet]:border-x-0 data-[presentation=sheet]:border-b-0 data-[presentation=sheet]:pb-[max(0.25rem,env(safe-area-inset-bottom))]',
typeof className === 'function' ? className(state) : className,
)
}
>
{(state) => (
<>
{typeof children === 'function' ? children(state) : children}
{showClose && (
<DialogClose
aria-label={closeLabel}
className="absolute end-2.5 top-2.5 z-10 text-muted-foreground hover:text-foreground"
/>
)}
</>
)}
</SDKDialogContent>
);
}
function DialogHeader({
separator = false,
className,
children,
...props
}: ComponentProps<'header'> & { separator?: boolean }) {
return (
<header
{...props}
data-slot="dialog-header"
className={cn(
'[&.sticky]:top-0',
surfaceHeaderRadius,
surfaceRegionInset,
'relative flex shrink-0 flex-col group-data-[show-close]/dialog:pe-10',
className,
)}
>
{children}
{separator && <Separator className="absolute inset-x-0 bottom-0 w-auto" />}
</header>
);
}
function DialogTitle({ className, ...props }: ComponentProps<typeof SDKDialogTitle>) {
return (
<SDKDialogTitle
{...props}
data-slot="dialog-title"
className={partClass(
'm-0 text-xl font-semibold leading-[1.25] tracking-tight text-foreground text-balance group-data-[size=sm]/dialog:text-lg',
className,
)}
/>
);
}
function DialogDescription({ className, ...props }: ComponentProps<typeof SDKDialogDescription>) {
return (
<SDKDialogDescription
{...props}
data-slot="dialog-description"
className={partClass('m-0 mt-1 text-sm leading-relaxed text-muted-foreground', className)}
/>
);
}
function DialogBody({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="dialog-body"
className={cn(
surfaceRegionInset,
'scroll-fade min-w-0 min-h-0 flex-1 overflow-y-auto overscroll-contain text-sm text-foreground [scrollbar-width:thin] [scrollbar-color:var(--border)_transparent]',
surfaceBodyPadding,
className,
)}
/>
);
}
function DialogFooter({
separator = true,
className,
children,
...props
}: ComponentProps<'footer'> & { separator?: boolean }) {
return (
<footer
{...props}
data-slot="dialog-footer"
className={cn(
'relative [&.sticky]:bottom-0',
surfaceFooterRadius,
surfaceRegionInset,
'flex shrink-0 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-end',
className,
)}
>
{separator && <Separator className="absolute inset-x-0 top-0 w-auto" />}
{children}
</footer>
);
}
type DialogTriggerProps = ComponentProps<typeof SDKDialogTrigger> & {
variant?: ButtonProps['variant'];
size?: ButtonProps['size'];
};
function DialogTrigger({
variant = 'secondary',
size = 'md',
className,
...props
}: DialogTriggerProps) {
return (
<SDKDialogTrigger
{...props}
data-size={size}
data-variant={variant}
className={partClass(buttonVariants({ variant, size }), className)}
/>
);
}
type DialogCloseProps = ComponentProps<typeof SDKDialogClose> & {
variant?: ButtonProps['variant'];
size?: ButtonProps['size'];
};
const closeIcon = <X aria-hidden="true" />;
function DialogClose({
children,
variant = 'ghost',
size = 'icon-xs',
className,
'aria-label': label,
...props
}: DialogCloseProps) {
const iconOnly = children == null && props.render == null;
return (
<SDKDialogClose
{...props}
data-size={size}
data-variant={variant}
aria-label={label ?? (iconOnly ? 'Close dialog' : undefined)}
className={partClass(buttonVariants({ variant, size }), className)}
>
{iconOnly ? closeIcon : children}
</SDKDialogClose>
);
}
type DialogActionProps = ButtonProps;
function DialogAction({ variant = 'primary', ...props }: DialogActionProps) {
return <Button variant={variant} {...props} />;
}
export type { DialogContentState, DialogController } from '@ui-sdk/react/dialog';
export { createDialogController, DialogShortcut } from '@ui-sdk/react/dialog';
export {
Dialog,
DialogAction,
type DialogAnimation,
DialogBackdrop,
DialogBody,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
type DialogSize,
DialogTitle,
DialogTrigger,
};
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';