SettingsDialog
A settings window: sections on the left, one pane on the right, and an optional search that jumps to a row. It lives in its own entry point, @adecore/ui/settings, with the parts a pane is built from.
import { SettingsDialog } from '@adecore/ui/settings';import { Button, Icon, Select, Switch } from '@adecore/ui';
import { MasterDetail, MasterItem, SettingsDialog, SettingsRow, SettingsSection, type SettingsSearchResult } from '@adecore/ui/settings';
import { Bell, Info, Keyboard, Palette, Settings, Sparkles } from 'lucide-react';
import { useState } from 'react';
function AppearancePane() {
const [theme, setTheme] = useState('system');
const [compact, setCompact] = useState(false);
return (
<SettingsSection title="Window" description="How the app looks on this computer.">
<SettingsRow
label="Theme"
searchId="theme"
control={
<Select
label="Theme"
value={theme}
onValueChange={setTheme}
items={[
{ value: 'system', label: 'Match the system' },
{ value: 'light', label: 'Light' },
{ value: 'dark', label: 'Dark' }
]}
/>
}
/>
<SettingsRow
label="Compact rows"
description="Fits more on a small screen."
searchId="compact"
control={<Switch label="Compact rows" checked={compact} onCheckedChange={setCompact} />}
/>
</SettingsSection>
);
}
function NotificationsPane() {
const [sounds, setSounds] = useState(true);
return (
<SettingsSection title="Alerts">
<SettingsRow label="Play a sound" searchId="sound" control={<Switch label="Play a sound" checked={sounds} onCheckedChange={setSounds} />} />
</SettingsSection>
);
}
const SHORTCUT_GROUPS = ['General', 'Editing', 'Navigation'];
function ShortcutsPane() {
const [picked, setPicked] = useState('General');
return (
<MasterDetail
listWidth={280}
listLabel="Shortcut groups"
list={SHORTCUT_GROUPS.map((group) => (
<MasterItem key={group} selected={picked === group} onSelect={() => setPicked(group)}>
{group}
</MasterItem>
))}
detail={<p className="text-sm text-text-muted">The shortcuts of {picked.toLowerCase()} go here.</p>}
/>
);
}
function AboutHero() {
return (
<div className="flex flex-col items-center gap-1.5 bg-surface-sunken px-8 pt-28 pb-12 text-center">
<Icon icon={Sparkles} size={20} className="mb-2 text-accent" />
<h3 className="text-lg font-semibold text-text">Example</h3>
<p className="text-xs text-text-muted">Version 1.0.0</p>
</div>
);
}
const DETAILS = [
{ label: 'Electron', value: '38.2.0' },
{ label: 'Chromium', value: '140.0.7339' },
{ label: 'Node', value: '22.19.0' },
{ label: 'Platform', value: 'macOS' }
];
const LINKS = ['Website', 'Source code', 'Report a problem'];
function AboutPane() {
const [automatic, setAutomatic] = useState(true);
return (
<>
<SettingsSection title="Updates">
<SettingsRow
label="Download updates by themselves"
control={<Switch label="Download updates by themselves" checked={automatic} onCheckedChange={setAutomatic} />}
/>
</SettingsSection>
<SettingsSection title="Details">
{DETAILS.map((row) => (
<SettingsRow key={row.label} label={row.label} control={<span className="text-xs text-text-muted">{row.value}</span>} />
))}
</SettingsSection>
<SettingsSection title="Links">
{LINKS.map((link) => (
<SettingsRow
key={link}
label={link}
control={
<Button variant="secondary" size="sm">
Open
</Button>
}
/>
))}
</SettingsSection>
</>
);
}
const GROUPS = [
{
label: null,
sections: [
{ id: 'appearance', icon: Palette, label: 'Appearance', description: 'Theme and density.', pane: AppearancePane },
{ id: 'notifications', icon: Bell, label: 'Notifications', description: 'What asks for your attention.', pane: NotificationsPane }
]
},
{
label: 'Advanced',
sections: [{ id: 'shortcuts', icon: Keyboard, label: 'Shortcuts', description: 'Every key the app knows.', pane: ShortcutsPane, split: true }]
}
];
const FOOTER = [{ id: 'about', icon: Info, label: 'About', description: 'The version you run.', pane: AboutPane, hero: AboutHero }];
const SEARCHABLE: SettingsSearchResult[] = [
{ section: 'appearance', id: null, label: 'Appearance' },
{ section: 'appearance', id: 'theme', label: 'Theme' },
{ section: 'appearance', id: 'compact', label: 'Compact rows' },
{ section: 'notifications', id: 'sound', label: 'Play a sound' },
{ section: 'shortcuts', id: null, label: 'Shortcuts' }
];
const search = {
find: (query: string) => SEARCHABLE.filter((result) => result.label.toLowerCase().includes(query.trim().toLowerCase())),
hint: '⌘F'
};
export default function SettingsDialogDemo() {
const [open, setOpen] = useState(false);
const [section, setSection] = useState('appearance');
const [target, setTarget] = useState<string | null>(null);
return (
<>
<Button variant="secondary" onClick={() => setOpen(true)}>
<Icon icon={Settings} size={14} />
Open settings
</Button>
<SettingsDialog
heading={
<span className="grid size-5 place-items-center rounded-md bg-accent text-accent-text">
<Icon icon={Sparkles} size={12} />
</span>
}
open={open}
onOpenChange={setOpen}
section={section}
onNavigate={(next) => {
setSection(next.section);
setTarget(next.target ?? null);
}}
groups={GROUPS}
footer={FOOTER}
search={search}
target={target}
onTargetShown={() => setTarget(null)}
/>
</>
);
}Sections and panes
groups is the navigation, in order, each group with an optional label. footer sections sit at the foot of the navigation. A section names a pane component, rendered only while open, inside a Suspense and an ErrorBoundary. A lazy pane loads on first open.
A pane is a padded, scrolling column. A split section gets the full height instead, for a MasterDetail.
A section with a hero opens on that block, edge to edge, with the title bar floating over it. The bar fills in as the pane scrolls. It covers the top 86 pixels of the hero (more when the description wraps), so leave that room. A split section draws no hero.
You hold the open section. onNavigate fires when a person picks another.
Tabs in a pane
A pane with several pages draws SettingsTabs and the picked page under it. The tabs stand in the header, under the title, so they stay put while the pane scrolls:
import { SettingsTabs } from '@adecore/ui/settings';
<SettingsTabs
value={tab}
tabs={[
{ id: 'general', label: 'General' },
{ id: 'colors', label: 'Colors' }
]}
label="Editor pages"
onValueChange={setTab}
/>In a split pane, and outside the dialog, SettingsTabs stays where it is drawn, such as above a MasterDetail's detail. Its props are the exported type SettingsTabsProps.
Search
search.find(query) returns the results, so it can search your own words in any language. While the field holds a query, the results replace the navigation. A result names a section and optionally the searchId of a SettingsRow. Picking one calls onNavigate with the row as target. Pass it back as target. The row scrolls into view and flashes, then onTargetShown fires, where you clear it.
Escape clears the query first and closes the dialog only from an empty field. Enter jumps to the first result. search.hint prints the shortcut that focuses the field. search.focusAt focuses the field each time the number grows, so your shortcut handler can bump it.
An account at the foot
account adds one more section under the footer, with a tab you draw yourself, such as an avatar and a name. The tab is a Base UI Tabs.Tab (from @base-ui/react/tabs) with the section's id as value.
A mark beside the title
heading draws before the title of the navigation, such as the app's mark at 16 or 20 pixels. A screen reader skips it and reads the title alone.
<SettingsDialog heading={<AppMark size={16} />} open={open} onOpenChange={setOpen} ... />Another title
The dialog is titled "Settings" in the person's language. title names it otherwise, for the settings of one thing such as a project.
<SettingsDialog title="Project settings" open={open} onOpenChange={setOpen} ... />Narrow windows
The dialog is 1200 by 760 pixels and shrinks with the viewport. Under 960 pixels the navigation narrows; under 640 it becomes a select above the pane.
Props
| Prop | Type | Default | |
|---|---|---|---|
open | boolean | Required. | |
onOpenChange | (open: boolean) => void | Required. | |
section | string | Required. The id of the open section. | |
onNavigate | (next: { section: string; target?: string | null }) => void | Required. | |
groups | readonly SettingsGroupEntry[] | Required. { label: string | null; sections } | |
footer | readonly SettingsSectionEntry[] | [] | |
account | { section: SettingsSectionEntry; tab: ReactNode } | ||
heading | ReactNode | Before the title. | |
title | string | "Settings" | The title of the dialog, for the settings of one thing. |
search | SettingsSearch | { find(query), hint?, focusAt? } | |
target | string | null | null | The row a search result jumped to. |
onTargetShown | () => void | ||
className | string | On the popup. | |
ref | Ref<HTMLDivElement> |
A SettingsSectionEntry is { id, icon, label, description, pane, split?, hero? }, where the description is the line under the pane's title. A SettingsSearchResult is { section, id, label }, with id: null for a result that is the pane itself.
SettingsDialogProps, SettingsGroupEntry, SettingsSectionEntry, SettingsSearch and SettingsSearchResult are exported types.