WorkspaceSwitcher
The workspace switcher. Put it in AppShell's `headerSlot`, and the `rail` and `bar` variants in `collapsedHeaderSlot` and `mobileHeaderSlot`.
packages/ui/src/components/layout/workspace-switcher.tsx
@marktiderman/genesis-ui/layoutimport { WorkspaceSwitcher } from "@marktiderman/genesis-ui/layout";react-docgen-typescript.workspaceThemeStyle
The CSS variables for a workspace's brand (`workspace.theme.accent`): `--primary`, `--primary-foreground` and `--ring` pointed at an accessible shade of the accent, as `brandThemeStyle` does for a public page. Empty without a valid accent. The switcher puts it on each workspace's picture and row; an app can put the current workspace's on its shell to brand everything inside (pass `{ mode: "dark" }` when that shell renders dark, so `--primary-text` reads on the dark background).
No declared props.
WorkspaceSwitcher
The workspace switcher. Put it in AppShell's `headerSlot`, and the `rail` and `bar` variants in `collapsedHeaderSlot` and `mobileHeaderSlot`.
| Prop | Type | Default | Description |
|---|---|---|---|
| actions | readonly WorkspaceSwitcherAction[] | — | Typed items at the bottom of the menu, after a separator. |
| badgeLabel | ((workspace: W, value: string | number) => string) | — | What a screen reader hears for a badge, in place of the bare value. Default: "3 new" for a number, the text itself otherwise. |
| className | string | — | |
| classNames | Partial<Record<WorkspaceSwitcherPart, string>> | — | A class for each part. `className` is the same as `classNames.root`. |
| current | Workspace | — | The current workspace; defaults to the nearest WorkspaceScope's. |
| defaultOpen | boolean | false | Whether the menu starts open, uncontrolled. |
| emptyText | ReactNode | No workspaces found | Shown when a search matches nothing. Default "No workspaces found". |
| footer | ReactNode | ((mode: "search" | "menu") => ReactNode) | — | The menu's last items, after `actions`. In the menu they are menu items (`DropdownMenuItem`); with search they must be plain links or buttons, since there is no menu around them. Pass a function to render each mode's own: `(mode) => mode === "menu" ? <DropdownMenuItem … /> : <a … />`. |
| hrefFor | ((workspace: W) => string) | — | Where each choice goes; defaults to the WorkspaceScope's, else the workspace's landing page. |
| kindIcons | Partial<Record<keyof GenesisWorkspaceKinds, LucideIcon>> | — | Pictures for kinds without an image; merged over the defaults. |
| kindLabels | Partial<Record<keyof GenesisWorkspaceKinds, string | null>> | — | Headings over each kind's group; merged over the defaults. `null` hides a heading. |
| label | string | Switch workspace | Accessible name of the trigger. Default "Switch workspace". |
| linkComponent | LinkComponent | ({ href, children, testID, ...rest }) => ( <a href={href} data-testid={testID} {...rest}> {children} </a> ) | The router's link (see AppShell's `linkComponent`). Each row is this link with the menu item's or option's props merged on, so it must pass `ref`, `id`, `role`, `aria-*`, `tabIndex`, `onClick`, `onMouseMove`, `onKeyDown`, `style` and `data-*` through to its `<a>` (see `LinkComponent`). |
| onNavigate | ((href: string, workspace: W) => void) | — | How a keyboard jump (`shortcuts.jump`) goes to a workspace: pass the router's navigate. Without it a jump is a full page load of the link (a menu click still uses `linkComponent`), and the switcher warns in development. |
| onOpenChange | ((open: boolean) => void) | — | |
| onSelect | ((workspace: W) => void) | — | Called whenever the viewer picks a workspace, from the menu or the keyboard. |
| open | boolean | — | Whether the menu is open, to control it. |
| order | readonly (keyof GenesisWorkspaceKinds)[] | — | The order of the kinds in the menu (default personal, roll-up, tenants). |
| placeholder | string | Choose a workspace | Shown when the URL is in no workspace. Default "Choose a workspace". |
| renderBadge | ((workspace: W) => ReactNode) | — | Replaces a workspace's badge (default: its `badge`, as a pill). Shorthand for `slots.badge`. A custom badge owns its screen-reader text: `badgeLabel` reaches only the default one. |
| renderImage | ((workspace: W, size: "sm" | "md") => ReactNode) | — | Replaces the picture (a brand mark, a colored tile). Shorthand for `slots.image`. |
| renderItem | ((workspace: W, state: { current: boolean; }) => ReactNode) | — | Replaces a row's content in the menu (the link around it stays). Shorthand for `slots.item`. |
| search | boolean | "auto" | false | A search box over the list, which then becomes a combobox (see the module comment). Default `false`. `"auto"` turns it on past {@link WORKSPACE_SWITCHER_SEARCH_THRESHOLD} workspaces. The highlight starts on the first match, not the current workspace (as in cmdk), so opening and pressing Enter goes to the first one. |
| searchPlaceholder | string | Find a workspace | The search box's placeholder and accessible name. Default "Find a workspace". |
| shortcuts | WorkspaceSwitcherShortcuts | — | Keyboard shortcuts to open the menu and to jump to a workspace. Off by default. |
| slotProps | WorkspaceSwitcherSlotProps<W> | — | More props for a part, including the `trigger` button and the menu `content`. |
| slots | WorkspaceSwitcherSlots<W> | — | Replace or drop a part. |
| variant | enum | sidebar | `sidebar` (default): the full row for `headerSlot`. `rail`: the picture alone, for the collapsed rail's `collapsedHeaderSlot`. `bar`: the name and a chevron, for the phone's top bar. |
| workspaces | readonly W[] | — | Every workspace; defaults to the nearest WorkspaceScope's. |
WORKSPACE_SWITCHER_PARTS
Every part, in document order; see {@link WorkspaceSwitcherPart}.
No declared props.
WORKSPACE_SWITCHER_SCOPE
The value of every part's `data-scope`.
No declared props.
WORKSPACE_SWITCHER_SEARCH_THRESHOLD
With a switcher's `search="auto"`, past this many workspaces it opens with a search box. On the web and the phone.
No declared props.
DEFAULT_WORKSPACE_KIND_ICONS
The default picture for a kind with no image of its own; tenants show their initials.
No declared props.