@mdbase-dev/ui
The shared visual foundation of mdbase apps: Editor, Reader, Writer, and any
app that wants to look like part of the family. Nothing here is required to
build on mdbase Connect.
import "@mdbase-dev/ui/fonts.css";
import "@mdbase-dev/ui/tokens.css";
import "@mdbase-dev/ui/brand.css";
import { Wordmark } from "@mdbase-dev/ui/brand";
import { loadThemePreference, applyThemePreference } from "@mdbase-dev/ui/theme";
import { mdbaseAppHref, withAppUrls } from "@mdbase-dev/ui/apps";
applyThemePreference(loadThemePreference());
tokens.css defines semantic roles (--color-canvas, --color-text,
--color-text-soft, --color-accent, ...) for light, dark and system
themes. Style components with roles, not palette values. Short aliases such
as --ink belong to each app.
--color-current and --color-on-current mark the keyboard/pointer current
choice in completion lists and diagnostics; --color-selected stays subtle for persistent selections.
Each colour that differs by theme is one light-dark() value, and :root
uses one scheme at a time. In CSS, var(--color-text) resolves as before. In
script, read a resolved colour from an element (getComputedStyle(element).color),
not the raw property, which is the light-dark() expression. An element that
sets its own color-scheme gets that scheme's colours.
- Corners come in three sizes:
--radius-sm (6px) for controls and rows,
--radius-md (8px) for content blocks and toasts, --radius-lg (10px) for
menus and dialogs.
theme stores the System, Light or Dark choice as mdbase:theme.
brand draws the Frontmatter mark, each app's inverted mark, and the
mdbase <app> wordmark. Add motion.css to animate the mark: loops
(orbit, scan, bounce, stream, sort, hop), entrances
(keys-first, drop, assemble), one-shot saved/error signals, and a
progress fill.
mark-activity is the page-wide store behind the app switcher's mark.
SaveNotice already reports saves and problems to it. For other work, call
signalMdbaseMark("saved" | "error") when a write the person made finishes,
trackMdbaseMarkProgress() (or useMdbaseMarkProgress(fraction)) when the
total is known, and holdMdbaseMarkBusy(loop) (or useMdbaseMarkBusy) while
it is not.
apps lists the mdbase apps, exports the MCP setup and endpoint URLs
(mcpSetupUrl, mcpEndpointUrl), and builds links that open the current
collection in another app. Every deployment passes its own URLs to
withAppUrls (or AppSwitcher's urls prop, which accepts all official
apps). Apps without a configured URL are omitted; shared metadata never falls
back to production origins. AppSwitcher accepts any OfficialAppId as
current, optional children/className/align for apps with their own
trigger identity (such as TaskNotes), and an optional collectionId when the
app does not carry ?collection= in location.href. The switcher includes an
AI clients (MCP) link by default (pass mcpUrl={null} to omit on custom
servers) and ends with a "Build your own" link to the SDK guide.
Opening screen
Every app opens on the same screen: its mark scanning above mdbase <app>
and a line saying what it is opening. Paint it from index.html, before any
script runs, and render OpeningScreen from @mdbase-dev/ui/screens while
the app loads after that. Both produce the same DOM, so the hand-over is
invisible.
// vite.config.ts
import { mdbaseOpeningPage } from "@mdbase-dev/ui/opening-page";
plugins: [react(), mdbaseOpeningPage({
app: "reader",
title: "Opening your library",
themeColor: { light: "#fcfcfd", dark: "#1b1d23" },
})];
<!-- index.html: keep <meta charset>; drop any theme-color meta and theme script -->
<div id="root"><!--mdbase-opening--></div>
<Suspense fallback={<OpeningScreen app="reader" title={t`Opening your library`} />}>
- The plugin inlines
tokens.css, brand.css and screens.css right after
<meta charset>, ahead of the app's own CSS, and writes the
theme-color meta. It refuses an index.html without the marker or charset,
or one that already sets theme-color.
- Its one inline script applies the saved theme before first paint. Until
the app replaces the page, it also turns a failed bundle or startup error
into the screen's failure state, with a Reload link. An app with a script
CSP must allow that script's hash.
- Without JavaScript the page shows that the app needs it. After eight
seconds, CSS alone shows "Still opening? Check your connection." with a
Reload link.
- The static page is English: it paints before any catalogue loads. The
React screen takes over in the reader's language.
OpeningScreen's error shows the failure state, and onRetry adds Try
again. layout="panel" renders a div without the reload hint, for a
screen inside the app's own chrome.
Switch and segmented control
Both need controls.css.
import { Switch } from "@mdbase-dev/ui/switch";
import { Segmented } from "@mdbase-dev/ui/segmented";
<Switch checked={wrap} onChange={setWrap}>Wrap long lines</Switch>
<Segmented aria-label="View" value={view} onChange={setView} options={[
{ value: "day", label: "Day" },
{ value: "week", label: "Week" },
]} />
Switch is for a setting that takes effect at once; use Checkbox for a
choice that waits for a Save. Its children are its label. Without children it
renders the control alone, for a row that lays out its own text: name it
with aria-label or aria-labelledby. Other button props pass through.
Segmented is one choice among two to four short options that stay in
view. It is a group of native radios, so arrow keys move the choice. Use
Select for more options or long labels.
ThemeSelect from @mdbase-dev/ui/theme-select is the segmented control
for System, Light and Dark.
Motion
motion.css (which controls.css imports) defines the durations and curves.
Something a hand just moved, such as a released button, a switch thumb or a
segmented thumb, settles on --motion-spring with --ease-spring, a spring
with about 2% overshoot; the press itself takes --motion-press. Menus, lists
and dialogs open on the same spring, from the corner beside their trigger.
Reduced motion sets every duration to zero, so nothing needs its own override.
Icon-button tooltips
Import Tooltip from @mdbase-dev/ui/tooltip and include controls.css.
Wrap one icon button or link in <Tooltip label="Search" shortcut="mod+k">…</Tooltip>.
Localize the label in the caller. The optional shortcut uses the same notation and
platform labels as the command palette and sets aria-keyshortcuts on the button.
The button keeps its ref and handlers; a native manual popover adds no layout box
or focus stop. Escape dismisses a visible tooltip before the parent dialog;
the bubble remains visible while hovered, with 120 ms to cross the gap.
Only the supplemental shortcut is linked as a description, preserving existing
button names and descriptions. Hover waits 400 ms, keyboard
focus is immediate, and a recently closed tooltip keeps the next one immediate
for 800 ms. Touch presses do not show a tooltip. Scroll, resize, window blur,
press, or an unavailable trigger cancels pending and visible hints.
Toasts
Mount one Toaster from @mdbase-dev/ui/toast inside the app's locale provider
and import @mdbase-dev/ui/toast.css after controls.css. Call
toast(message, undo?) with localized copy and, when applicable, a real inverse
mutation. The toast stays for five seconds (eight with Undo), pauses on hover
or focus, and queues up to three more messages. Unmounting the owner clears the
queue.
For anything else, pass options in place of the undo function:
toast("Collection shared", { tone: "success" });
const dismiss = toast("Could not save", {
tone: "error",
sticky: true,
action: { label: retryLabel, onAction: retry, dismiss: true },
});
tone puts a tick or an exclamation mark before the message, sticky keeps
the toast until it is dismissed, durationMs sets another time, and
dismissible: false removes the close button. toast returns a function that
dismisses that toast.
Languages
The /i18n entry exports uiCatalogues: CatalogueSource with synchronous
English and lazy local-deployment JSON for fr de es ja ko pt ru zh.
Compose it once with the app's catalogue using @mdbase-dev/i18n:
import { i18n, uiCatalogues } from "@mdbase-dev/ui/i18n";
const runtime = createI18nRuntime({ i18n, english: appEnglish, loadLocale, libraries: [uiCatalogues] });
// Wrap the app once in LocaleProvider with this runtime.
Core-macro presentation helpers use the shared Lingui singleton; do not compose
into an unrelated isolated instance. Keep React and Lingui deduplicated in app
bundlers. No form is remounted on a locale switch. Build output includes all
ten catalogues and transformed macros; consumers do not compile library source.
PO files are the only authoring format. Builds use the kit CLI to prune obsolete PO
entries before compilation, including English fallback; prepack runs strict catalogue
checks and rebuilds so stale compiled messages cannot enter a fresh tarball.
Run strict i18n:check before release: a fallback-capable development build does
not prove a language is complete.
Reviewed identical terms are Esc/ID, the literal example email, and French
Collection/Collections (allowlisted per generated ID).
Give every new message a context (for example t({ message: "Clear", context: "Date picker" })).
Apps compose this catalogue with their own, and a message without a context gets the same
generated ID as an app's message with the same English text, so one would replace the other's
translations. i18n-context-baseline.json freezes the older messages that have none; the
catalogue test rejects any other.
Command palette
CommandPalette from @mdbase-dev/ui/command-palette accepts an optional
groupLabel(groupId: string): string callback for localized group headings.
For example, pass groupLabel={readerCommandGroupLabel}. Without it, the heading
remains the command's group string. This is presentation only: keep Command.group
and showAll values as stable IDs. Group order, browsing limits and search matching
still use those IDs; translated headings do not change matching or merge groups.
Re-render with the current locale's callback to update the presentation.
Link picker
LinkPicker from @mdbase-dev/ui/link-picker is the field for linking one
record to another: type to find a record, or make a new one of a given kind
from what was typed. Include controls.css.
<LinkPicker
label={t`Author`}
query={query}
onQueryChange={setQuery}
options={matches.map((person) => ({ id: person.path, title: person.name, detail: t`Person` }))}
creates={[{ id: "person", label: t`New person` }]}
emptyMessage={t`No matching people.`}
onPick={(option) => link(option.id)}
onCreate={(create, title) => createAndLink(create.id, title)}
/>
The app matches and ranks options for the current query; the picker does not
filter. creates are listed after the matches once something is typed, unless a
match already carries exactly that title. Every string is passed in, so the
picker adds nothing to the shared catalogue. Focus stays in the text field: the
first Escape closes the list, the second calls onClose, as does leaving the
field. linkPickerRows(query, options, creates) gives the same rows to a surface
that draws its own list, such as an editor's completion popup.
Quick create
QuickCreate from @mdbase-dev/ui/quick-create is a short form for a record
made in passing, such as one chosen from a link picker's create row when its
type needs more than a name. Include controls.css.
{creating && <QuickCreate
title={t`New book`}
name={creating.title}
nameLabel={t`Title`}
onNameChange={(title) => setCreating({ ...creating, title })}
anchor={() => field.current?.getBoundingClientRect()}
submitLabel={t`Create and link`}
blocker={creating.isbn ? undefined : t`Give the ISBN.`}
onSubmit={createAndLink}
onClose={(refocus) => { setCreating(undefined); if (refocus) field.current?.focus(); }}
>
<IsbnField value={creating.isbn} onChange={(isbn) => setCreating({ ...creating, isbn })} />
</QuickCreate>}
Render it while the form is wanted. It opens in the top layer beside anchor
(called again on scroll and resize; return nothing once that place has gone),
puts the keyboard in the first field after the name and keeps Tab inside. The
app supplies the fields as children and every string except Cancel. Escape and
Cancel call onClose(true); a press elsewhere calls onClose(false), because
the focus has already moved. A list open inside the form takes the first Escape.
Anchored popover
AnchoredPopover from @mdbase-dev/ui/anchored-popover is a small panel beside
the control that opened it, for a value to choose or type: a calendar, a
checklist, a short form. Include controls.css.
<button ref={anchor} aria-haspopup="dialog" aria-expanded={open} onClick={() => setOpen(!open)}>{t`Due`}</button>
{open && <AnchoredPopover anchor={anchor} label={t`Due date`} onClose={() => setOpen(false)}>
<Calendar value={due} onPick={pick} />
</AnchoredPopover>}
Render it while it is wanted. It opens in the top layer, follows its anchor, and
puts the keyboard in the element marked data-autofocus, or failing that in its
first control. Escape calls onClose(true) with the focus back on the anchor; a
press elsewhere calls onClose(false) after the field being typed in has lost
the focus, so a field that commits when it is left keeps what was typed. A list
or menu open inside it takes the first Escape. A menu of actions is Menu.
Date picker
@mdbase-dev/ui/date-picker has DateField, a date that reads as a date and
opens a calendar to change it, and Calendar, the month on its own for a panel
that is already open. Dates go in and out as they are stored (2026-11-28).
Include controls.css and date-picker.css; filter-builder.css and
properties.css already bring the second with them.
<DateField value={due ?? ""} label={t`Due`} placeholder={t`No date`} onChange={setDue} />
The calendar's field takes a typed day: a stored date, today, tomorrow or
yesterday in the interface's language, a weekday (the next one), or a number of
days or weeks from today (+3, -1, 2w). The arrow keys move through the
days and Page Up and Page Down through the months, from the field or the grid.
The week starts where the reader's locale starts it. readDay(text) and
formatDay(value) read and write a day the same way outside the picker. The
text is in the shared catalogue; pass labels to word any of it differently.
Combo
Combo from @mdbase-dev/ui/combo is a text field with a list of plain values
under it: type to narrow the list, choose a row, or take what was typed. It is
the link picker given values in place of records. Include controls.css.
<Combo
label={t`Stage`}
value={stage}
options={stages.map((value) => ({ value }))}
newLabel={t`Use`}
emptyMessage={t`Nothing matches.`}
commitOnBlur
onCommit={(value) => setStage(value)}
/>
Without newLabel only the options can be chosen. accepts says whether typed
text may be taken, and emptyMessage shows when it may not and nothing
matches. onCommit(value, made) reports whether the value was typed rather than
chosen. Every string is passed in.
Filter builder
FilterBuilder from @mdbase-dev/ui/filter-builder is an inline filter bar
over a CEL where expression. Each filter is a pill: a rule on a field, with
one value or several, or an expression kept as written. Pills combine in nested
all, any and none groups. Include controls.css and filter-builder.css.
<FilterBuilder
query={where}
fields={filterFieldsFromProperties(propertiesInUse(records, declared))}
error={queryError}
onChange={setWhere}
/>