UI kit
The @spacemix/ui design system - what is promised, the conventions every component follows, the design tokens, the stable components, toasts and the dismiss stack, motion presets, and an index of the component pages.
@spacemix/ui (packages/ui/src, package version 0.1.0) is SpaceMIX's design system: components for views, layouts, forms, data, charts, navigation, feedback and overlays, motion presets, and the design tokens in tokens.css. The frame provides it at runtime (HOST_MODULES maps @spacemix/ui to the global __opUi) together with its styles, so your bundle doesn't carry it and your extension picks up the host's version. Use it, plus lucide-react for icons, instead of building your own controls.
What is promised: the exported names and their props, and the token names. What isn't: the exact classes, sizes and colors a component renders with. They follow the app's look and may change with it. Don't style an extension by targeting a component's internal classes.
See it live: in the app, the Design System page shows every export of the kit, every token and every motion preset working, with its props and a snippet to copy, plus full-page patterns built from the kit and the widget frame's op-* kit. Open it from Design System at the bottom of the server menu at the top left (on a phone, your avatar at the top right), or search for "Design System" (Ctrl/⌘ K). These pages stay the reference for what is promised.
The component pages
This page has the conventions, the tokens, the stable components and the behaviour every layer shares. Each group of components has its own page:
| Page | What is on it | Source |
|---|---|---|
| Layout | Page, Section, Container, Stack, HStack, VStack, Grid, Toolbar, Divider, Spacer, ScrollArea, SplitView, ListDetail, SidebarLayout, SidePanel, Panel, Inset, AspectRatio, Center, VisuallyHidden |
layout.tsx |
| Actions | IconButton, ButtonGroup, SegmentedControl, Toggle, CopyButton, Link |
components.tsx |
| Forms | Field, useField, Label, Textarea, Checkbox, CheckboxGroup, RadioGroup, Radio, Switch, Slider, NumberInput, SearchField, PasswordInput, TagInput, FileDrop, PinInput, ColorSwatchPicker, Fieldset, FormSection, FormActions |
forms.tsx |
| Pickers | Select, MultiSelect, Combobox, TimePicker, Calendar, DatePicker, DateRangePicker |
popovers.tsx |
| Data display | Badge, Tag, StatusDot, Avatar, AvatarGroup, Card, Stat, DescriptionList, Table, List, ListItem, Tree, Timeline, CodeBlock, InlineCode, Progress, ProgressCircle, Meter, Skeleton, Spinner, Highlight, RelativeTime, FileSize, NumberFormat, Board and the format helpers |
data.tsx, components.tsx |
| Charts | Sparkline, BarChart, LineChart, DonutChart, Heatmap, Gauge, ChartLegend, ChartTooltip |
charts.tsx |
| Navigation | Tabs, Breadcrumbs, Pagination, NavList, Stepper, Accordion, Disclosure, BackLink, AnchorNav |
navigation.tsx |
| Feedback | Alert, Callout, Banner, toast, Toaster, ToastProvider, ErrorState, LoadingState, NoResults, PermissionDenied, OfflineState, InlineMessage, ConfirmInline |
feedback.tsx |
| Overlays | Tooltip, Popover, HoverCard, DropdownMenu, Dialog, Drawer, Gallery, Lightbox, CommandMenu, CommandDialog, and the floating helpers useFloating, computePosition, Portal, PortalContainer, useDismiss |
popovers.tsx, floating.ts, host.ts |
Stability
The page as a whole is stable, and so is everything that was in the kit before this release: cx, Button, Input, Kbd, PageHeader, EmptyState, Markdown, ConfirmDialog, ContextMenu, MenuEntry, MenuAnchor, anchorFrom, RenameInput, the motion presets and the design tokens. ButtonVariant is new in this release (the type existed but wasn't exported) and is stable too, but it may gain members: code that switches over it must handle a value it doesn't know.
Everything on the component pages, Size, Tone and useControllableState are experimental: they are new in this release, and their names and props may still be adjusted before they are promised. The new props of the stable components are experimental for the same reason; each section below says which ones. The success, warning, info, -soft, c1–c6, scrim, sunk, control-border, accent-hover, accent-text, font-display, --op-shadow and --op-shadow-strength tokens are stable like the rest: token names don't change within protocol 1.
Conventions
Every component follows the same rules (packages/ui/src/types.ts), so a prop you know from one works the same on the next.
| Rule | What it means |
|---|---|
size |
Only ever takes Size: "sm" | "md" | "lg". "md" is the default and matches the app's controls. A length in pixels has its own name (diameter, height, cellSize), and spacing is gap or space. The one exception: Input and the fields built on it also take a number for the native size attribute. |
tone |
Takes Tone: "neutral" | "accent" | "success" | "warning" | "danger" | "info", for what a color means. |
color |
Only a chart series color (SeriesColor, "c1" to "c6", see Charts). A component takes tone or color, never both. |
variant |
For how a thing looks ("primary" | "secondary" | "ghost" and the like). There are no synonyms (intent, kind) for these ideas. |
| Controlled or not | Values take value / defaultValue / onChange(value); the callback gets the value, not the event (Input alone keeps the native event). Checkboxes and switches take checked / defaultChecked / onChange(checked), toggle buttons pressed / defaultPressed / onChange(pressed), and anything that opens open / defaultOpen / onOpenChange(open). onChange gets the type value has: a value that can be cleared is T | null in both. Leave value (or checked, pressed, open) out and the component keeps its own state from the default. |
| One name per idea | The same idea has the same prop name everywhere: loading for work in progress (the control spins and is disabled), empty for what shows when there is nothing to list, disabled, invalid, required, label and description. |
className |
Passed through and joined last, so you can add layout classes. Where a component has a default width, a width class in className (w-48, flex-1, basis-1/2) replaces it. |
ref |
An ordinary prop (React 19), forwarded to the root element unless the component's page says otherwise. |
| Native props | Where the root is a native element, its native props are spread onto it (ButtonHTMLAttributes for a button, InputHTMLAttributes for an input). |
| Keyboard and ARIA | Each widget follows its WAI-ARIA Authoring Practices pattern (roles, states, focus order, arrow keys), with a visible focus-visible ring. The kit's ring is a 2px solid accent ring with a 2px gap in the surface color (focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface); a row inside a list gets the same ring inset (focus-visible:ring-inset) instead. Use the same classes on a focusable element of your own so it matches. |
| Colors | Tokens only (bg-surface, text-muted, bg-success-soft), so light and dark both work. |
| Floating layers | Menus, popovers, tooltips, dialogs and toasts render through a portal (Portal), so no scroll area or overflow-hidden parent clips them. See Escape and the dismiss stack. |
| Motion | Through motion/react and the motion presets, transform and opacity only, and still under reduced motion. |
type Size = "sm" | "md" | "lg";
type Tone = "neutral" | "accent" | "success" | "warning" | "danger" | "info";
Stability: experimental (Size, Tone).
Design tokens
tokens.css defines the colors as CSS variables on :root and swaps them under :root[data-theme="dark"]. The frame sets data-theme on its own <html> and keeps it in step with the app, so anything built from the tokens works in light and dark with no code. Light is a cool neutral canvas with white surfaces, cool grey lines, ink text and one indigo accent; dark is cool near-black with off-white text and a lifted, lighter indigo accent, which takes dark text (accent-fg).
Each Tailwind color is a theme token (--color-*) that points at a CSS variable (--op-*). Tailwind classes in your files compile against these names (the build references @spacemix/ui/tokens.css as its theme):
| Tailwind color | Theme token | CSS variable | Use |
|---|---|---|---|
bg |
--color-bg |
--op-bg |
Page background (bg-bg) |
surface |
--color-surface |
--op-surface |
Cards, inputs, list containers (bg-surface) |
elevated |
--color-elevated |
--op-elevated |
Dialogs and popovers (bg-elevated) |
hover |
--color-hover |
--op-hover |
Hover and pressed fills (bg-hover) |
sunk |
--color-sunk |
--op-sunk |
A recessed fill below surface: segmented-control tracks, chips, quiet wells (bg-sunk) |
border |
--color-border |
--op-border |
Default borders and dividers (border-border) |
border-strong |
--color-border-strong |
--op-border-strong |
Emphasised borders (border-border-strong) |
control-border |
--color-control-border |
--op-control-border |
The edge of a control a person types in or presses: text fields, selects, secondary buttons; 3:1 or better on surface and bg (border-control-border) |
fg |
--color-fg |
--op-fg |
Main text (text-fg) |
muted |
--color-muted |
--op-muted |
Secondary text (text-muted) |
subtle |
--color-subtle |
--op-subtle |
Placeholders, meta text, quiet icons (text-subtle) |
accent |
--color-accent |
--op-accent |
Primary actions, links, selection (bg-accent, text-accent) |
accent-fg |
--color-accent-fg |
--op-accent-fg |
Text on the accent (text-accent-fg): white in light, near-black in dark, where the accent is a light indigo. Use it on bg-accent instead of text-white |
accent-soft |
--color-accent-soft |
--op-accent-soft |
Tinted backgrounds (bg-accent-soft) |
accent-hover |
--color-accent-hover |
--op-accent-hover |
The accent fill when hovered or pressed, a step darker; accent-fg on it is 4.5:1 or better (hover:bg-accent-hover) |
accent-text |
--color-accent-text |
--op-accent-text |
Accent text on accent-soft, 4.5:1 or better on it over bg, surface and elevated (bg-accent-soft text-accent-text) |
danger |
--color-danger |
--op-danger |
Errors and destructive actions (text-danger, bg-danger) |
danger-soft |
--color-danger-soft |
--op-danger-soft |
Tinted background behind danger text (bg-danger-soft) |
success |
--color-success |
--op-success |
Done, healthy, a rise that is good (text-success) |
success-soft |
--color-success-soft |
--op-success-soft |
Tinted background behind success text (bg-success-soft) |
warning |
--color-warning |
--op-warning |
Needs attention, nearly over a limit (text-warning) |
warning-soft |
--color-warning-soft |
--op-warning-soft |
Tinted background behind warning text (bg-warning-soft) |
info |
--color-info |
--op-info |
Neutral news, tips, in progress (text-info) |
info-soft |
--color-info-soft |
--op-info-soft |
Tinted background behind info text (bg-info-soft) |
c1 … c6 |
--color-c1 … --color-c6 |
--op-c1 … --op-c6 |
Chart series, in order (text-c2, bg-c3); c1 follows the accent, and dark has its own lifted values. The widget frame has the same six, light and dark. |
scrim |
--color-scrim |
--op-scrim |
The dimmed layer behind a modal (bg-scrim); darker in dark mode so it still reads. |
The series tokens, one by one: --color-c1, --color-c2, --color-c3, --color-c4, --color-c5, --color-c6, and --op-c1, --op-c2, --op-c3, --op-c4, --op-c5, --op-c6. --op-c1 follows the accent in each theme; dark has its own lifted --op-c2 to --op-c6, so every series reads at 3:1 or better on bg, surface and elevated in both themes.
Status colors. success, warning, info and danger are for text, icons, dots and borders: each reads at 4.5:1 or better on surface and bg. For a filled background use the -soft tint with the status color as the text (bg-warning-soft text-warning), which is what Badge, Alert and Callout do. Don't put white text on a solid status fill: the light theme's status colors are dark and the dark theme's are light, so white text fails in one of them. The one solid fill that takes text-accent-fg is a destructive button (Button variant="danger").
Other theme values:
| Token | Value | Tailwind |
|---|---|---|
--font-sans |
Figtree, then Inter Variable (for scripts outside Latin) and the system UI font | font-sans |
--font-display |
Figtree, the same stack as --font-sans. Page and view titles only; body text, controls and tables stay on font-sans. It sets the family only: the kit's titles add weight 650 and -0.02em tracking themselves (font-[650] tracking-[-0.02em]) |
font-display |
--font-display--font-variation-settings |
normal, since Figtree has no display cut; font-display applies it with the family |
none; comes with font-display |
--font-mono |
JetBrains Mono, then the system monospace font | font-mono |
--radius-sm |
7 px | rounded-sm |
--radius-md |
10 px | rounded-md |
--radius-lg |
12 px | rounded-lg |
--radius-xl |
16 px | rounded-xl |
--shadow-pop |
Border ring plus a soft drop shadow, tinted with --op-shadow and deepened by --op-shadow-strength |
shadow-pop |
--op-shadow |
The shadow color as an RGB triplet: 22 22 31 (ink) in light, 0 0 6 (near-black) in dark. Use it as rgb(var(--op-shadow) / 0.1) for a shadow of your own |
none; shadow-[0_2px_8px_rgb(var(--op-shadow)/0.1)] |
--op-shadow-strength |
How much deeper shadows are in the theme, a multiplier for your alphas: 1 in light, 1.7 in dark |
none; calc(0.1 * var(--op-shadow-strength)) |
--op-window-border |
The edge of a window floating over the app, a step past --op-border-strong |
none; var(--op-window-border) |
--ease-out |
cubic-bezier(0.22, 1, 0.36, 1) |
ease-out |
Opacity modifiers work on the colors (bg-accent/10, border-accent/40). With prefers-reduced-motion: reduce, animations and transitions are cut to almost nothing everywhere in the frame.
Never hard-code colors. A hex value looks wrong in one of the two themes. In plain CSS, use var(--op-fg) and the other variables directly. The --op-* variable names are also what a widget receives in its theme (see Widget reference).
Stability: stable. Token names won't be removed or renamed within protocol 1; their values may change.
Using newer exports on an older host
The kit your bundle runs against is the one the server ships (see How your code meets the host). On a server from before this release, every export on the component pages is missing: the import doesn't fail, it is undefined, and rendering it throws. Test for what you use, as the contract's "New bundle, old host" rule says:
import { Badge, toast } from "@spacemix/ui";
if (typeof toast === "function") toast.success("Saved");
const status = typeof Badge === "function" ? <Badge tone="success">Live</Badge> : <span className="text-success">Live</span>;
New props on old components (Button's loading, Input's leftIcon) don't fail on an older host, but do nothing there: the old component passes them on to the DOM element, and React may log a warning about an unknown attribute. Don't rely on them for anything a person needs (a loading button there stays clickable).
Names that clash with lucide-react
lucide-react has icons named like these kit components: Badge, BarChart, Calendar, Container, Gauge, Grid, LineChart, Link, List, Radio, Section, Table, Tag and Timeline. Import the icon by its *Icon alias, which lucide exports for every icon, and keep the plain name for the component:
import { Calendar, Table, Tag } from "@spacemix/ui";
import { CalendarIcon, TagIcon } from "lucide-react";
Toasts in an extension frame
toast() works in every extension view without setup: the frame mounts a <Toaster fallback /> next to your view (apps/desktop/frame/main.tsx). A Toaster or ToastProvider your view mounts itself renders instead whenever it is mounted, even one mounted later (after a loading state), with its own position, duration and limit; the frame's comes back when yours unmounts. Because the fallback is always mounted, every extension frame has a live region named "Notifications" (<section aria-label="Notifications">), empty until a toast shows. See Toasts.
Escape and the dismiss stack
Every layer that closes on Escape or a press outside goes through one stack (useDismiss in floating.ts): DropdownMenu, Popover, HoverCard, Tooltip, Select and the other pickers, Dialog, Drawer, CommandDialog, ConfirmDialog and ContextMenu. The rules:
- Escape closes only the newest open layer. A menu opened inside a dialog closes on the first Escape; the dialog stays until the second.
- A press inside a layer opened later (a submenu, a list opened from a popover, a popover in a dialog) doesn't close the layers under it.
- Modals (
Dialog,Drawer,ConfirmDialog) close on a press on their backdrop, not on every press outside, so a press inside a toast or a portalled list doesn't cancel them.
Menus, popovers and lists sit at z-index 70, dialogs and drawers at 60 (so a popover opened from a dialog is above it), toasts at 80. A layer of your own joins the stack with useDismiss.
cx
function cx(...parts: Array<string | false | null | undefined>): string;
Joins class names, skipping falsy parts: cx("px-3", active && "bg-hover").
Stability: stable.
useControllableState
function useControllableState<T>(value: T | undefined, defaultValue: T, onChange?: (value: T) => void): [T, (next: T | ((prev: T) => T)) => void];
A value a component either owns or takes from its caller: controlled while value is defined, kept internally (starting at defaultValue) otherwise. It returns the current value and a stable setter that takes a value or an updater (prev) => next, skips a value equal to the current one (Object.is) and calls onChange with the new value. It is the pattern behind every kit control's value / defaultValue / onChange and open / defaultOpen / onOpenChange; use it to give a control of your own the same props.
function Stars({ value, defaultValue = 0, onChange }: { value?: number; defaultValue?: number; onChange?: (n: number) => void }) {
const [stars, setStars] = useControllableState(value, defaultValue, onChange);
return <HStack>{[1, 2, 3, 4, 5].map((n) => <IconButton key={n} aria-label={`${n} stars`} onClick={() => setStars(n)}><Star className={n <= stars ? "text-warning" : ""} /></IconButton>)}</HStack>;
}
Source: packages/ui/src/controllable.ts. Stability: experimental.
Button
type ButtonVariant = "primary" | "secondary" | "ghost" | "danger";
interface ButtonProps extends ComponentProps<"button"> {
variant?: ButtonVariant; // default "secondary"
size?: Size; // default "md"
loading?: boolean; // default false
leftIcon?: ReactNode;
rightIcon?: ReactNode;
fullWidth?: boolean;
}
function Button(props: ButtonProps): JSX.Element;
The app's button. Every other button attribute passes through (onClick, type, disabled, aria-*, ref); className is appended. Icons inside are kept from shrinking; size them with className="size-4", or pass them as leftIcon and rightIcon, which size them for the button.
| Prop | Type | Default | What it does |
|---|---|---|---|
variant |
ButtonVariant |
"secondary" |
"secondary" is bordered on surface; "primary" the accent fill for the main action of a screen; "ghost" text only, for toolbars; "danger" a solid danger fill for a destructive action. |
size |
Size |
"md" |
"sm" 28 px, "md" 32 px (the app's toolbars), "lg" 40 px. |
loading |
boolean |
false |
Shows a spinner in place of the content (the width is kept), disables the button and sets aria-busy. |
leftIcon |
ReactNode |
none | An icon before the label, sized for the button and hidden from screen readers. |
rightIcon |
ReactNode |
none | An icon after the label (a chevron, an arrow). |
fullWidth |
boolean |
none | Stretches to the full width of the container. |
<Button variant="primary" type="submit" leftIcon={<Plus />} loading={saving}>Add</Button>
Stability: stable: Button and variant with "primary", "secondary" and "ghost"; ButtonVariant, newly exported, is stable and may gain members, so code that switches over it must handle an unknown value. Experimental: ButtonProps, size, loading, leftIcon, rightIcon, fullWidth and the "danger" variant. For a button that holds only an icon, use IconButton.
Input
interface InputProps extends Omit<ComponentProps<"input">, "size"> {
size?: Size | number; // default "md"
invalid?: boolean;
leftIcon?: ReactNode;
rightIcon?: ReactNode;
leftAddon?: ReactNode;
rightAddon?: ReactNode;
htmlSize?: number;
}
function Input(props: InputProps): JSX.Element;
A full-width single-line text field with the app's focus ring. All input attributes pass through, onChange gets the native event, and className is appended.
| Prop | Type | Default | What it does |
|---|---|---|---|
size |
Size | number |
"md" |
The kit's scale: "sm" 32 px, "md" 36 px, "lg" 40 px. A number is the native size attribute (width in characters), as before the scale existed; the field then has the "md" height. |
invalid |
boolean |
none | Sets aria-invalid and a danger border. A surrounding Field with an error sets it too. |
leftIcon |
ReactNode |
none | Content inside the field before the text: an icon (in the subtle color) or a small button. |
rightIcon |
ReactNode |
none | Content inside the field after the text: an icon, a unit, a Kbd hint or a small button. |
leftAddon |
ReactNode |
none | An attached segment before the field, such as https://. |
rightAddon |
ReactNode |
none | An attached segment after the field, such as .example.com or a unit. |
htmlSize |
number |
none | The native size attribute, for when size holds the scale. Wins over a numeric size. |
With an icon or an addon the field becomes a box around the <input>: className then goes on the box and ref stays on the <input>. Inside a Field it takes the field's id, description, error, required and disabled state.
<Input value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search" />
<Input leftAddon="https://" rightAddon=".example.com" aria-label="Subdomain" />
Stability: stable: Input, its native attributes and a numeric size. Experimental: InputProps, size as the scale, invalid, leftIcon, rightIcon, leftAddon, rightAddon and htmlSize.
Kbd
function Kbd(props: { children: ReactNode; className?: string }): JSX.Element;
A keyboard key, for shortcuts in hints and menus: <Kbd>⌘</Kbd><Kbd>K</Kbd>. className is joined last onto the <kbd>.
Stability: stable: Kbd and children. Experimental: className.
PageHeader
function PageHeader(props: { title: ReactNode; subtitle?: ReactNode; actions?: ReactNode; below?: ReactNode }): JSX.Element;
The header at the top of a view: a title, an optional subtitle under it, and optional actions on the right. Its padding matches the app's own pages, and narrows on phones. Without below it renders as it always has. below is a slot under the row, for Tabs or filters. To pin it above a scrolling body, pass it as a Page's header.
<PageHeader title="Tasks" subtitle="3 open" actions={<Button variant="primary">New task</Button>} />
Stability: stable: PageHeader and title, subtitle, actions as strings. Experimental: title and subtitle as any node, and below.
EmptyState
function EmptyState(props: { icon: ReactNode; title: ReactNode; body?: ReactNode; action?: ReactNode; size?: Size } & Omit<ComponentProps<"div">, "title" | "children">): JSX.Element;
A centered message for an empty list or a view that isn't set up yet: an icon in a tile, a title, a sentence, and an optional action under it. size is "sm" for a panel or a widget, "md" (default) for a page, "lg" for an empty window, as on the other state views in Feedback. Other <div> props, className (joined last) and ref go to the root <div>.
<EmptyState icon={<Inbox className="size-5" />} title="No messages" body="New mail shows up here." action={<Button>Connect account</Button>} />
Stability: stable: EmptyState and icon, title, body, action as before. Experimental: title and body as any node, body optional, size, and className, ref and the other <div> props.
Markdown
function Markdown(props: { text: string; className?: string }): JSX.Element;
Renders markdown with GitHub extensions (tables, strikethrough, task lists, autolinks) in the app's type styles. Links get target="_blank"; in the frame, the runtime routes the click to host.shell.openUrl. Raw HTML in the text is not rendered. Without className the output has no wrapper element; with it, the output is wrapped in a <div> that gets the class.
<Markdown text={note.body} />
Stability: stable: Markdown and text. Experimental: className.
ConfirmDialog
function ConfirmDialog(props: {
open: boolean;
title: React.ReactNode; // the question; a string, or any node
body: React.ReactNode;
confirmLabel?: string; // default "Confirm"
danger?: boolean; // style the confirm button as destructive
typeToConfirm?: string; // text the user must type before confirming
onConfirm: () => void;
onCancel: () => void;
}): React.ReactPortal;
"Are you sure?" for an action worth a second look. Use it instead of window.confirm, which the frame doesn't have. Escape or a click on the backdrop calls onCancel; Escape goes through the dismiss stack, so a popover or menu open above the dialog closes first. Without typeToConfirm, the confirm button has focus, so Enter confirms. With it, the user must type that text (case and surrounding spaces don't matter) before the button works; the field is cleared every time the dialog opens. danger makes the confirm button a Button variant="danger". The dialog is labelled by its title through an id of its own, so several on one page don't collide. It renders into document.body, or into a surrounding PortalContainer. The dialog doesn't close itself: set open to false in both callbacks. For a larger dialog with a form, use Dialog; for a small step in place, ConfirmInline.
<ConfirmDialog
open={deleting}
title={`Delete ${board.name}?`}
body="Its cards are deleted too."
confirmLabel="Delete"
danger
onConfirm={() => { setDeleting(false); void remove(board.id); }}
onCancel={() => setDeleting(false)}
/>
Stability: stable: ConfirmDialog and its props, with title as a string. Experimental: title as any node.
ContextMenu, MenuEntry, MenuAnchor, anchorFrom
type MenuEntry =
| { kind?: "item"; label: string; icon?: React.ReactNode; onSelect: () => void; danger?: boolean; selected?: boolean; disabled?: boolean }
| { kind: "submenu"; label: string; icon?: React.ReactNode; items: MenuEntry[] }
| { kind: "separator" };
interface MenuAnchor { x: number; y: number }
const anchorFrom: (e: React.MouseEvent) => MenuAnchor;
function ContextMenu(props: { anchor: MenuAnchor | null; items: MenuEntry[]; onClose: () => void }): React.ReactPortal;
A right-click menu at a point on the screen. It shows while anchor is set. anchorFrom turns a mouse event into an anchor and suppresses the browser's own menu. The menu stays inside the window, flipping to the other side of the anchor when it doesn't fit. It closes (calls onClose) on a press or a right-click outside the menu and its submenus, Escape, a resize, the window losing focus, or after an item runs. It is a layer of the dismiss stack: over a dialog, Escape closes only the menu. Arrow keys move, Enter picks, and the right and left arrows open and close submenus; submenus also open on hover. selected shows a check mark; danger colors the item; disabled items can't be picked. It renders into document.body, or into a surrounding PortalContainer. For a menu that opens from a button, use DropdownMenu.
const [menu, setMenu] = useState<MenuAnchor | null>(null);
const close = useCallback(() => setMenu(null), []);
const items: MenuEntry[] = [
{ label: "Rename", onSelect: () => setRenaming(true) },
{ kind: "separator" },
{ label: "Delete", danger: true, onSelect: () => setDeleting(true) },
];
<li onContextMenu={(e) => setMenu(anchorFrom(e))}>{note.title}</li>
<ContextMenu anchor={menu} items={items} onClose={close} />
Pass a stable onClose (from useCallback): the menu re-attaches its listeners when it changes.
Stability: stable.
RenameInput
function RenameInput(props: { value: string; onCommit: (name: string) => void; onCancel: () => void; className?: string; label?: string }): JSX.Element;
A text field that takes the place of a title while it's renamed. It opens focused with the current name selected. Enter or leaving the field commits the trimmed name; Escape cancels. Only one of the two runs. A blank name, or the same name, calls onCancel instead of onCommit. Clicks on the field don't reach the row behind it. label is the field's accessible name (default "Rename"). It has no styles of its own: pass className.
{renaming
? <RenameInput value={note.title} onCommit={(title) => { setRenaming(false); void update(note.id, { title }); }} onCancel={() => setRenaming(false)} className="w-full bg-transparent text-fg outline-none" />
: <span>{note.title}</span>}
Stability: stable.
Motion presets
const spring: Transition; // { type: "spring", stiffness: 520, damping: 42, mass: 0.9 }
const softSpring: Transition; // { type: "spring", stiffness: 300, damping: 34 }
const fade: Transition; // { duration: 0.18, ease: [0.22, 1, 0.36, 1] }
const pageVariants: Variants; // initial / animate / exit: a short rise and fade for pages
const popVariants: Variants; // initial / animate / exit: a small scale and fade for popovers and dialogs
const listItem: Variants; // initial / animate / exit: list rows appearing, and sliding left on removal
spring, softSpring, fade, pageVariants, popVariants and listItem are one motion language for the whole app: short, damped, never bouncy, and only transform and opacity, so it stays smooth on every webview. Use them with motion/react:
import { AnimatePresence, motion } from "motion/react";
import { listItem, spring } from "@spacemix/ui";
<AnimatePresence initial={false}>
{items.map((t) => (
<motion.li key={t.id} layout transition={spring} variants={listItem} initial="initial" animate="animate" exit="exit">{t.title}</motion.li>
))}
</AnimatePresence>
Use motion sparingly.
Stability: stable. The names and shapes are stable; the numbers may be tuned.
Icons
lucide-react is provided by the frame. Import any icon by its PascalCase name (import { Plus, Trash2 } from "lucide-react") and size it with classes (className="size-4"). The manifest's icon is the same icon's name in kebab-case ("trash-2", "check-square"). For icons whose name is also a kit component, see Names that clash with lucide-react.