@tradalab/lyra
v3.26.0
Published
Tradalab UI kit - shadcn (radix-lyra) primitives, composed components, and app shell for React 19 / Next 16 / Tailwind v4.
Maintainers
Readme
@tradalab/lyra
Tradalab's UI kit — shadcn (
radix-lyrastyle) primitives, composed components, and an app shell for React 19 / Next 16 / Tailwind v4.
ESM-only. Extracted from Tradalab's foundation kit so every company app shares the same component surface.
Install
pnpm add @tradalab/lyra
# peers: react ^19, react-dom ^19 (next ^16 only if you use /shell)The stylesheet pulls in Tailwind v4, so your app needs @tailwindcss/postcss.
/* app/globals.css */
@import "@tradalab/lyra/styles.css";Subpaths
| Subpath | Exports | Boundary |
|---|---|---|
| @tradalab/lyra/utils | cn, foldText, formatBytes/formatCount, addTag/matchesKeyword, pickDelimiter/groupByPrefix, CONNECTION_COLORS/resolveColor/ENV_FRAME, SIDEBAR_COOKIE/sidebarOpenFromCookie | server-safe |
| @tradalab/lyra/hooks | useMobile, useDirtyFields, useBackClose/pushBackLayer, useSidebarWidth + clampSidebarWidth/SIDEBAR_WIDTH_KEY | client |
| @tradalab/lyra/ui | 61 shadcn primitives + AccountMenu, ActionButton, Container, EmptyState, StatusBadge | client |
| @tradalab/lyra/blocks | Form/FormField + RHF glue, Panel, Confirm/useConfirm, Tree, TzPicker, OptionPicker, MobileSheet, ChoiceDrawer, McpSettings, LlmSettings, PlatePicker, usePlate, useCompact, PreferenceScript, StatTile, BarList, ColorSwatches, TagInput, loadExpanded/saveExpanded, DateField, LockedReason, UnsavedBadge, useConfirmReason, useBlocked, ConnectionTree/buildConnectionTree, ConfigListDialog, SshFields/TlsFields/ProxyFields + sshDefaults/tlsDefaults/proxyDefaults, ReleaseNotes, useHostKeyTrust + hostKeyAsk/retryAfterTrust, ListSection/ListSectionTitle/ListItem/ListRow, BackDrawer/BackDialog/BackAlertDialog/BackSheet | client |
| @tradalab/lyra/data-table | DataTable + usePager, TableFilterBar, TableFilterChips, TableSearch, TableReload, filterRows, pageWindow | client |
| @tradalab/lyra/shell | AppShell, PageShell, PageHeader, TopBar, NavItem, NavGroup, Breadcrumbs, BottomNav, useActiveRoute, useSearchParam, useTabParam, usePageParam, UrlTabs | client |
| @tradalab/lyra/styles.css | Tailwind v4 base + radix-lyra tokens (light/dark) | CSS |
Client subpaths carry a build-injected "use client"; import them inside a
client tree or pass via children — don't import them into a Server Component's
own module.
import { Button, Card, CardHeader } from "@tradalab/lyra/ui"
import { AppShell, NavItem } from "@tradalab/lyra/shell"Tables: four modes, and the list decides which
DataTable owns the controls; usePager (3.8.0) owns the wiring that every console used to
write out by hand. Pick the mode from what is behind the list, not from habit.
| Mode | Pass | For |
|---|---|---|
| numbered | {...pager.bind(total)} | the server pages it and returns a total - a list somebody audits |
| cursor | onLoadMore + hasMore + loadingMore | the store only gives a continuation token and no count |
| client-paged | {...pager.slice(rows).props} | the fetch IS the whole answer: a list derived from two endpoints, one operation's result |
| unpaged | unpaged | the row count does not grow with tenants or with time - a declared inventory, a fixed catalogue |
const pager = usePager({ pageSize: 25, labels }) // labels come from the app's i18n
const { data } = useThings({ page: pager.page, pageSize: pager.size })
<TableFilterBar actions={<TableReload onClick={refetch} loading={isFetching} />}>
<TableSearch onChange={pager.onFilter(setQuery)} placeholder="Name or code" />
</TableFilterBar>
<DataTable columns={columns} data={data?.things ?? []} {...pager.bind(data?.total ?? 0)} />Two rules the components enforce rather than document:
TableFilterBarreplacesDataTable's own bar (searchable/toolbar/onReload). Two bars on one table is how a screen ends up with two search boxes that search different things.searchablestays off on anything the server pages. It filters the rows already in the browser, so it answers "no results" about a row on page three. Send the query instead;filterRowsis for the unpaged case, where local filtering is the truth.
To keep the page, the query and the open tab in the URL, shell holds the Next side and
data-table only takes state: usePager({ ...usePageParam(), labels }), and
<TableSearch value={q} onChange={pager.onFilter(setQ)} /> with
const [q, setQ] = useSearchParam("q"). Rows per page stay out of the URL. Show what is in force
with TableFilterChips: a link can open a table already narrowed. Clear a chip through
pager.onFilter too, so the page goes back to 1 with the filter.
DataTable also takes onRowClick (the whole row, and Enter or Space) and selection
(getRowId + selected + onSelectedChange). The header box covers the rows on screen only;
acting on every row that matches a filter is a separate request that sends the filter.
lyra ships no copy and no number formatting: usePager takes labels, including
range: ({from, to, total}) => string. That keeps next-intl out of the library, which matters
because data-table must stay loadable by a consumer that is not a Next app.
Toast
2.0.0 replaced the sonner-based toast with shadcn's Base UI Toast. sonner is
gone — it is no longer a peer dependency, and apps should drop it.
toast is a manager object, not a callable:
import { Toaster, toast } from "@tradalab/lyra/ui"
toast.add({ title: "Saved" })
toast.add({ title: "Upload failed", description: err.message, type: "error" })
const id = toast.add({ title: "Uploading…", type: "loading", timeout: 0 })
toast.close(id)type is "success" | "error" | "info" | "warning" | "loading" — there is no
toast.success("x"). timeout: 0 never auto-dismisses (sonner's duration:
Infinity). Position belongs to the viewport this package styles, so sonner's
position and richColors props have no equivalent. Mount <Toaster/> once —
apps on @tradalab/nekit already get it from NekitProvider.
Plate and density
3.4.0 added a palette the reader picks. The colours live in styles.css behind
[data-plate="<name>"], so an app only wires the choice:
import { PlatePicker, PreferenceScript, useCompact, usePlate } from "@tradalab/lyra/blocks"
// In the root layout, as early in the tree as possible.
<PreferenceScript />
// On a settings screen.
const [plate, setPlate] = usePlate()
<PlatePicker value={plate} onChange={setPlate} label="Accent colour" resetLabel="Default" />usePlate and useCompact remember the choice per DEVICE, in localStorage
under lyra.plate and lyra.compact, which is the same granularity as the
theme. Absence means the default, so turning one off removes its key rather than
storing "off".
Keep suppressHydrationWarning on <html>. The script writes attributes the
server did not render, which is the same reason next-themes needs it; every
tradalab layout and template-web already carry it.
Leaving out <PreferenceScript /> is neither a compile error nor a runtime one.
The attributes then arrive from an effect, so the first paint is always the
neutral default and every reader who chose a colour watches it flip. It has to be
a raw inline script to beat that paint, which is why lyra renders it instead of
leaving it to each app.
Phones
3.12.0 moved in what the scorix Android apps had each written by hand. The kit
is sized for a pointer, so a phone app opts in to finger-sized controls on its
root, and takes the phone's own chrome from the kit:
<html data-touch="true"> // 40px controls, 14px text
import { BottomNav } from "@tradalab/lyra/shell"
<BottomNav items={[{ id: "codes", label: t("codes"), icon: <KeyRound /> }]} activeId={tab} onSelect={setTab} />
import { ChoiceDrawer, MobileSheet } from "@tradalab/lyra/blocks"
<MobileSheet open title="Add account" onOpenChange={open => !open && close()}>…</MobileSheet>
<ChoiceDrawer trigger={row} title="Theme" options={themes} value={theme} onValueChange={setTheme} />BottomNav routes nothing and adds no safe-area padding: the id comes back to
the app, and the app's root pads the edges.
Develop
make install # pnpm install
make build # tsup + inject-use-client + verify-build-output
make verify # typecheck + lint + test
make ui-add <name> # scaffold a shadcn primitive, adapt, rebuild barrel
make ui-update <name> # overwrite a primitive with the latest upstream version
make ui-sync # re-adapt every primitive + rebuild barrel
make ui-diff # report which primitives changed upstream (exit 1 if any)Staying current with shadcn — make ui-diff compares every primitive
against the live radix-lyra registry and exits non-zero when one has moved.
It normalises away everything the CLI would rewrite anyway (icon-library
placeholders, cn-* template classes, import aliases, prettier line-wrapping),
so what it prints is real change. Prefer it over shadcn add --diff, which
caps its output at five files per run.
A primitive lyra deliberately diverges from carries a customised note in
primitives.lock.json; ui-diff lists those separately instead of failing on
them forever. Document the divergence in a JSDoc block in the file too —
make ui-update will overwrite it, and that note is what tells the next person
to put it back.
Layout — src/<layer>/ with a barrel index.ts; one tsup entry per
subpath; ESM-only to dist/. Layers (enforced by eslint-plugin-boundaries):
utils/hooks (foundation) → ui → shell. No upward imports.
"use client" is not in source — it is injected onto the client entry
artifacts post-build by scripts/inject-use-client.mjs, then asserted by
scripts/verify-build-output.mjs. scripts/sync-ui.mjs adapts shadcn-CLI
output to repo conventions.
Release - bump version in package.json, commit, then push a tag
v<version> (git tag -a vX.Y.Z -m vX.Y.Z && git push origin vX.Y.Z). The tag
pipeline runs typecheck, lint, test and build, then the publish job pushes that
dist to the npm public registry. It refuses a tag that differs from
package.json, and skips a version already on npm. It needs NPM_TOKEN (an npm
automation token) as a protected, masked CI variable and v* as a protected tag.
pnpm release (npm login + build + publish) remains the manual fallback.
