shadcn.io is not affiliated with official shadcn/ui
Layout Switcher Command Menu Block for React
A dashboard configurator's layout switcher as a command menu docked at the end of the page: six layouts each with a greyscale diagram, a band that draws the highlighted one larger, and Enter to re-arrange the drawn dashboard, still under reduced motion.
Installation
Overview
Preview a layout before you switch to it with this layout switcher command menu for React with Base UI. It opens from the Dashboard panel of Slabgrid, a dashboard configurator, whose header holds an outline field with its ⌘ K cap, and the dashboard, a sidebar, a top bar and content drawn as shapes, sits under a soft scrim inside a hairline frame with a plus mark on each corner. The menu is the catalog Command, docked at the end of the page like a panel, with six layouts: Sidebar at the start, Sidebar at the end, Top bar, Split, Centred and Focus. Each row carries a small greyscale diagram of its arrangement, a name and a hint, and a tick on the one applied. A band at the top of the menu draws the highlighted layout larger with a sentence that says what it is, so moving through the list previews every layout in turn, and Enter applies the highlighted one: the menu closes and the drawn dashboard re-arranges, its column and row tracks sliding for a third of a second. Under reduced motion nothing slides and the new arrangement shows at once. The arrangements are logical, so a sidebar at the end sits at the other side in an RTL page. For preview the menu is drawn open in place when the page loads; the field, or Ctrl or ⌘ K while focus is in the block, opens the real command dialog with the same layout and query. For dashboards, editors and any product with a choice of page layout.
FAQ
Why is the menu already open, and what do I keep?
So you can see it without a click. On load the menu is the Command with its preview band drawn inline at the end of a picture of the dashboard, in a plain shell that is not modal, so nothing is trapped, hidden or focused and the page around the preview keeps working. The header's field opens the real command dialog, modal, with its focus trap, Escape and focus return, and the inline copy stays closed until a reload. Both show the same Palette and share the block's state, so the layout applied in the copy is the one the dialog opens on. In your app keep the dialog and drop the copy: the "in-place" state, the scrim with its shell and the Escape and blur effects.
How is a layout drawn and how does it move?
Every diagram is one CSS grid of three columns and two rows holding four regions: a sidebar, a top bar, the content and a second pane. A layout is only its track sizes and where each region sits, typed as literal classes, and the regions a layout drops fade out and park in a column with no width. Changing the layout changes grid-template-columns and grid-template-rows, which the browser animates over 300 ms. The row diagrams, the band and the dashboard behind the menu are the same component at three sizes, so they can never disagree.
What happens with reduced motion?
Nothing moves. The tracks and the fades have no transition under prefers-reduced-motion, so highlighting a layout swaps the band's diagram at once and applying one swaps the dashboard at once; the sentence beside the band says what the layout is, so no information depends on seeing the change happen. Nothing loops and nothing plays on load.
What does Enter change?
It applies the highlighted layout: the dashboard behind the menu takes the arrangement as the menu closes (you see it re-arrange, with no scrim over it), the row gets a tick and the words ", applied", the status line names the layout, and focus goes back to the field. Reopening the dialog starts its band on the applied layout. The highlight alone never applies anything.
What stays local, and how do I wire it?
All of it. The six layouts and the applied one are typed state in the block; nothing is saved and nothing leaves the page. In your app keep LAYOUTS as the rows, write the choice to your layout state or user settings in pick, and render your real dashboard with the same track classes so the diagram is a faithful preview.
Is it accessible from the keyboard?
Yes. Type to search by name, hint or word ("sidebar", "split", "centred", "focus"), the arrow keys move through the layouts and preview each, Enter applies the highlighted one and Escape closes the menu and puts focus on the field. Ctrl or ⌘ K opens the dialog while focus is inside the block, and only then. The rows are options of a cmdk listbox; the block turns off its own fuzzy filter and lists the rows itself. The diagrams are hidden from assistive technology; the band's sentence and each row's name and hint carry the same facts.
How does it look on a phone?
The drawn dashboard goes, since the menu covers most of it, and the band shows the diagram across the full width without its sentence (which is read out instead). The copy shown on load docks to the top of the page at full width, so the keyboard does not cover the foot; the key hints go and the count stays. The real dialog keeps the Command dialog's own phone layout.
Related
- Pro
Appearance Command Menu
Visual pickersA dashboard app's appearance menu shown open beside a live mini app: mode, corner radius, density and text size in four groups with a tick on each current choice, and a preview that restyles the moment you choose while the menu stays open.
- Pro
Motion Presets Command Menu
Visual pickersA motion tool's preset menu shown open over its transitions panel: easing curves, springs and durations each drawn as a 24 px curve, a track band that runs the highlighted preset's real CSS timing once on an arrow key or Replay, and a text reading under reduced motion.
- Pro
New Page Template Command Menu
Edit and insertA site builder's new-page menu shown open over its page tree: templates in five groups each with a drawn wireframe of six lines, a typed name that turns the list into Create from templates, and choosing one adds the page, with its slug, to the tree and selects it.
- AaAgAaAaAaPro
Font Picker Command Menu
Visual pickersA document editor's font menu hung from the toolbar's font name, with six system font stacks each set in its own real CSS stack, a specimen band that follows the highlight, a row of weights and an italic toggle, and Enter to set the document's font.
- Pro
Tone Picker Command Menu
Visual pickersA design tool's tone picker as a command menu shown open over its Fill row: an eleven-step grey ramp and recent tones, a HEX, RGB or HSL switch that rewrites every value and what Enter copies, and a band with the highlighted tone's contrast on white and on black.
- Pro
Design Tokens Command Menu
Visual pickersA design-system inspector's token picker as a command menu hung from a Fill field: tokens in groups with their resolved values and a small drawing, a box pane that wears whatever you apply, the alias chain of the last token, and a copy as CSS variable or JSON.