App Shell.
A full-height app layout: a top bar with logo, context pickers and the account chip, a workspace rail, an optional list column, the main area and an optional inspector. On phones it becomes top bar, main and a bottom tab bar. The preview is the TurtleDeck dashboard.
"use client";
import * as React from "react";
import {
BoxIcon,
CodeIcon,
Grid3x3Icon,
HammerIcon,
HouseIcon,
ListChecksIcon,
LogOutIcon,
MapIcon,
PauseIcon,
PlayIcon,
PlusIcon,
SettingsIcon,
SquareTerminalIcon,
UserIcon,
UsersIcon,
} from "lucide-react";
import { AccountChip, AccountChipContent, AccountChipLabel, AccountChipTrigger } from "@/components/ui/account-chip";
import { Button } from "@/components/ui/button";
import { DropdownMenuItem, DropdownMenuSeparator } from "@/components/ui/dropdown-menu";
import { Eyebrow } from "@/components/ui/eyebrow";
import {
JobCard,
JobCardActions,
JobCardEyebrow,
JobCardFooter,
JobCardHeader,
JobCardProgress,
JobCardStats,
JobCardTimer,
JobCardTitle,
} from "@/components/ui/job-card";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { StatusDot } from "@/components/ui/status-dot";
import { StatusPill } from "@/components/ui/status-pill";
import { UsageMeter, UsageMeterGroup, UsageMeterGroupLabel } from "@/components/ui/usage-meter";
import { turtles } from "./data";
import { Fleet } from "./fleet";
import { Inspector } from "./inspector";
import { AppShell as Shell, type AppShellNavItem } from "./shell";
const nav: AppShellNavItem[] = [
{ id: "map", label: "Map", icon: MapIcon },
{ id: "programs", label: "Programs", icon: CodeIcon },
{ id: "jobs", label: "Jobs", icon: ListChecksIcon },
{ id: "build", label: "Build", icon: HammerIcon },
{ id: "storage", label: "Storage", icon: BoxIcon },
{ id: "craft", label: "Craft", icon: Grid3x3Icon },
{ id: "swarm", label: "Swarm", icon: UsersIcon },
{ id: "console", label: "Console", icon: SquareTerminalIcon },
];
const pinned: AppShellNavItem[] = [{ id: "settings", label: "Settings", icon: SettingsIcon }];
/** TurtleDeck's dashboard built on the AppShell layout from ./shell. */
export default function AppShell() {
const [active, setActive] = React.useState("map");
const [selected, setSelected] = React.useState("testy");
const turtle = turtles.find((t) => t.id === selected) ?? turtles[0];
return (
<Shell
logo={<Logo />}
context={
<>
<Select defaultValue="smp">
<SelectTrigger size="sm" aria-label="World" className="hidden max-w-44 sm:flex">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="smp">Survival SMP</SelectItem>
<SelectItem value="creative">Creative test</SelectItem>
</SelectContent>
</Select>
<StatusPill tone="online" className="hidden rounded-md border px-2.5 py-1.5 xl:inline-flex">
Relay online
</StatusPill>
</>
}
actions={
<>
<Select value={selected} onValueChange={setSelected}>
<SelectTrigger size="sm" aria-label="Turtle" className="border-primary font-display font-semibold md:hidden">
<SelectValue />
</SelectTrigger>
<SelectContent align="end">
{turtles.map((t) => (
<SelectItem key={t.id} value={t.id}>
{t.name}
</SelectItem>
))}
</SelectContent>
</Select>
<AccountChip>
<AccountChipTrigger name="Tim" plan="Pro" fallback="TH">
<UsageMeterGroup aria-label="AI allowance" className="hidden xl:flex">
<UsageMeterGroupLabel>AI allowance</UsageMeterGroupLabel>
<UsageMeter size="compact" label="5-hour" value={32} />
<UsageMeter size="compact" label="Week" value={18} />
</UsageMeterGroup>
</AccountChipTrigger>
<AccountChipContent>
<AccountChipLabel name="Tim" email="tim@thultz.dev" plan="Pro">
<UsageMeter label="5-hour" value={32} reset="Resets at 3:40 pm" />
<UsageMeter label="Week" value={18} reset="Resets Monday" />
</AccountChipLabel>
<DropdownMenuSeparator />
<DropdownMenuItem>
<UserIcon /> Account
</DropdownMenuItem>
<DropdownMenuItem>
<LogOutIcon /> Sign out
</DropdownMenuItem>
</AccountChipContent>
</AccountChip>
<Button size="sm" className="hidden lg:inline-flex">
<PlusIcon /> Link a turtle
</Button>
</>
}
nav={nav}
pinnedNav={pinned}
active={active}
onNavigate={setActive}
list={<Fleet selected={selected} onSelect={setSelected} />}
listLabel="Fleet"
inspector={<Inspector turtle={turtle} />}
inspectorLabel={`${turtle.name} controls`}
>
{active === "map" ? (
<MapView turtle={turtle} />
) : (
<div className="flex flex-1 flex-col gap-2 bg-grid p-6">
<Eyebrow>Workspace</Eyebrow>
<h1 className="text-3xl font-medium tracking-tight">
{[...nav, ...pinned].find((n) => n.id === active)?.label}
<span className="text-primary">.</span>
</h1>
<p className="text-sm text-muted-foreground">Nothing here in the demo. Try the map.</p>
</div>
)}
</Shell>
);
}
function Logo() {
return (
<span className="flex items-center gap-1.5 font-display text-lg font-bold tracking-tight">
turtle
<span className="rounded-sm border border-primary px-1.5 py-0.5 font-mono text-[10px] tracking-[0.15em] text-primary">
DECK
</span>
</span>
);
}
function MapView({ turtle }: { turtle: (typeof turtles)[number] }) {
const [paused, setPaused] = React.useState(false);
const [startedAt] = React.useState(() => Date.now() - 252_000);
return (
<div className="flex flex-1 flex-col">
<div className="relative flex flex-1 flex-col">
<div className="relative h-[300px] shrink-0 bg-[#0e1311] bg-grid md:h-auto md:min-h-[480px] md:flex-1">
<TunnelMap />
<div className="absolute top-3 left-3 flex flex-col gap-1 rounded-md border bg-card px-3 py-2 shadow-block-sm sm:top-4 sm:left-4">
<div className="flex items-center gap-2">
<StatusDot tone={turtle.status} />
<span className="font-display text-[15px] font-bold">{turtle.name}</span>
<span className="font-mono text-[10px] tracking-[0.12em] text-success uppercase">
{turtle.status === "offline" ? "Last known" : "Live"}
</span>
</div>
<span className="font-mono text-[11px] text-muted-foreground tabular-nums">
X {turtle.pos[0]} Y {turtle.pos[1]} Z {turtle.pos[2]} <span className="max-sm:hidden">Facing {turtle.facing}</span>
</span>
</div>
<div className="absolute top-4 right-4 hidden gap-2 lg:flex">
<Button size="sm" variant="outline">
Ores only
</Button>
<Button size="sm" variant="secondary">
Follow turtle
</Button>
</div>
</div>
<JobCard
aria-label="Current job"
className="m-3 sm:m-4 md:absolute md:bottom-4 md:left-1/2 md:z-10 md:m-0 md:w-[min(520px,calc(100%-2rem))] md:-translate-x-1/2"
>
<JobCardHeader>
<JobCardEyebrow>{paused ? "Paused" : "Running job"}</JobCardEyebrow>
<JobCardTitle>Strip mine, 3 branches of 32</JobCardTitle>
<JobCardTimer startedAt={paused ? null : startedAt} seconds={252} />
</JobCardHeader>
<JobCardProgress value={64} aria-label="Job progress" />
<JobCardFooter>
<JobCardStats>
<span>41/64 blocks</span>
<span>Ores 7</span>
<span>Fuel used 118</span>
</JobCardStats>
<JobCardActions>
<Button size="sm" variant="secondary" onClick={() => setPaused((p) => !p)}>
{paused ? <PlayIcon /> : <PauseIcon />}
{paused ? "Resume" : "Pause"}
</Button>
<Button size="sm" variant="destructive">
<HouseIcon /> Stop and come home
</Button>
</JobCardActions>
</JobCardFooter>
</JobCard>
</div>
<div className="flex h-11 shrink-0 items-center gap-3 border-t bg-card px-4">
<Eyebrow>Console</Eyebrow>
<span className="min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground">
[14:02:11] Mined iron ore at 121 12 -352. Following the vein (2 blocks).
</span>
</div>
</div>
);
}
/** A top-down sketch of the tunnel: mapped blocks, the path so far and the turtle. */
function TunnelMap() {
const cells: { x: number; y: number; fill: string }[] = [];
for (let x = 0; x < 16; x++) {
for (let y = 0; y < 9; y++) {
if (y === 4 && x <= 10) continue;
const ore = (x * 7 + y * 3) % 23 === 0 ? "#c9a98d" : (x * 5 + y * 11) % 31 === 0 ? "#8fd6cf" : null;
cells.push({ x, y, fill: ore ?? ((x + y) % 3 ? "#2a322d" : "#323b35") });
}
}
return (
<svg
viewBox="0 0 320 180"
role="img"
aria-label="Map of the tunnel, the turtle and mapped blocks"
className="absolute inset-0 m-auto h-full max-h-[420px] w-full max-w-[760px] p-6 md:pb-40"
>
{cells.map((c) => (
<rect key={`${c.x}-${c.y}`} x={c.x * 20 + 1} y={c.y * 20 + 1} width={18} height={18} rx={1} fill={c.fill} />
))}
<path d="M10 90 H210" stroke="#f5a665" strokeWidth="2" />
<path d="M210 90 H310" stroke="#f5a665" strokeWidth="2" strokeDasharray="5 6" opacity="0.6" />
<rect x={202} y={82} width={16} height={16} rx={2} fill="#f5a665" stroke="#3a2a1c" strokeWidth="2" />
</svg>
);
}"use client";
import * as React from "react";
import { EllipsisIcon, PanelLeftIcon } from "lucide-react";
import { cn } from "@/lib/utils";
import { AppRail, AppRailContent, AppRailFooter, AppRailItem } from "@/components/ui/app-rail";
import { BottomTabBar, BottomTabBarItem } from "@/components/ui/bottom-tab-bar";
import { Button } from "@/components/ui/button";
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
export type AppShellNavItem = {
id: string;
label: string;
icon: React.ComponentType<{ className?: string }>;
};
export type AppShellProps = {
/** Brand mark on the left of the top bar. */
logo: React.ReactNode;
/** Context pickers after the logo, e.g. a world Select and a relay status pill. */
context?: React.ReactNode;
/** Right side of the top bar, usually an AccountChip and a primary action. */
actions?: React.ReactNode;
nav: AppShellNavItem[];
/** Items pinned to the bottom of the rail, e.g. Settings. */
pinnedNav?: AppShellNavItem[];
active: string;
onNavigate: (id: string) => void;
/** Optional list column (a fleet, sites, scripts). A column from 1024px, a sheet below that. */
list?: React.ReactNode;
listLabel?: string;
/** Optional inspector. A right column from 1280px; below that it stacks under the main content. */
inspector?: React.ReactNode;
inspectorLabel?: string;
children: React.ReactNode;
className?: string;
};
function useMinWidth(px: number) {
return React.useSyncExternalStore(
(onChange) => {
const mql = window.matchMedia(`(min-width: ${px}px)`);
mql.addEventListener("change", onChange);
return () => mql.removeEventListener("change", onChange);
},
() => window.matchMedia(`(min-width: ${px}px)`).matches,
// Server render stacks the inspector; wide screens move it into its column after hydration.
() => false,
);
}
/**
* A full-height app layout: top bar, workspace rail, optional list column, main area and optional
* inspector. On phones it becomes top bar, main and a bottom tab bar.
*/
export function AppShell({
logo,
context,
actions,
nav,
pinnedNav = [],
active,
onNavigate,
list,
listLabel = "List",
inspector,
inspectorLabel = "Inspector",
children,
className,
}: AppShellProps) {
const wide = useMinWidth(1280);
const [listOpen, setListOpen] = React.useState(false);
const [moreOpen, setMoreOpen] = React.useState(false);
// Phones get four tabs and a More sheet when there are more than five destinations.
const all = [...nav, ...pinnedNav];
const tabs = all.length > 5 ? all.slice(0, 4) : all;
const overflow = all.length > 5 ? all.slice(4) : [];
const overflowActive = overflow.some((i) => i.id === active);
const go = (id: string) => {
onNavigate(id);
setMoreOpen(false);
};
return (
<div data-slot="app-shell" className={cn("flex h-svh min-h-0 flex-col bg-background", className)}>
<header className="flex h-14 shrink-0 items-center gap-3 border-b bg-card px-3 sm:gap-4 sm:px-4 lg:h-15">
{list && (
<Sheet open={listOpen} onOpenChange={setListOpen}>
<SheetTrigger asChild>
<Button variant="ghost" size="icon-sm" className="lg:hidden" aria-label={`Open ${listLabel.toLowerCase()}`}>
<PanelLeftIcon />
</Button>
</SheetTrigger>
<SheetContent side="left" className="w-[85vw] max-w-[300px] gap-0 p-0">
<SheetHeader className="border-b p-4">
<SheetTitle>{listLabel}</SheetTitle>
<SheetDescription className="sr-only">Pick an item to show it in the main view.</SheetDescription>
</SheetHeader>
<div className="min-h-0 flex-1 overflow-y-auto">{list}</div>
</SheetContent>
</Sheet>
)}
<div className="shrink-0">{logo}</div>
{context && <div className="flex min-w-0 items-center gap-3">{context}</div>}
<div className="ml-auto flex min-w-0 items-center gap-3">{actions}</div>
</header>
<div className="flex min-h-0 flex-1">
<AppRail aria-label="Workspaces" className="hidden md:flex">
<AppRailContent>
{nav.map((item) => (
<AppRailItem key={item.id} isActive={item.id === active} onClick={() => onNavigate(item.id)}>
<item.icon />
<span>{item.label}</span>
</AppRailItem>
))}
</AppRailContent>
{pinnedNav.length > 0 && (
<AppRailFooter>
{pinnedNav.map((item) => (
<AppRailItem key={item.id} isActive={item.id === active} onClick={() => onNavigate(item.id)}>
<item.icon />
<span>{item.label}</span>
</AppRailItem>
))}
</AppRailFooter>
)}
</AppRail>
{list && (
<aside aria-label={listLabel} className="hidden w-[268px] shrink-0 flex-col overflow-y-auto border-r lg:flex">
{list}
</aside>
)}
<main className="flex min-w-0 flex-1 flex-col overflow-y-auto">
{children}
{inspector && !wide && (
<section aria-label={inspectorLabel} className="border-t bg-card">
{inspector}
</section>
)}
</main>
{inspector && wide && (
<aside aria-label={inspectorLabel} className="w-[332px] shrink-0 overflow-y-auto border-l bg-card">
{inspector}
</aside>
)}
</div>
<BottomTabBar aria-label="Sections" className="shrink-0 md:hidden">
{tabs.map((item) => (
<BottomTabBarItem key={item.id} isActive={item.id === active} onClick={() => go(item.id)}>
<item.icon />
<span>{item.label}</span>
</BottomTabBarItem>
))}
{overflow.length > 0 && (
<Sheet open={moreOpen} onOpenChange={setMoreOpen}>
<SheetTrigger asChild>
<BottomTabBarItem isActive={overflowActive}>
<EllipsisIcon />
<span>More</span>
</BottomTabBarItem>
</SheetTrigger>
<SheetContent side="bottom" className="gap-0 pb-[max(env(safe-area-inset-bottom),1rem)]">
<SheetHeader className="p-4">
<SheetTitle>More</SheetTitle>
<SheetDescription className="sr-only">Other workspaces</SheetDescription>
</SheetHeader>
<nav aria-label="More workspaces" className="grid grid-cols-3 gap-2 px-4">
{overflow.map((item) => (
<Button
key={item.id}
variant={item.id === active ? "secondary" : "outline"}
aria-current={item.id === active ? "page" : undefined}
className={cn("h-16 flex-col gap-1.5", item.id === active && "border-primary text-primary")}
onClick={() => go(item.id)}
>
<item.icon />
<span className="font-mono text-[10px] tracking-[0.08em] uppercase">{item.label}</span>
</Button>
))}
</nav>
</SheetContent>
</Sheet>
)}
</BottomTabBar>
</div>
);
}"use client";
import { SearchIcon } from "lucide-react";
import * as React from "react";
import { Button } from "@/components/ui/button";
import {
EntityCard,
EntityCardBar,
EntityCardDescription,
EntityCardHeader,
EntityCardList,
EntityCardMeta,
EntityCardTag,
EntityCardTitle,
} from "@/components/ui/entity-card";
import { Eyebrow } from "@/components/ui/eyebrow";
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group";
import { StatusDot } from "@/components/ui/status-dot";
import { turtles } from "./data";
export function Fleet({ selected, onSelect }: { selected: string; onSelect: (id: string) => void }) {
const [query, setQuery] = React.useState("");
const shown = turtles.filter((t) => t.name.toLowerCase().includes(query.trim().toLowerCase()));
const online = turtles.filter((t) => t.status !== "offline").length;
return (
<div className="flex min-h-full flex-col gap-3 p-4">
<div className="flex items-baseline justify-between gap-2">
<Eyebrow>Fleet / {turtles.length} turtles</Eyebrow>
<span className="font-mono text-[10px] tracking-[0.12em] text-muted-foreground uppercase">{online} online</span>
</div>
<InputGroup className="h-9">
<InputGroupAddon>
<SearchIcon />
</InputGroupAddon>
<InputGroupInput
type="search"
placeholder="Find a turtle"
aria-label="Find a turtle"
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
</InputGroup>
<EntityCardList aria-label="Turtles">
{shown.map((t) => (
<EntityCard key={t.id} selected={selected === t.id} onClick={() => onSelect(t.id)}>
<EntityCardHeader>
<StatusDot tone={t.status} pulse={t.status !== "offline"} />
<EntityCardTitle>{t.name}</EntityCardTitle>
<EntityCardTag>{t.status}</EntityCardTag>
</EntityCardHeader>
<EntityCardDescription>{t.job}</EntityCardDescription>
<EntityCardMeta>
<span>{t.pos.join(" ")}</span>
<span>Fuel {t.fuel}%</span>
</EntityCardMeta>
<EntityCardBar value={t.fuel} />
</EntityCard>
))}
{shown.length === 0 && <p className="py-4 text-center text-xs text-muted-foreground">No turtle called that.</p>}
</EntityCardList>
<div className="mt-auto rounded-md border border-dashed border-input p-3 text-xs leading-relaxed text-muted-foreground">
Updates ready: <span className="text-foreground">2 turtles</span> on v1.8.
<Button size="sm" variant="secondary" className="mt-2 flex h-7">
Update
</Button>
</div>
</div>
);
}"use client";
import * as React from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { ControlPad } from "@/components/ui/control-pad";
import { EntityCardBar } from "@/components/ui/entity-card";
import { Eyebrow } from "@/components/ui/eyebrow";
import { InventoryGrid, InventorySlot } from "@/components/ui/inventory-grid";
import { Stat, StatGroup, StatLabel, StatValue } from "@/components/ui/stat";
import { inventory, type Turtle } from "./data";
const tools = ["Dig", "Place", "Suck", "Drop", "Inspect", "Attack"];
export function Inspector({ turtle }: { turtle: Turtle }) {
const [slot, setSlot] = React.useState<number | null>(0);
const offline = turtle.status === "offline";
return (
<div className="flex flex-col gap-6 p-4 sm:p-5">
<div className="flex flex-col gap-2.5">
<Eyebrow>01 / Status</Eyebrow>
<StatGroup variant="tiles" className="grid-cols-3">
<Stat>
<StatLabel>Fuel</StatLabel>
<StatValue>{turtle.fuelUnits.toLocaleString("en-US")}</StatValue>
</Stat>
<Stat>
<StatLabel>Home</StatLabel>
<StatValue>{turtle.home}</StatValue>
</Stat>
<Stat>
<StatLabel>Slots</StatLabel>
<StatValue>{turtle.slots}</StatValue>
</Stat>
</StatGroup>
<EntityCardBar value={turtle.fuel} aria-label={`Fuel ${turtle.fuel}%`} />
</div>
<div className="flex flex-col gap-2.5">
<Eyebrow>02 / Move</Eyebrow>
<ControlPad
keyboard="pad"
disabled={offline}
showHints={false}
onAction={(_, action) => toast(`${turtle.name}: ${action.label.toLowerCase()}`)}
/>
<div className="grid grid-cols-3 gap-1.5">
{tools.map((t) => (
<Button key={t} size="sm" variant="outline" disabled={offline} className="max-sm:h-11">
{t}
</Button>
))}
</div>
</div>
<div className="flex flex-col gap-2.5">
<div className="flex items-baseline justify-between gap-2">
<Eyebrow>03 / Inventory</Eyebrow>
<span className="truncate font-mono text-[10px] tracking-[0.1em] text-muted-foreground uppercase">
Pickaxe, modem
</span>
</div>
<InventoryGrid aria-label={`${turtle.name} inventory`} value={slot} onValueChange={setSlot}>
{inventory.map((item, i) =>
item ? <InventorySlot key={i} name={item.name} count={item.count} color={item.color} /> : <InventorySlot key={i} />,
)}
</InventoryGrid>
</div>
<div className="grid grid-cols-3 gap-2">
{["Refuel", "Unload", "Go home"].map((a) => (
<Button key={a} size="sm" variant="secondary" disabled={offline} className="max-sm:h-11">
{a}
</Button>
))}
</div>
</div>
);
}export type Turtle = {
id: string;
name: string;
status: "online" | "busy" | "offline";
job: string;
pos: [number, number, number];
facing: string;
fuel: number;
fuelUnits: number;
home: string;
slots: string;
};
export const turtles: Turtle[] = [
{ id: "testy", name: "Testy", status: "online", job: "Strip mine 41/64", pos: [120, 12, -352], facing: "North", fuel: 72, fuelUnits: 3602, home: "43 m", slots: "6/16" },
{ id: "digger", name: "Digger", status: "online", job: "Idle at home", pos: [118, 64, -340], facing: "East", fuel: 91, fuelUnits: 4550, home: "0 m", slots: "2/16" },
{ id: "builder", name: "Builder-2", status: "busy", job: "Build layer 3/10", pos: [140, 70, -310], facing: "South", fuel: 44, fuelUnits: 2200, home: "51 m", slots: "11/16" },
{ id: "farmhand", name: "Farmhand", status: "offline", job: "Last seen 2h ago", pos: [96, 65, -300], facing: "West", fuel: 12, fuelUnits: 600, home: "22 m", slots: "14/16" },
];
export const inventory: ({ name: string; count: number; color: string } | null)[] = [
{ name: "Coal", count: 32, color: "#3a3f3c" },
{ name: "Torch", count: 20, color: "#e8c98a" },
{ name: "Cobble", count: 64, color: "#6d766f" },
{ name: "Iron", count: 11, color: "#c9a98d" },
{ name: "Diamond", count: 3, color: "#8fd6cf" },
{ name: "Gravel", count: 7, color: "#857d74" },
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
];Installation#
$npx lanterncn add app-shellThis copies all 5 files into components/app-shell and installs every component it uses. With the shadcn CLI: npx shadcn@latest add httptim/lantern-ui/app-shell.
Usage#
Render it from any page.
import AppShell from "@/components/app-shell/app-shell";
export default function Page() {
return <AppShell />;
}The layout lives in shell.tsx as AppShell and takes logo, context, actions, nav, pinnedNav, active, onNavigate, list, inspector and children. app-shell.tsx, fleet.tsx, inspector.tsx and data.ts are the TurtleDeck example built on it; replace them with your own content.
Breakpoints: the rail shows from 768px, the list column from 1024px (a left sheet opened from the top bar below that) and the inspector column from 1280px (stacked under the main content below that). Under 768px the rail becomes a bottom tab bar; with more than five destinations the last tab is More, which opens a sheet with the rest.
The shell is h-svh with its own scroll areas, so render it as the whole page. Put the world, turtle and similar pickers in context or actions as Select components.