Skip to content
wuchendiPublic

About

Dashboard app shell as a shadcn registry: rail, space panels, page header, list menus, search, intro

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

appshell

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/

Install

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 switches

Files 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

Use

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 panels gets a panel beside its pages; folding never remounts the page. Whether the panel is open and its width (one for every space) live in the appshell cookie (readShellPrefs / shellPrefsCookie); without a prefs prop the shell reads document.cookie while rendering (client-only hosts), and with prefs="client" right after hydration (static hosts). A fixed object (prefs={{ panelOpen: false }} or true) 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's href; 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 below href the entry goes back to href, 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), take Link, usePathname and useRouter from your createNavigation() 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 /studio while the browser is on /zh/studio. Re-apply the import after each shadcn add.

  • Shortcuts: Cmd/Ctrl+B folds the panel, Cmd/Ctrl+K calls onSearch, a bare C (or newAction.key) runs newAction. The panel edge folds the panel too. Bare keys (C, / in HeaderSearch, J/K) do nothing while typing, during IME composition or with focus in a modal dialog.

  • Rail badges: ShellSpace.badge sits at the entry icon's top right, e.g. an unread count; a number hides at 0.

  • Current links: ShellLink is marked current only by the aria-current it is given. The TanStack adapter drops the router's own active marking (aria-current, data-status, the active class), which names a pending navigation's target before its page shows.

  • Labels: every visible string comes from labels (ShellLabels). shellLabelsEn and shellLabelsZh ship with the shell; hosts on i18n build the object from their translations.

  • Rows: give list rows data-shell-row and tabIndex={0}, then useRowNavigation(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 a CollectionTable in it scrolls on its own (or use your own ScrollArea with min-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; width is a grid track; sortKey makes the header sort; core keeps it on narrow screens; label names a column whose header is 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}" from getRowLabel (else a text primary cell, else the id). A row opens on clicks in its own DOM only, so menus and dialogs rendered from rowActions / renderSubRow are safe. renderSubRow={row => node | null} adds a full-width block under a row (you own the expanded state; J/K skips it), loading shows skeleton rows and empty replaces 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 — pass page, pageSize, total, onPageChange (and onPageSizeChange) 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: PanelRow takes href (a full app path, query included), icon or dot (success, info, progress (pulsing), warning, danger, muted); inset keeps 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 using ShellLink / useShellNavigate; plain next/link elsewhere does not drive it.

  • Search: render <SearchDialog> yourself (open state from onSearch) and pass search={(query, signal) => Promise<ShellSearchResult[]>}. While it is pending the dialog says so; a rejected search clears the results and shows labels.searchFailed.

Upgrade

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).

Develop

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

License

MIT

About

Dashboard app shell as a shadcn registry: rail, space panels, page header, list menus, search, intro

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages