Pyric
Navigate

API reference

@pyric/ui/primitives

31 published symbols from @pyric/ui

Generated from the TypeScript declarations shipped at this import path.

Interfaces

BadgeProps

Properties

PropertyTypeDescription
ariaLabel?stringAccessible label. When set, the visible text becomes aria-hidden and screen readers announce this instead — useful when the badge is a terse glyph but the meaning is longer.
childrenReactNodeBadge content — usually a short word like “ALLOW” or “GET”.
className?stringForwarded to the underlying <span>.
kind?stringFreeform category surfaced as data-pyric-badge-kind. The library doesn’t enumerate kinds — the consumer decides what values exist (allow, deny, get, update, …) and styles them via [data-pyric-badge-kind="…"].

ConfirmDialogProps

Properties

PropertyTypeDescription
body?ReactNodeBody content — explanation, consequences, paths affected.
cancelLabel?string-
className?stringForwarded to the content node so consumers can style.
confirmLabel?string-
destructive?booleanWhen true, the confirm button carries data-pyric-destructive so consumers can style it differently (e.g. red).
onConfirm() => voidFires when the user presses confirm. The component does NOT close itself on confirm — the consumer typically dismisses after the destructive action resolves.
onOpenChange(open: boolean) => voidCalled when the user dismisses via overlay click, Escape, or the cancel button. NOT called by onConfirm.
openbooleanControlled open state.
titlestringHeading.

ConfirmOptions

Properties

PropertyType
body?ReactNode
cancelLabel?string
confirmLabel?string
destructive?boolean
titlestring

ConfirmProviderProps

Properties

PropertyTypeDescription
childrenReactNode-
dialogClassName?stringForwarded to the rendered <ConfirmDialog>.

CopyButtonProps

Properties

PropertyTypeDescription
ariaLabel?stringForwarded as the button’s accessible label when in the idle state. Defaults to “Copy to clipboard”. The copied state uses a hard-coded “Copied” label so screen readers announce the state change consistently.
children?ReactNodeOptional content to render inside the button. Defaults to a short text label that toggles between “Copy” and “Copied”.
className?stringForwarded to the underlying <button>. Consumers compose Tailwind classes, CSS-module classes, or whatever they want.
resetMs?numberMilliseconds before the data-copied state attribute clears. Defaults to 2000.
textstringText to copy to the clipboard on click.

JsonViewProps

Properties

PropertyTypeDescription
className?stringForwarded to the root container.
defaultCollapsedDepth?numberDepth at and below which object/array nodes start collapsed. 0 collapses the root, 1 collapses everything under the root, Infinity (default) leaves everything expanded.
valueunknownAny JSON-serializable value.

SegmentedControlProps

Type Parameters

Type Parameter
T extends string

Properties

PropertyTypeDescription
ariaLabel?stringAccessible label for the radiogroup.
className?stringForwarded to the container.
onChange(value: T) => voidFired with the new value when a segment is clicked.
optionsreadonly SegmentedOption<T>[]The selectable segments, rendered left-to-right.
valueTThe currently-selected value.

SegmentedOption

Type Parameters

Type Parameter
T extends string

Properties

PropertyTypeDescription
labelReactNodeVisible label.
tone?stringFreeform tone surfaced as data-pyric-segment-tone — e.g. ok / error so the consumer can tint the active label. The library doesn’t enumerate tones.
valueTThe value committed via onChange when this segment is picked.

ToastInput

Extended by

Properties

PropertyTypeDescription
body?ReactNode-
duration?numberAuto-dismiss after this many ms. 0 makes the toast sticky; default is 5000.
kind?ToastKind-
titlestring-

ToastProviderProps

Properties

PropertyTypeDescription
childrenReactNode-
className?stringForwarded to the rendered container.
defaultDuration?numberDefault auto-dismiss in ms. Per-toast duration overrides. Default 5000; pass 0 to make sticky-by-default.
regionLabel?stringRegion label for assistive tech. Defaults to “Notifications”.

ToastRecord

Extends

Properties

PropertyTypeDescription
body?ReactNode-
duration?numberAuto-dismiss after this many ms. 0 makes the toast sticky; default is 5000.
idstring-
kind?ToastKind-
titlestring-

UpdateHighlight

Properties

PropertyType
cycle0 | 1
kindUpdateHighlightKind

UseContainerSizeOptions

Properties

PropertyTypeDescription
mediumBreakpoint?numberWidth (px) below which the bucket is 'medium' (and above which it is 'wide'). Default 768.
narrowBreakpoint?numberWidth (px) below which the bucket is 'narrow'. Default 480.

UseUpdateHighlightsOptions

Type Parameters

Type Parameter
T

Properties

PropertyType
durationMs?number
entriesReadonlyMap<string, T>
equals?(previous: T, next: T) => boolean
ready?boolean
scopestring

VirtualListProps

Type Parameters

Type Parameter
T

Properties

PropertyTypeDescription
className?stringForwarded to the scroll container.
estimateSizenumber | (index: number) => numberEstimated row height in px. useVirtualizer measures actual rendered heights via ResizeObserver — this is just the guess used before measurement. Pass a function for variable sizing.
getItemKey?(item: T, index: number) => string | numberOptional key resolver. Defaults to the index. Use when rows reorder so React can preserve component state across moves.
height?string | numberHeight the scroll container fills. Default 100% — the consumer’s parent typically constrains height.
itemsreadonly T[]-
overscan?numberNumber of off-screen rows to render on each side. TanStack default is 5; bump for smoother fast scrolling.
renderItem(item: T, index: number) => ReactNodeRender one row. The library handles positioning + key-by-index.

Type Aliases

ConfirmFn()

type ConfirmFn = (options: ConfirmOptions) => Promise<boolean>;

Parameters

ParameterType
optionsConfirmOptions

Returns

Promise<boolean>


ContainerSize

type ContainerSize = "narrow" | "medium" | "wide";

ToastKind

type ToastKind = "info" | "success" | "warning" | "error";

UpdateHighlightKind

type UpdateHighlightKind = "added" | "modified";

Functions

Badge()

function Badge(__namedParameters: BadgeProps): Element;

Headless pill / tag. Renders an inline <span> carrying data-pyric-badge and (when kind is set) data-pyric-badge-kind so consumers can style categories with attribute selectors. Ships no visual styling of its own.

Parameters

ParameterType
__namedParametersBadgeProps

Returns

Element


ConfirmDialog()

function ConfirmDialog(__namedParameters: ConfirmDialogProps): ReactPortal;

Headless confirmation dialog. Hand-rolled (we evaluated Radix Dialog at M4 but Radix’s Presence + Portal stack doesn’t render under our bun:test + JSDOM env — see plan section 7 risk #1).

Provides:

  • Portal to document.body (so the dialog can escape parent stacking contexts)
  • Escape-to-close
  • Overlay click to close
  • ARIA role="dialog" aria-modal="true" wiring
  • Focus restoration to the previously-focused element on close
  • Initial focus on the confirm button when opening

Ships no visual CSS. Consumers style via the structural data-pyric-* attributes.

Parameters

ParameterType
__namedParametersConfirmDialogProps

Returns

ReactPortal


ConfirmProvider()

function ConfirmProvider(__namedParameters: ConfirmProviderProps): Element;

Mounts a single managed <ConfirmDialog> and exposes the imperative confirm() API through context. Scoped — multiple providers can coexist in different subtrees, each managing its own dialog.

Parameters

ParameterType
__namedParametersConfirmProviderProps

Returns

Element


CopyButton()

function CopyButton(__namedParameters: CopyButtonProps): Element;

Headless copy-to-clipboard button. Exposes its copied state via the data-copied attribute on the underlying <button> so consumers can style the success state with [data-copied] (or data-[copied]:bg-green-500 in Tailwind’s arbitrary-variant syntax). Ships no visual styling of its own.

Parameters

ParameterType
__namedParametersCopyButtonProps

Returns

Element


JsonView()

function JsonView(__namedParameters: JsonViewProps): Element;

Headless collapsible JSON tree. One structural step above a <pre> dump: object/array nodes are independently expandable, but there’s no editing and no syntax-color theme — just data-pyric-* hooks for the consumer to style.

Styling hooks:

  • [data-pyric-ui="json-view"] — root
  • [data-pyric-json-node] — every node, with data-pyric-json-type
  • [data-pyric-json-toggle] — the expand/collapse button (containers only)
  • [data-pyric-json-node][data-pyric-collapsed] — a collapsed container
  • [data-pyric-json-key] — the key/index label
  • [data-pyric-json-value] — a primitive value
  • [data-pyric-json-summary] — the {…} / […] placeholder when collapsed

Parameters

ParameterType
__namedParametersJsonViewProps

Returns

Element


SegmentedControl()

function SegmentedControl<T>(__namedParameters: SegmentedControlProps<T>): Element;

Headless segmented control — a single-select group of pill buttons that reads as one widget. Wired as an ARIA radiogroup.

Ships no visual styling. Consumers style via:

  • [data-pyric-ui="segmented-control"] — the container
  • [data-pyric-segment] — each option button
  • [data-pyric-segment][data-pyric-active] — the selected one
  • [data-pyric-segment-tone="…"] — tone-tinted options

Type Parameters

Type Parameter
T extends string

Parameters

ParameterType
__namedParametersSegmentedControlProps<T>

Returns

Element


ToastProvider()

function ToastProvider(__namedParameters: ToastProviderProps): Element;

Toast queue host. Mounts a single live region into document.body via portal and exposes the imperative API via context. Scoped — a subtree can host its own provider for isolated queues if needed.

Headless: every node carries structural data-* attributes, no shipped CSS. Auto-dismiss timers are kept per-toast.

Parameters

ParameterType
__namedParametersToastProviderProps

Returns

Element


useConfirm()

function useConfirm(): ConfirmFn;

Imperative confirmation hook. Returns a function that opens the provider-managed dialog and resolves to true on confirm, false on cancel/dismiss.

const confirm = useConfirm(); const ok = await confirm({ title: ‘Delete?’, destructive: true }); if (ok) await deleteDoc(ref);

Requires a <ConfirmProvider> ancestor.

Returns

ConfirmFn


useContainerSize()

function useContainerSize<T>(options?: UseContainerSizeOptions): {
  ref: RefObject<T>;
  size: ContainerSize;
};

Container-query helper. Returns the current size bucket ('narrow' | 'medium' | 'wide') of the element pointed at by the returned ref. Re-fires on resize via ResizeObserver.

const { ref, size } = useContainerSize(); return

;

Headless: the consumer styles via [data-size='narrow'] selectors. The library’s feature components use this hook to stamp their roots with data-size, which is the policy the survey’s modern-CSS subsection landed on (no viewport media queries, no library-side breakpoints — push the threshold decision to the consumer via data attributes).

Type Parameters

Type ParameterDefault type
T extends HTMLElementHTMLDivElement

Parameters

ParameterType
options?UseContainerSizeOptions

Returns

{
  ref: RefObject<T>;
  size: ContainerSize;
}
ref
ref: RefObject<T>;
size
size: ContainerSize;

useToast()

function useToast(): ToastContextValue;

Imperative toast hook. Returns { toast, dismiss, toasts }.

const { toast } = useToast(); toast({ title: ‘Saved.’, kind: ‘success’ });

Requires a <ToastProvider> ancestor.

Returns

ToastContextValue


useUpdateHighlights()

function useUpdateHighlights<T>(__namedParameters: UseUpdateHighlightsOptions<T>): ReadonlyMap<string, UpdateHighlight>;

Tracks transient additions and modifications between keyed snapshots. The first ready snapshot in each scope is a silent baseline.

Type Parameters

Type Parameter
T

Parameters

ParameterType
__namedParametersUseUpdateHighlightsOptions<T>

Returns

ReadonlyMap<string, UpdateHighlight>


VirtualList()

function VirtualList<T>(__namedParameters: VirtualListProps<T>): Element;

Thin wrapper around @tanstack/react-virtual. Renders a scrollable container with absolutely-positioned rows, drawing only the rows currently in view (plus overscan neighbors).

Headless — no shipped CSS beyond what’s structurally required to position rows (the inner spacer’s height + each row’s position: absolute; top: …px). Consumers style via the className prop and standard CSS targeting [data-pyric-ui= "virtual-list"] on the scroll container and [data-pyric-virtual-row] on each row.

Type Parameters

Type Parameter
T

Parameters

ParameterType
__namedParametersVirtualListProps<T>

Returns

Element