A dashboard app shell — icon rail, one rounded content card, resizable space panels, one-row page
headers, list header menus, a Cmd/Ctrl+K search dialog and first-run intros — shipped as a
shadcn registry under the @cdlab namespace. Host apps
copy the code in with shadcn add and own it from then on. There is no npm package.
Stack: React 19, shadcn/ui on Base UI (base-nova), Tailwind v4. Routing through an adapter for
TanStack Router or Next.js (App Router, server rendered).
Demo: https://wuchendi.github.io/appshell/demo/
Add the registry to the host's components.json:
{ "registries": { "@cdlab": "https://wuchendi.github.io/appshell/r/{name}.json" } }/r/ is the latest release; /v{version}/r/ pins one and /next/r/ tracks main.
bunx shadcn add @cdlab/shell-router-tanstack # or @cdlab/shell-router-next — install exactly one
bunx shadcn add @cdlab/shell-layout # AppShell, rail, panels, PageHeader (pulls in shell-core)
bunx shadcn add @cdlab/shell-menus # Filter / Display menus, chips, header search
bunx shadcn add @cdlab/shell-search # Cmd/Ctrl+K dialog
bunx shadcn add @cdlab/shell-intro # first-run intro page
bunx shadcn add @cdlab/shell-collection # column table, batch bar, column switchesFiles land in shell/** — under src/ when the host has one — and import each other as
@/shell/..., so @/* must point at that root (./src/* or ./*). Both router items install
shell/router.tsx; shell-layout and shell-search import it and fail to compile without one.
shell-layout adds the progress-bar keyframes to the host stylesheet.
In a monorepo whose shadcn components live in a workspace package, the app's components.json
maps ui / utils to that package (e.g. "ui": "@acme/ui/components"); shadcn add rewrites
the shell's @/components/ui/* imports to it. cn is the npm package cn, added to the app's
dependencies and never rewritten, whatever utils points at.
The canvas behind the rail and the content card is var(--shell-canvas, var(--color-muted)). Set
--shell-canvas in the host theme (light and dark, however the host switches them) to pick
another color:
:root { --shell-canvas: oklch(0.965 0 0); }
.dark { --shell-canvas: oklch(0.11 0 0); }| Item | What it is |
|---|---|
shell-core |
Labels (en / zh) and their context, ShellSpace and path matching, the panel state context and its prefs cookie, the typing guard for bare-key shortcuts, J/K row navigation, the mobile hook, the fill-page context |
shell-router-tanstack / shell-router-next |
@/shell/router: ShellLink, useShellPathname, useShellNavigate, useShellNavigating |
shell-layout |
<AppShell>, Rail, PageHeader, PageBody, IconButton, PanelFrame / PanelSection / PanelRow / PanelAllRow, NavigationProgress |
shell-menus |
FilterMenu, DisplayMenu, MenuSection, MenuRow, MenuSwitch, Chips, ChipCount, ResetButton, HeaderSearch |
shell-search |
SearchDialog over the host's own search function plus a "Go to" list of the spaces |
shell-intro |
FeatureIntro, IntroArtCard, IntroArtArrow |
shell-collection |
CollectionTable (sticky header, sortable columns, select all, 36px rows that open on click / Enter, J/K, right-click menu, hover actions, narrow core columns, sub-rows, loading and empty states, inner scrolling in fill pages), CollectionPager and useCollectionPage, BatchBar, ColumnsSection; ShellColumn |
import { Boxes, Gauge, Settings } from 'lucide-react'
import { shellLabelsZh } from '@/shell/core/labels'
import { AppShell } from '@/shell/layout/app-shell'
import { PageHeader } from '@/shell/layout/page-header'
import { PanelFrame, PanelRow, PanelSection } from '@/shell/layout/panel'
const spaces = [
{ key: 'overview', href: '/', label: 'Overview', icon: Gauge, exact: true },
{ key: 'items', href: '/items', label: 'Items', icon: Boxes },
{
key: 'settings',
href: '/settings',
label: 'Settings',
icon: Settings,
footer: true,
},
]
function ItemsPanel() {
return (
<PanelFrame title="Items">
<PanelSection label="Views">
<PanelRow href="/items" icon={Boxes} active>
All items
</PanelRow>
</PanelSection>
</PanelFrame>
)
}
// TanStack Router: the root route's component.
export function Shell() {
return (
<AppShell
spaces={spaces}
panels={{ items: ItemsPanel }}
homeHref="/"
logo={<Logo />}
logoLabel="My app"
account={<AccountMenu />}
labels={shellLabelsZh}
newAction={{ label: 'New item', onSelect: openCreate }}
onSearch={() => setSearchOpen(true)}
>
<Outlet />
</AppShell>
)
}
// Every page starts with the one-row header.
<PageHeader
title="Items"
tools={<FilterMenu … />}
actions={<DisplayMenu …>…</DisplayMenu>}
/>Next.js (App Router): AppShell takes components and functions, so render it from a client
component, and read the prefs cookie in the server layout so the first render matches the client:
// app/layout.tsx (Server Component)
import { cookies } from 'next/headers'
import { shellLabelsZh } from '@/shell/core/labels'
import { readShellPrefs } from '@/shell/core/prefs'
import { Shell } from './shell' // "use client": the <AppShell> above, plus `prefs` and `labels` props
export default async function RootLayout({
children,
}: {
children: React.ReactNode
}) {
const prefs = readShellPrefs((await cookies()).toString())
return (
<html lang="zh">
<body>
<Shell prefs={prefs} labels={shellLabelsZh}>
{children}
</Shell>
</body>
</html>
)
}Reading cookies makes the routes under that layout dynamic. A statically prerendered host has no
request cookies: pass prefs="client" instead, and the shell renders the defaults, then applies the
cookie right after hydration without the fold animation. Every shipped component is a client
component; @/shell/core/labels, prefs, spaces and the collection helpers are plain modules a
Server Component can import.
-
Spaces are the rail entries. A space with a component in
panelsgets a panel beside its pages; folding never remounts the page. Whether the panel is open and its width (one for every space) live in theappshellcookie (readShellPrefs/shellPrefsCookie); without aprefsprop the shell readsdocument.cookiewhile rendering (client-only hosts), and withprefs="client"right after hydration (static hosts). A fixed object (prefs={{ panelOpen: false }}ortrue) starts every load in that state, whatever the cookie holds.useShellPanel()gives the open state and its setters. A rail entry navigates to its space'shref; only when that page is already shown and the space has a panel does the click fold or unfold the panel instead. From a detail page belowhrefthe entry goes back tohref, and a space without a panel always navigates. -
Locale-prefixed routes (next-intl
/[locale]/…): hrefs stay plain app paths. In your copy of@/shell/router(the Next adapter), takeLink,usePathnameanduseRouterfrom yourcreateNavigation()module instead of Next, so paths lose the locale on the way in and gain it on the way out:import { useLinkStatus } from 'next/link' import { Link as NextLink, usePathname, useRouter } from '@/i18n/navigation'
Active states,
navigate(), rail and panel links then work on/studiowhile the browser is on/zh/studio. Re-apply the import after eachshadcn add. -
Shortcuts: Cmd/Ctrl+B folds the panel, Cmd/Ctrl+K calls
onSearch, a bareC(ornewAction.key) runsnewAction. The panel edge folds the panel too. Bare keys (C,/inHeaderSearch, J/K) do nothing while typing, during IME composition or with focus in a modal dialog. -
Rail badges:
ShellSpace.badgesits at the entry icon's top right, e.g. an unread count; a number hides at 0. -
Current links:
ShellLinkis marked current only by thearia-currentit is given. The TanStack adapter drops the router's own active marking (aria-current,data-status, theactiveclass), which names a pending navigation's target before its page shows. -
Labels: every visible string comes from
labels(ShellLabels).shellLabelsEnandshellLabelsZhship with the shell; hosts on i18n build the object from their translations. -
Rows: give list rows
data-shell-rowandtabIndex={0}, thenuseRowNavigation(listRef)for J/K. -
Fill pages: by default the whole page scrolls under the pinned header. A list page that should keep its column header and pager on screen renders
<PageBody fill>as a direct child of its root, after<PageHeader>: the body takes the remaining height and aCollectionTablein it scrolls on its own (or use your ownScrollAreawithmin-h-0 flex-1). Content taller than the window still scrolls with the page. It is per page, so a detail page in the same space keeps the normal layout. -
Tables: describe columns as
ShellColumn<T>(the first is the primary column;widthis a grid track;sortKeymakes the header sort;corekeeps it on narrow screens;labelnames a column whoseheaderis not text in the display menu) and render<CollectionTable>; put<ColumnsSection>in the display menu and<BatchBar>after the list. Row checkboxes are named "Select {name}" fromgetRowLabel(else a text primary cell, else the id). A row opens on clicks in its own DOM only, so menus and dialogs rendered fromrowActions/renderSubRoware safe.renderSubRow={row => node | null}adds a full-width block under a row (you own the expanded state; J/K skips it),loadingshows skeleton rows andemptyreplaces the rows. Cells clip (plain text and numbers end with an ellipsis), rows grow past 36px for multi-line cells, and a table wider than its container scrolls sideways inside itself — the header follows, the actions stay pinned to the right edge, and the table never widens its parent card. -
Paging: client mode — sort and filter first, then
const { rows, pager } = useCollectionPage(sorted)and render<CollectionTable rows={rows}>followed by<CollectionPager {...pager} selected={n} />. Server mode — passpage,pageSize,total,onPageChange(andonPageSizeChange) to<CollectionPager>yourself and give the table the current page. "Select all" works on the rows the table has, i.e. the current page. -
Panels:
PanelRowtakeshref(a full app path, query included),iconordot(success,info,progress(pulsing),warning,danger,muted);insetkeeps a row without either aligned with the others. -
Routing: shell links and navigation go through
@/shell/router. On Next.js the progress bar follows navigations started by the shell — rail, panel rows, search — and by host code usingShellLink/useShellNavigate; plainnext/linkelsewhere does not drive it. -
Search: render
<SearchDialog>yourself (open state fromonSearch) and passsearch={(query, signal) => Promise<ShellSearchResult[]>}. While it is pending the dialog says so; a rejected search clears the results and showslabels.searchFailed.
Items are copied source, so upgrading a host means re-running shadcn add and reviewing the diff.
Without --overwrite, shadcn skips identical files and asks before replacing each file that
differs — shell files and UI components alike, even with -y. Answer yes for shell/** and no
for UI components you have edited. Without a terminal (CI) it stops at the first question and
writes nothing. With --overwrite it replaces everything, edited UI components included: commit
first, then restore those (git checkout -- packages/ui or wherever they live).
bun install
bun run check # lint + typecheck + unit tests with coverage + registry and demo builds
bun run registry:smoke # shadcn add every item into a Vite and a Next.js scratch host, typecheck + build (needs network)
bun run --cwd apps/shell-web dev| Path | |
|---|---|
registry/shell/** |
the shipped sources (same @/shell/... layout as in a host) |
registry.json |
registry items, their files and dependencies |
apps/shell-web |
the demo app; @/shell/* aliases into registry/shell, @/shell/router to the TanStack adapter |
MIT