Contextual panels with a curved pointer, quiet motion, and composable help and actions.
Default
Sizes
Actions
Select an action to preview its intent. No workspace data is changed.
Prompt Chips
Help Panel
Placement
Custom Anchoring
Sheet
Draft Guard & Modal
Type a note, then try Escape or clicking outside.
Hover & Nested
Hover, click, or press the shortcut to inspect @kofi.
Shared Popover
- Hollis Grant Owner Owner
@hollis
- Inès Moreau Editor Editor
@ines
- Kofi Mensah Viewer Viewer
@kofi
Click Edit on different members to see the shared popover glide.
Purpose
A popover opens a small panel beside the control that triggered it. It’s useful for short explanations, quick settings, or a small set of actions.
Parts & Composition
Put PopoverTrigger and PopoverContent inside Popover. Use header, body, and footer parts for structured sections. Add a PopoverTitle for the accessible name and a PopoverClose to provide a dismiss action.
API & Props
| Part / Prop | Purpose |
|---|---|
Popover | Root provider (open, defaultOpen, onOpenChange, controller, modal, hover delays, dismissible, onDismissAttempt, onPayloadChange, size: xs | sm | md | lg (default md, inherited by trigger and content), presentation: auto | popover | sheet) |
PopoverTrigger | Button trigger styled via buttonVariants({ variant, size }) (defaults to variant="secondary", inherits size from Popover) |
PopoverContent | Top-layer popup/sheet (size: inherits Popover size, scales width, inherited text, and region insets, arrow default false, mobileTitle, mobileCloseLabel, side, sideOffset, align, alignOffset, collisionPadding, initialFocus, finalFocus, anchor, container, keepMounted) |
PopoverHeader, PopoverTitle, PopoverDescription, PopoverBody, PopoverFooter, PopoverClose | Structured header (separator default false), accessible name/description, scrollable body, footer (separator default true), and dismiss button |
PopoverArrow | Curved pointer SVG (pass arrow on PopoverContent or compose manually; automatically hidden in sheet presentation) |
PopoverList, PopoverAction, PopoverShortcut | Action list with slidingHighlight (default true), native button rows, and keycap hints |
createPopoverController() | Programmatic shared-popover and multi-trigger control |
Common props in detail
| Prop | Purpose |
|---|---|
open / defaultOpen / onOpenChange | Control or initialize visibility independently of the body’s state. |
presentation | Defaults to "auto". Set "popover" for an anchored popover or "sheet" for a bottom sheet. |
PopoverContent.keepMounted | Keep the content mounted across closing when its own state should persist. |
Interaction states
| State | Behavior |
|---|---|
| Open / Close | data-[presentation=popover] transitions opacity, scale (0.95 -> 1 -> 0.98), and blur (3px) over 200ms; shared controller popovers animate left/top between anchors. |
Hover / Focus (PopoverList) | useSlidingHighlight glides the shared slidingHighlight (bg-primary/10) across enabled [data-popover-action] / [data-highlight-item] elements; slidingHighlight={false} falls back to bg-accent. |
| Focus | PopoverAction applies focus-visible:ring-3 focus-visible:ring-ring/30; PopoverTrigger inherits Button focusRing. |
| Disabled | disabled / data-disabled sets opacity-45 and pointer-events-none on PopoverAction. |
Theming, Layout & Responsiveness
Uses shadcn semantic tokens (popover, popover-foreground, foreground, accent, accent-foreground, muted, muted-foreground, border, ring) across light, dark, and custom themes.
| Attribute | Meaning |
|---|---|
--surface-padding | Uses the same scale as Card (xs 1rem, sm 1.25rem, md 1.5rem, lg 1.75rem). Inherited by PopoverHeader, PopoverBody (surfaceBodyPadding), and PopoverFooter via surfaceRegionInset. |
data-presentation="popover" | "sheet" | Switches between anchored popover and mobile bottom sheet (max-h-[85dvh], safe-area bottom padding, optional mobileTitle header). |
data-side="top" | "bottom" | "left" | "right" | Rotates PopoverArrow automatically to face the anchor. |
data-sliding-highlight | Present on PopoverList when the sliding highlight overlay is active. |
PopoverAction heights align with Button (xs 28px, sm 32px, md 40px, lg 48px) and enforce min-h-11 (44px) on @media(pointer:coarse) touch devices with touch-manipulation. presentation defaults to "auto", switching to a bottom sheet on small touch screens ([--sheet-backdrop:rgb(0_0_0/0.4)]). PopoverContent and PopoverBody use thin border-colored scrollbars ([scrollbar-width:thin]).
Motion & Accessibility
Use PopoverTitle and PopoverDescription inside PopoverContent to supply aria-labelledby and aria-describedby. PopoverAction keeps standard <button> semantics and Tab order while PopoverList renders decorative highlight feedback only (aria-hidden="true"). Give icon-only PopoverTrigger or PopoverClose buttons an explicit aria-label.
Guidance for Coding Agents
Install Popover with the command on the Install tab. Read this Info page and the linked UI SDK reference before implementing.
Use Popover for short, anchored content or controls. Compose the header, body, footer, and close parts as needed. Set responsive presentation on the root and leave placement, dismissal, and focus to the primitive.
Set presentation on the root and size on the trigger or content, and pass mobileTitle on PopoverContent so touch-sheet users see a clear title and close button. Pass variant and size directly to the trigger and close parts so each action has one interactive element.
Start from the closest Preview → Usage example and use this page’s API table for component parts and options. For inherited props, callbacks, keyboard behavior, and rendering options, consult UI SDK Popover.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/popover'use client';
import type { PopoverOptions } from '@ui-sdk/core/popover';
import {
createPopoverController,
type PopoverContentState,
type PopoverController,
Popover as SDKPopover,
PopoverArrow as SDKPopoverArrow,
PopoverClose as SDKPopoverClose,
PopoverContent as SDKPopoverContent,
PopoverDescription as SDKPopoverDescription,
PopoverShortcut as SDKPopoverShortcut,
PopoverTitle as SDKPopoverTitle,
PopoverTrigger as SDKPopoverTrigger,
} from '@ui-sdk/react/popover';
import { mergeProps } from '@ui-sdk/react/primitive';
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 { useSlidingHighlight } from '@/hooks/use-sliding-highlight';
import {
compactControlMinHeights,
concentricRadius,
controlTextSizes,
partClass,
type StandardControlSize,
slidingHighlight as slidingHighlightClass,
surfaceBodyPadding,
surfaceFooterRadius,
surfaceHeaderRadius,
surfacePadding,
surfaceRegionInset,
} from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
type PopoverProps = PopoverOptions & {
children?: ReactNode;
size?: StandardControlSize;
};
const SharedPopoverContext = createContext(false);
const PopoverSizeContext = createContext<StandardControlSize>('md');
const popoverContentBase = cva(
[
'not-prose relative isolate flex min-h-0 max-w-[min(var(--available-width,100vw),calc(100vw-1.5rem))] max-h-(--available-height) flex-col rounded-lg border border-border bg-popover text-popover-foreground outline-none shadow-sm origin-(--transform-origin) [scrollbar-width:thin] [scrollbar-color:var(--border)_transparent]',
surfacePadding,
'data-[presentation=popover]:transition-[opacity,scale,filter] data-[presentation=popover]:duration-200 data-[presentation=popover]:ease-out data-[presentation=popover]:data-starting-style:opacity-0 data-[presentation=popover]:data-ending-style:opacity-0 motion-safe:data-[presentation=popover]:data-starting-style:scale-95 motion-safe:data-[presentation=popover]:data-starting-style:blur-[3px] motion-safe:data-[presentation=popover]:data-ending-style:scale-[0.98] motion-safe:data-[presentation=popover]:data-ending-style:blur-[3px] motion-reduce:data-[presentation=popover]:transition-none',
],
{
variants: {
size: {
xs: ['w-64 [--surface-padding:1.3rem]', controlTextSizes.xs],
sm: ['w-72 [--surface-padding:1.35rem]', controlTextSizes.sm],
md: ['w-80', controlTextSizes.md],
lg: ['w-96 [--surface-padding:1.75rem]', controlTextSizes.lg],
},
},
},
);
const popoverActionClasses = `group/popover-action relative flex w-full min-w-0 items-center justify-start gap-3 ${concentricRadius} px-3 text-start text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground group-data-sliding-highlight/popover-list:hover:bg-transparent group-data-sliding-highlight/popover-list:focus-visible:bg-transparent [@media(pointer:coarse)]:min-h-11 disabled:pointer-events-none disabled:opacity-45 data-disabled:pointer-events-none data-disabled:opacity-45 motion-reduce:transition-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`;
function Popover({ presentation = 'auto', size = 'md', controller, ...props }: PopoverProps) {
return (
<PopoverSizeContext value={size}>
<SharedPopoverContext value={controller != null}>
<SDKPopover {...props} controller={controller} presentation={presentation} />
</SharedPopoverContext>
</PopoverSizeContext>
);
}
type PopoverTriggerProps = ComponentProps<typeof SDKPopoverTrigger> & {
variant?: ButtonProps['variant'];
size?: ButtonProps['size'];
};
function PopoverTrigger({ variant = 'secondary', size, className, ...props }: PopoverTriggerProps) {
const contextSize = useContext(PopoverSizeContext);
const triggerSize = size ?? contextSize;
return (
<SDKPopoverTrigger
{...props}
data-size={triggerSize}
data-variant={variant}
className={partClass(buttonVariants({ variant, size: triggerSize }), className)}
/>
);
}
type PopoverContentProps<Payload = unknown> = ComponentProps<typeof SDKPopoverContent<Payload>> & {
arrow?: boolean;
size?: StandardControlSize;
mobileTitle?: ReactNode;
mobileCloseLabel?: string;
};
function PopoverContent<Payload = unknown>({
side = 'bottom',
sideOffset = 12,
align = 'center',
collisionPadding = 12,
arrow = false,
size,
mobileTitle,
mobileCloseLabel = 'Close popover',
className,
children,
...props
}: PopoverContentProps<Payload>) {
const shared = useContext(SharedPopoverContext);
const contextSize = useContext(PopoverSizeContext);
const contentSize = size ?? contextSize;
return (
<SDKPopoverContent
{...props}
side={side}
sideOffset={sideOffset}
align={align}
collisionPadding={collisionPadding}
data-size={contentSize}
className={partClass(
cn(
popoverContentBase({ size: contentSize }),
'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(var(--surface-padding,1rem),env(safe-area-inset-bottom))] [--sheet-backdrop:rgb(0_0_0/0.4)]',
shared &&
'motion-safe:data-[presentation=popover]:data-open:not-data-starting-style:transition-[left,top,opacity,scale,filter]',
),
className,
)}
>
{(state) => (
<>
{state.presentation === 'sheet' && mobileTitle != null && (
<PopoverHeader>
<PopoverTitle>{mobileTitle}</PopoverTitle>
<PopoverClose aria-label={mobileCloseLabel} />
</PopoverHeader>
)}
{arrow && state.presentation === 'popover' && <PopoverArrow />}
{typeof children === 'function' ? children(state) : children}
</>
)}
</SDKPopoverContent>
);
}
type PopoverCloseProps = ComponentProps<typeof SDKPopoverClose> & {
variant?: ButtonProps['variant'];
size?: ButtonProps['size'];
};
const closeIcon = <X aria-hidden="true" />;
function PopoverClose({
children,
variant = 'ghost',
size = 'icon-xs',
className,
'aria-label': label = children == null ? 'Close popover' : undefined,
...props
}: PopoverCloseProps) {
const isCornerClose = children == null && props.render === undefined;
return (
<SDKPopoverClose
{...props}
aria-label={label}
data-size={size}
data-variant={variant}
className={partClass(
cn(
buttonVariants({ variant, size: size }),
isCornerClose &&
'absolute end-2.5 top-2.5 z-10 text-muted-foreground hover:text-foreground',
),
className,
)}
>
{children ?? closeIcon}
</SDKPopoverClose>
);
}
function PopoverArrow({ className, children, ...props }: ComponentProps<typeof SDKPopoverArrow>) {
return (
<SDKPopoverArrow
aria-hidden="true"
{...props}
className={partClass(
'group/popover-arrow pointer-events-none size-2.5 text-popover data-[side=top]:-bottom-2.5 data-[side=bottom]:-top-2.5 data-[side=left]:-right-2.5 data-[side=right]:-left-2.5 in-data-[presentation=sheet]:hidden',
className,
)}
>
{children ?? (
<svg
aria-hidden="true"
viewBox="0 0 24 10"
className="absolute top-1/2 left-1/2 h-full w-5 max-w-none -translate-x-1/2 -translate-y-1/2 overflow-visible group-data-[side=bottom]/popover-arrow:rotate-180 group-data-[side=left]/popover-arrow:-rotate-90 group-data-[side=right]/popover-arrow:rotate-90"
focusable="false"
>
<path d="M0 -1H24V0C17 0 16 9 12 9S7 0 0 0Z" fill="currentColor" />
<path
d="M0 0C7 0 8 9 12 9S17 0 24 0"
fill="none"
className="stroke-border"
strokeWidth="1"
/>
</svg>
)}
</SDKPopoverArrow>
);
}
function PopoverHeader({
separator = false,
className,
children,
...props
}: ComponentProps<'div'> & { separator?: boolean }) {
return (
<div
{...props}
data-slot="popover-header"
className={cn(
'relative [&.sticky]:top-0',
surfaceHeaderRadius,
surfaceRegionInset,
'flex shrink-0 flex-col gap-1 has-[>[data-slot=popover-close]]:pe-10',
className,
)}
>
{children}
{separator ? <Separator className="absolute inset-x-0 bottom-0 w-auto" /> : null}
</div>
);
}
function PopoverTitle({ className, ...props }: ComponentProps<typeof SDKPopoverTitle>) {
return (
<SDKPopoverTitle
{...props}
data-slot="popover-title"
className={partClass('m-0 text-sm font-semibold leading-snug tracking-tight', className)}
/>
);
}
function PopoverDescription({ className, ...props }: ComponentProps<typeof SDKPopoverDescription>) {
return (
<SDKPopoverDescription
{...props}
data-slot="popover-description"
className={partClass('m-0 text-sm leading-relaxed text-muted-foreground', className)}
/>
);
}
/** Extend the scroll viewport to the divider inset; keep content padding inside it. */
function PopoverBody({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="popover-body"
className={cn(
surfaceRegionInset,
surfaceBodyPadding,
'scroll-fade min-h-0 overflow-y-auto overscroll-contain [scrollbar-width:thin] [scrollbar-color:var(--border)_transparent]',
className,
)}
/>
);
}
function PopoverFooter({
separator = true,
className,
children,
...props
}: ComponentProps<'div'> & { separator?: boolean }) {
return (
<div
{...props}
data-slot="popover-footer"
className={cn(
'relative [&.sticky]:bottom-0',
surfaceFooterRadius,
surfaceRegionInset,
'flex shrink-0 flex-wrap items-center gap-2',
className,
)}
>
{separator ? <Separator className="absolute inset-x-0 top-0 w-auto" /> : null}
{children}
</div>
);
}
/** Decorative feedback only: actions keep ordinary button and Tab semantics. */
function PopoverList({
slidingHighlight = true,
className,
children,
ref,
...props
}: ComponentProps<'div'> & { slidingHighlight?: boolean }) {
const { containerRef, highlightStyle } = useSlidingHighlight({
itemSelector:
':is([data-popover-action],[data-highlight-item]):not(:disabled):not([data-disabled]):not([aria-disabled=true])',
disabled: !slidingHighlight,
});
const listRef = useMemo(() => {
if (!slidingHighlight) return ref;
return ref ? mergeProps({ ref: containerRef }, { ref }).ref : containerRef;
}, [containerRef, ref, slidingHighlight]);
return (
<div
{...props}
ref={listRef}
data-slot="popover-list"
data-sliding-highlight={slidingHighlight ? '' : undefined}
className={cn('group/popover-list relative isolate flex flex-col gap-1', className)}
>
{slidingHighlight && (
<span aria-hidden="true" style={highlightStyle} className={slidingHighlightClass} />
)}
{children}
</div>
);
}
function PopoverAction({
className,
variant = 'ghost',
type = 'button',
...props
}: ComponentProps<typeof Button>) {
return (
<Button
{...props}
type={type}
variant={variant}
data-popover-action=""
className={cn(popoverActionClasses, className)}
/>
);
}
function PopoverShortcut({ className, ...props }: ComponentProps<typeof SDKPopoverShortcut>) {
return (
<SDKPopoverShortcut
{...props}
data-slot="popover-shortcut"
className={partClass(
compactControlMinHeights.sm,
'ms-auto inline-flex min-w-6 items-center justify-center rounded-lg border border-border/60 bg-muted/60 px-1.5 font-sans text-xs text-muted-foreground',
className,
)}
/>
);
}
export {
createPopoverController,
Popover,
PopoverAction,
PopoverArrow,
PopoverBody,
PopoverClose,
PopoverContent,
type PopoverContentState,
type PopoverController,
PopoverDescription,
PopoverFooter,
PopoverHeader,
PopoverList,
PopoverShortcut,
PopoverTitle,
PopoverTrigger,
};
import type { ButtonOptions } from '@ui-sdk/core/button';
import { Button as ButtonPrimitive } from '@ui-sdk/react/button';
import { cva, type VariantProps } from 'class-variance-authority';
import { Loader2 } from 'lucide-react';
import type { ComponentProps, ReactNode } from 'react';
import { controlHeights, controlTextSizes, focusRing } from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
/*
* Clean tactile button surfaces with a subtle top highlight, contact shadow,
* and 2% press scale using pure Tailwind/theme tokens.
*/
const flatPress = 'motion-safe:not-data-disabled:not-data-pending:active:scale-[0.985]';
const activeInsetShadow =
'active:shadow-[inset_0_1px_3px_rgb(0_0_0/0.12),0_1px_2px_rgb(0_0_0/0.06)] dark:active:shadow-[inset_0_1px_3px_rgb(0_0_0/0.18),0_1px_2px_rgb(0_0_0/0.1)]';
const tactileFilled =
'bg-[linear-gradient(180deg,rgb(255_255_255/0.16),rgb(255_255_255/0)_75%)] shadow-[inset_0_1.5px_0_rgb(255_255_255/0.22),inset_0_-1px_0_rgb(0_0_0/0.12),0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)] active:shadow-[inset_0_1px_3px_rgb(0_0_0/0.18),0_1px_2px_rgb(0_0_0/0.1)]';
const tactileNeutral = `bg-[linear-gradient(180deg,rgb(255_255_255/0.35),transparent_48%,rgb(0_0_0/0.025)_100%)] shadow-[inset_0_1px_0_rgb(255_255_255/0.65),inset_0_-1px_0_rgb(0_0_0/0.06),0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)] dark:bg-[linear-gradient(180deg,rgb(255_255_255/0.06),transparent_48%,rgb(0_0_0/0.12)_100%)] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.1),inset_0_-1px_0_rgb(0_0_0/0.12),0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)] ${activeInsetShadow}`;
/** Surface map for button variants, shared with Toggle, Tabs, Radio, Checkbox, and Switch. */
const buttonSurfaces = {
primary: `border-[color-mix(in_oklch,var(--primary),black_8%)] bg-primary text-primary-foreground ${tactileFilled} ${flatPress}`,
secondary: ` bg-popover text-popover-foreground border-[color-mix(in_oklch,var(--muted),black_5%)] ${tactileNeutral} ${flatPress}`,
outline: `border-input bg-accent/10 text-foreground shadow-sm hover:text-accent-foreground ${activeInsetShadow} ${flatPress}`,
ghost: `border-transparent text-foreground hover:bg-muted ${activeInsetShadow} ${flatPress}`,
destructive: `border-[color-mix(in_oklch,var(--destructive),black_8%)] bg-destructive text-[color:var(--destructive-foreground,white)] ${tactileFilled} ${flatPress}`,
tertiary: `border-transparent bg-accent text-accent-foreground ${activeInsetShadow} ${flatPress}`,
'destructive-soft': `border-transparent bg-destructive/10 text-destructive dark:bg-destructive/20 ${activeInsetShadow} ${flatPress}`,
link: 'border-transparent text-primary underline-offset-4 hover:underline',
} as const;
type ButtonVariant = keyof typeof buttonSurfaces;
const buttonBase = cva(
[
// layout
'group/button relative isolate inline-flex shrink-0 items-center justify-center whitespace-nowrap rounded-lg border text-sm font-medium',
// interaction
'cursor-pointer select-none touch-manipulation',
'transition-[background-color,border-color,box-shadow,translate,scale,filter] duration-150 ease-out motion-reduce:transition-none',
focusRing,
// 44px touch target on coarse pointers without changing the visual size
'[@media(pointer:coarse)]:after:absolute [@media(pointer:coarse)]:after:inset-1/2 [@media(pointer:coarse)]:after:min-h-11 [@media(pointer:coarse)]:after:min-w-11 [@media(pointer:coarse)]:after:-translate-1/2',
// states
'disabled:cursor-not-allowed aria-disabled:opacity-50 data-disabled:cursor-not-allowed data-disabled:opacity-50 data-pending:cursor-wait',
// icons
"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-(--icon-size,1rem) [&>span:has(>svg):not([class*='size-'])]:size-(--icon-size,1rem)",
],
{
variants: {
size: {
md: `${controlHeights.md} ${controlTextSizes.md} gap-2 px-4 [--icon-size:1.2rem]`,
xs: `${controlHeights.xs} ${controlTextSizes.xs} gap-1 px-2.5 [--icon-size:0.875rem]`,
sm: `${controlHeights.sm} ${controlTextSizes.sm} gap-1.5 px-3 [--icon-size:1rem]`,
lg: `${controlHeights.lg} ${controlTextSizes.lg} gap-2 px-6 [--icon-size:1.25rem]`,
icon: `${controlHeights.md} aspect-square [--icon-size:1.2rem]`,
'icon-xs': `${controlHeights.xs} aspect-square [--icon-size:0.875rem]`,
'icon-sm': `${controlHeights.sm} aspect-square [--icon-size:1rem]`,
'icon-lg': `${controlHeights.lg} aspect-square [--icon-size:1.25rem]`,
},
},
defaultVariants: { size: 'md' },
},
);
type ButtonVariantProps = VariantProps<typeof buttonBase> & {
variant?: ButtonVariant;
};
function buttonVariants({
variant = 'primary',
size,
className,
}: ButtonVariantProps & { className?: string } = {}) {
return cn(buttonBase({ size }), buttonSurfaces[variant], className);
}
type ButtonProps = Omit<
ComponentProps<typeof ButtonPrimitive>,
keyof ButtonOptions | 'className' | 'children'
> &
ButtonOptions &
ButtonVariantProps & {
children?: ReactNode;
className?: string;
/** Prevent repeated activation and display an inline spinner without replacing the label. */
loading?: boolean;
};
const spinner = (
<Loader2
aria-hidden="true"
data-slot="spinner"
className="hidden size-(--icon-size,1rem) animate-spin in-data-pending:inline-block in-data-loading:inline-block motion-reduce:animate-none"
/>
);
function Button({
className,
variant = 'primary',
size = 'md',
loading = false,
disabled,
children,
'aria-busy': ariaBusy,
...props
}: ButtonProps) {
return (
<ButtonPrimitive
{...props}
className={buttonVariants({ variant, size, className })}
data-size={size}
data-variant={variant}
data-loading={loading || undefined}
disabled={disabled || loading}
aria-busy={loading || ariaBusy}
>
{spinner}
{children}
</ButtonPrimitive>
);
}
export { Button, type ButtonProps, type ButtonVariant, buttonSurfaces, buttonVariants };
import { Separator as SDKSeparator } from '@ui-sdk/react/separator';
import type { ComponentProps } from 'react';
import { partClass } from '@/lib/devvarena-ui';
type SeparatorProps = ComponentProps<typeof SDKSeparator> & { variant?: 'fade' | 'solid' };
/** Theme-derived fading rule built on `@ui-sdk/react/separator`. */
function Separator({
orientation = 'horizontal',
decorative = true,
variant = 'fade',
className,
...props
}: SeparatorProps) {
return (
<SDKSeparator
{...props}
orientation={orientation}
decorative={decorative}
data-variant={variant}
className={partClass(
'pointer-events-none shrink-0',
orientation === 'horizontal' ? 'h-px w-full' : 'w-px self-stretch',
variant === 'solid'
? 'bg-[var(--separator-color,var(--border))]'
: orientation === 'horizontal'
? 'bg-[linear-gradient(to_right,transparent,var(--separator-color,var(--border))_18%,var(--separator-color,var(--border))_82%,transparent)]'
: 'bg-[linear-gradient(to_bottom,transparent,var(--separator-color,var(--border))_18%,var(--separator-color,var(--border))_82%,transparent)]',
className,
)}
/>
);
}
export type { SeparatorProps };
export { Separator };
'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';