Widgets in zones that people reorder (drag or arrow keys), resize, switch display and hide; an editor sheet with Add widgets, reset and an optional company default; saved to localStorage or your onChange with a save status.
Part of High Command Pro. The preview and props are open to everyone; installing it needs your license key. Set up your key · Pricing
$ npx shadcn@latest add @highcommand/dashboard-layoutCopies the source into your project and pulls in what it needs (3 other items). First time? Add the registry to components.json.
Provides a dashboard's layout state (visibility, order, size, display variant, saving) to the `Zone`s and layout editor beneath it.
schemarequiredDashboardSchema—The dashboard's zones and widgets.
childrenrequiredReactNode—The dashboard: `Zone`s, `EditLayoutButton` and the layout editor read this provider's state.
idstring"dashboard"Names the dashboard (grip ids, the default storage key).
rolestring | nullnullThe signed-in role: widgets limited to other roles never show.
storageKeystring | false—localStorage key for the person's layout (default `hq-layout:<id>`); false keeps it in memory (use `onChange`).
valueLayoutItem[] | null—The person's layout, when you hold it (null: the default).
onChange(items: LayoutItem[] | null) => void | Promise<unknown>—Called a moment after the last change with the new layout (null: reset). Return a promise to show Saving, Saved or the error.
companyLayoutItem[] | nullnullA shared default (an admin's) for anyone without a personal layout.
onSaveCompany(items: LayoutItem[] | null) => Promise<void>—Saves the shared default; when given, the editor offers "Save as company default".
defaultEditingbooleanfalseOpen in edit mode.
<Zone />8 propsA zone of the dashboard: its shown widgets in the person's order and sizes.zonerequiredstring—The zone's id in the schema.
renderrequiredRecord<string, (() => ReactNode) | undefined>—How each widget renders, by widget id (a widget without a renderer is left out).
classNamestring—Extra class names for the zone's container.
styleCSSProperties—Inline styles for the container, applied after the zone's own grid variables.
testidstring—Sets `data-testid` on the container.
emptyReactNode—Shown when no widget is (outside edit mode).
labelstring—Names the zone for assistive technology (a group).
phoneOrderRecord<string, number>—On a phone (stacked), an order for some widgets: 0 first, then 1, then 2, ties in layout order.
<EditLayoutButton />1 props"Edit layout": opens the editor (put it in the shell's `pageActions`); on a phone it shows as an icon with the same name.classNamestring—Extra class names for the button.
<LayoutEditor />2 propsThe editor sheet, shown while editing: every zone's widgets in order (drag or arrow keys to move, size, display, hide), the hidden ones to add back, reset, and (with `onSaveCompany` on the provider) the company default.titlestring"Customize this dashboard"The sheet's heading.
onOpen() => void—Called when the editor opens (close your panel stack here, as High Command does).
defaultLayout(s: DashboardSchema): LayoutItem[]The built-in default: every widget in schema order.
normalizeLayout(s: DashboardSchema, items: readonly LayoutItem[] | null | undefined): LayoutItem[]Make any stored list a valid layout of today's schema: unknown or repeated ids are dropped, a size the widget cannot take falls back to its default, locked widgets show, and widgets added since the layout was saved appear at their default place (after the widget that precedes them in the schema) with their default visibility. Several old ids renamed to one widget (figures merged into a group) keep the place of the first, shown if any of them was. Zones whose order is fixed keep schema order.
unknownWidgets(s: DashboardSchema, items: readonly LayoutItem[]): string[]Ids this dashboard does not have (a server would refuse them).
zoneItems(s: DashboardSchema, items: readonly LayoutItem[], zone: string, role: string | null | undefined): (LayoutItem & { def: WidgetDef; })[]The items of one zone (in layout order) that `role` may see.
setVisible(s: DashboardSchema, items: readonly LayoutItem[], id: string, visible: boolean): LayoutItem[]Show or hide one widget (locked widgets stay shown).
setVariant(s: DashboardSchema, items: readonly LayoutItem[], id: string, variant: string): LayoutItem[]Pick a widget's display option; the default (or one it does not offer) is stored as none.
setSize(s: DashboardSchema, items: readonly LayoutItem[], id: string, size: "1" | "2" | "third" | "half" | "two_thirds" | "full"): LayoutItem[]The layout with widget `id` set to `size`; unchanged if the widget is unknown or does not offer that size.
moveWidget(s: DashboardSchema, items: readonly LayoutItem[], id: string, to: number, role: string | null | undefined): LayoutItem[]Move a widget within its zone, among the widgets `role` sees and that are shown: `to` is its new position in that visible list (clamped). Hidden widgets and widgets of other zones keep their places. A zone whose order is fixed does not move.
dropIndex(from: number, onto: number, after: boolean): number | nullWhere a dropped widget lands: `from` is its index among the zone's shown widgets, `onto` the index of the widget it was dropped on, `after` whether it fell on that widget's far half. Returns the new index, or null when nothing moves.
widgetDef(s: DashboardSchema, id: string): WidgetDef | undefinedThe widget in the schema with this id, or undefined.
zoneDef(s: DashboardSchema, zone: string): ZoneDef | undefinedThe zone in the schema with this id, or undefined.
canSeeWidget(d: WidgetDef, role: string | null | undefined): booleanWhether `role` may see the widget: always when it names no roles, otherwise only when `role` is one of them.
variantOf(d: WidgetDef, it: Pick<LayoutItem, "variant"> | undefined): string | undefinedThe display option a widget shows in a layout: its stored variant, else its first.
resolveLayout(s: DashboardSchema, user: readonly LayoutItem[] | null | undefined, company: readonly LayoutItem[] | null | undefined): LayoutItem[]The layout a person sees: their own if saved, else the shared default (an admin's) if one is set, else the built-in default.
sameLayout(a: readonly LayoutItem[], b: readonly LayoutItem[]): booleanTwo layouts are the same arrangement (used to tell whether a person's layout differs from the default they would get).
nextSize(sizes: readonly ("1" | "2" | "third" | "half" | "two_thirds" | "full")[], cur: "1" | "2" | "third" | "half" | "two_thirds" | "full" | undefined): "1" | "2" | "third" | "half" | "two_thirds" | "full"The next size in a widget's list (the frame's size button cycles through them).
useDashboardLayout(): DashboardLayoutApiThe dashboard's layout for the signed-in person (role filtering included), and its edits. Read-only defaults without a provider.
useLayoutContext(): Ctx | nullThe raw context (null outside a provider).
useReorderKeys(api: DashboardLayoutApi, zone: string): (e: KeyboardEvent<Element>, it: ZoneItem) => voidKeyboard reorder on a grip: arrows move one place, Home and End to the ends. Shared by the page frames and the editor list.
useDragReorder(api: DashboardLayoutApi, zone: string, axis: "x" | "y" | "auto"): { drag: string | null; over: { id: string; after: boolean; } | null; onDragStart: (e: DragEvent<Element>, id: string) => void; onDragOver: (e: DragEvent…Pointer drag between the shown widgets of one zone (native drag and drop).