Skip to content

@xtandard/kit/ui

@xtandard/kit/ui — the shared admin shell of the xtandard products, as compiled React components and helpers (ADR 0008):

  • primitives (ToggleSwitch, Segmented, Dropdown, CreatableCombobox, TextInput, TextArea), Button/Badge/Avatar/Kbd, toasts and the theme toggle;
  • the theme store (createThemeStore, keyed per product), host-theme detection and ThemeProvider/useTheme;
  • createApiClient (the panel API client core) and takeTokenFromUrl;
  • bootSpa (the SPA’s main.tsx), ShellFrame + useShellConfig + useShellNav;
  • the common bits (Spinner, PageHeader, ModalDialog, Drawer, CopyButton, …), the format helpers and BrandMark.

Pair it with @xtandard/kit/ui/styles.css. Product seams (theme key, config global, scope class, error class, brand tokens) are parameters.

Optional peers: react, react-dom, @base-ui-components/react, lucide-react, wouter, @tanstack/react-query, clsx, tailwind-merge.

import { … } from "@xtandard/kit/ui";
Name Summary
Avatar
Badge
bootSpa Boot the standalone admin SPA. Call once from the product’s main.tsx.
BrandMark A product’s symbol, inlined as a data URL (pass the SVG markup) so it works inside the embed with no asset to serve. Inside a ThemeProvider it renders the variant for the resolved theme; outside one it renders both and lets the dark: variant pick.
canLeave Consult the active blocker. true when navigation may proceed.
clearNavBlocker Clear blocker if it is still the active one (safe from stale cleanups).
cn Merge class names with Tailwind-aware de-duplication.
ConfigError The default message for a /config failure (pass it as ShellFrameProps.fallback).
ConfirmDialog A ModalDialog with Cancel / confirm buttons (danger for destructive actions).
CopyButton An icon button that copies text to the clipboard with a brief check-mark. A denied clipboard shows an error toast; toastMessage also toasts on success.
CreatableCombobox A single-select combobox that lets you pick an existing option or type a new one — when the typed text matches nothing, a “Create …” item appears and selecting it calls onCreate. Used for the project/environment switchers.
createApiClient Create one product’s API client. errorClass is the product’s error class (it receives (status, body)); it defaults to ApiError.
createShellQueryClient A QueryClient with the shell’s defaults: one retry, no refetch on window focus.
createThemeStore Create the theme store for one product. storageKey is the product’s localStorage key ("xtandard-webhooks:theme"…); it is a stored-data contract, so products pass it explicitly.
detectHostTheme The host page’s theme, for theme="inherit": an explicit signal on <html> (then <body>) — a dark/light class, a data-theme/data-mode/data-color-scheme attribute, or an inline color-scheme — and, only when the host sets none, the OS prefers-color-scheme.
Drawer A right-hand sheet for details and long forms.
Dropdown A select (Base UI Select) whose popup portals into the embed wrapper when there is one.
EmptyCard A dashed placeholder card for empty lists, with an optional icon and call to action.
formatCompact Compact number for tight spaces (950, 1.2K, 34K, 1.5M, 2B).
formatCount A whole number with grouping (12,345); rounds fractions.
formatDate Short date, locale-aware ("Nov 21, 2026").
formatDateTime Absolute date-time, locale-aware ("Nov 21, 2026, 03:04 PM").
formatDurationMs A duration in milliseconds: "87 ms" below a second, "1.25 s" above.
formatNumber A number with grouping and up to maxFractionDigits decimals (1,234.5).
initials Up to two initials for an avatar: "Ada Lovelace" → "AL", "[email protected]" → "AL" (the email domain is ignored), "?" when nothing is left.
Kbd
LoadingRow A centred spinner with a label, for a view that is still loading.
ModalDialog A centred modal (Base UI Dialog), portaled into the embed wrapper when there is one.
Mono Keys/ids render in the mono face per the design system.
Page Page wrapper with the shared max width and gutters (wide for tables and charts).
PageHeader A view’s title row: heading, optional description and right-aligned actions.
portalContainerRef The current portal container ref, or undefined when none is set (Base UI then defaults to document.body). Pass the result to a Base UI *.Portal container={…} prop.
readConfigGlobal Read the bootstrap config the panel handler injects as window[configGlobal] ("__WEBHOOKS_CONFIG__"…). {} when it is missing (dev server, embed, SSR).
relativeTime Compact relative time: "just now", "5m ago", "in 2h", "3d ago", "2mo ago", "1y ago". Values are floored, so "1h ago" means at least one full hour. now is injectable for tests.
resolveTheme The concrete theme a preference resolves to right now.
SectionCard A bordered card with a titled header row and a padded body. A string title also labels the <section> (aria-label), so the card is a named region in the accessibility tree.
Segmented A segmented control (Base UI ToggleGroup) for a small set of exclusive options.
setNavBlocker Register the current blocker (replaces any previous one).
setPortalContainerRef Point portals at ref (the embed wrapper). Pass undefined to reset to the body default.
ShellFrame The shared admin chrome: sticky header (brand, switcher, badges, toggle), tabs and content.
Spinner A 16px spinning ring in the current text colour.
StatCard A KPI tile: uppercase label, a large tabular value, an optional hint and icon.
subscribeHostTheme Watch the host page for theme switches: class/attribute/style changes on <html> and <body>, plus the OS scheme. Returns the unsubscribe function. Without a DOM or MutationObserver (SSR, old test environments) it only follows the OS scheme.
subscribeSystemTheme Call cb when the OS colour scheme flips. Returns the unsubscribe function.
svgDataUrl An SVG document as a data: URL, so the SPA and the embed render it without serving an asset.
systemTheme The OS colour scheme right now (light when it can’t be read, e.g. on the server).
takeTokenFromUrl Read a portal token from #token= (preferred) or ?token=, and strip it from the URL through replace (e.g. (url) => history.replaceState(null, "", url)). Other query and hash parameters are kept. Returns the token, or null when the URL carries none (nothing is replaced then).
ThemeProvider Provide the resolved theme (and the store, for ThemeToggle) to the subtree.
ThemeToggle The system/light/dark switcher. It persists the choice in the product’s theme store (the store prop, else the enclosing ThemeProvider’s).
ToastProvider Hosts the toast stack (inside the embed wrapper, so it gets the scoped styles and theme).
ToggleSwitch
toQuery Build a query string ("?a=1&b=2", or "" when nothing is left), skipping undefined, null and "". Arrays are comma-joined (and skipped when empty); booleans become "true"/"false".
truncate Truncate with an ellipsis; never longer than max characters (including the ellipsis).
useResolvedTheme Resolve a ThemeMode against store, re-rendering on every relevant change.
useShellConfig The /config query plus the shell’s derived state, with both portal-race fixes: admin work waits for /config (ready/adminReady), and a token means portal from the first render.
useShellNav In-app navigation for the shell: go(path, params?) consults the nav guard (a view with unsaved edits can veto the move), carries the sticky params over, then applies params ("" removes one).
useTheme The active theme. Outside a ThemeProvider it follows the OS scheme and reports no toggle (there is no store to persist a choice in).
useToast add(kind, message, detail?) for the nearest ToastProvider; throws outside one.
Name Summary
ApiError Thrown by the client for non-2xx responses. Products subclass it (WebhooksApiError…).
Name Summary
ApiClient One product’s API client.
ApiClientOptions Options for ApiClient.setApiBase.
ApiErrorBody The JSON error body the panel API returns, with the HTTP status always filled in.
BootedSpa What bootSpa returns.
BootSpaOptions Options for bootSpa.
BrandMarkProps Props for BrandMark.
ButtonProps Props for Button.
CreateApiClientOptions Options for createApiClient.
DropdownOption
FormatDateTimeOptions Options for formatDateTime.
SegmentOption
ShellAppProps The props bootSpa (and createEmbed) pass to the product’s App.
ShellConfigBase The /config fields the shell reads. Products extend it with their own.
ShellConfigState What useShellConfig returns.
ShellFrameProps Props for ShellFrame.
ShellTab One navigation tab.
ThemeProviderProps Props for ThemeProvider.
ThemeSignalSource The bits of an element detectHostTheme reads (keeps it testable without a DOM).
ThemeState What useTheme returns.
ThemeStore A persisted theme preference, bound to one localStorage key.
ThemeToggleProps Props for ThemeToggle.
Toast One toast in the stack.
ToastContextValue
UseShellConfigOptions Options for useShellConfig.
UseShellNavOptions Options for useShellNav.
Name Summary
ApiErrorConstructor A constructor for the error the client throws (an ApiError subclass, or compatible).
Blocker Returns true if navigation is allowed, false to block it (e.g. user cancelled).
ButtonSize
ButtonVariant
FetchLike The subset of fetch the client uses (the global fetch satisfies it).
QueryValue A query-string value accepted by toQuery.
ResolvedTheme A concrete theme — what every surface, text color and viewer resolves to.
ThemeMode How the dashboard’s theme is decided: - "auto" — its own system/light/dark preference (persisted), with the toggle. - "inherit" — follow the host page (see detectHostTheme); no toggle. - "light" / "dark" — fixed by the host (e.g. from its own theme state); no toggle.
ThemePref A theme preference: system follows the OS.
ToastKind The tone of a toast.
Name Summary
Button The shell’s button: primary / secondary / ghost / danger variants, sizes, a loading spinner.
TextArea
TextInput