Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

refactor(ui): extract shared SettingsToggle, SegmentedControl, Checkbox primitives

vastsa75c4ff86ffbe
diff --git a/apps/desktop/src/AGENTS.md b/apps/desktop/src/AGENTS.md
new file mode 100644
index 000000000..4b7ea3e05
--- /dev/null
+++ b/apps/desktop/src/AGENTS.md
@@ -0,0 +1,53 @@
+# Renderer & UI — Agent Rules
+
+Scoped rules for `apps/desktop/src/`. These tighten the root `AGENTS.md`;
+on conflict the rules here win.
+
+---
+
+## Shared UI primitives are mandatory
+
+Every renderer component must use the shared primitives from
+`components/ui.tsx` and `components/settings/`. Inline reimplementation
+of any shared primitive is a spec violation.
+
+### Primitive catalog
+
+| Need | Component | Source |
+|---|---|---|
+| Button | `Button` | `components/ui.tsx` |
+| Text input | `Input` | `components/ui.tsx` |
+| Password input | `PasswordInput` | `components/ui.tsx` |
+| Textarea | `Textarea` | `components/ui.tsx` |
+| Form field (label + hint) | `Field` | `components/ui.tsx` |
+| Boolean toggle (switch) | `SettingsToggle` | `components/ui.tsx` |
+| Multi-option segment | `SegmentedControl` | `components/ui.tsx` |
+| Checkbox | `Checkbox` | `components/ui.tsx` |
+| Native dropdown (non-Settings) | `Select` | `components/ui.tsx` |
+| Settings dropdown | `SettingsMenuSelect` | `components/settings/SettingsMenuSelect.tsx` |
+| Status badge | `Badge` | `components/ui.tsx` |
+| Card container | `Panel` | `components/ui.tsx` |
+| Icon-only button with tooltip | `TooltipButton` | `components/ui.tsx` |
+| Inline help | `HelpIcon` | `components/ui.tsx` |
+| Settings layout | `SettingsCard`, `SettingsRow` | `features/settings/primitives.tsx` |
+
+### Prohibited patterns
+
+- `<button role="switch">` with manual `settings-toggle` class → use `SettingsToggle`
+- `<div className="settings-segment">` with manual button loop → use `SegmentedControl`
+- `<label><input type="checkbox"/>…</label>` → use `Checkbox`
+- `<select>` or `Select` in Settings pages → use `SettingsMenuSelect`
+- `<button className="btn-*">` with manual class assembly → use `Button`
+- `<span className="badge-*">` with manual class assembly → use `Badge`
+
+### When to add a new primitive
+
+Add to `components/ui.tsx` when the same pattern appears (or will appear)
+in three or more files. The new component must:
+
+1. Use existing CSS classes from `styles/ui-kit.css` or `styles/settings.css`
+2. Accept `className` for composition
+3. Include proper ARIA attributes
+4. Be exported from `components/ui.tsx` (or `components/settings/` for
+ Settings-specific primitives)
+5. Be documented in `docs/spec/04-ux/07-ui-design-system.md` §11
diff --git a/apps/desktop/src/components/extensions/McpEditorSheet.tsx b/apps/desktop/src/components/extensions/McpEditorSheet.tsx
index 61ea2e338..07da5316a 100644
--- a/apps/desktop/src/components/extensions/McpEditorSheet.tsx
+++ b/apps/desktop/src/components/extensions/McpEditorSheet.tsx
@@ -12,7 +12,7 @@ import {
type McpTransport,
type ProjectRecord,
} from "@pi-desktop/shared";
-import { Button, Field, HelpIcon, Input, TooltipButton, cx, portalOverlay } from "../ui";
+import { Button, Field, HelpIcon, Input, SettingsToggle, TooltipButton, cx, portalOverlay } from "../ui";
import { IconPlay, IconServer, IconTerminal, IconX } from "../icons";
import { ScopeControl } from "./ScopeControl";
import { KeyValueRows, pairsToRecord, recordToPairs, type KeyValuePair } from "./KeyValueRows";
@@ -186,16 +186,11 @@ function ManagementScope({
/>
</span>
</div>
- <button
- type="button"
- className={cx("settings-toggle", draft.enabled && "on")}
- role="switch"
- aria-checked={draft.enabled}
- aria-label={t("settings.enableCapability", { name: draft.label || draft.id })}
- onClick={() => setDraft({ ...draft, enabled: !draft.enabled })}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={draft.enabled}
+ label={t("settings.enableCapability", { name: draft.label || draft.id })}
+ onChange={() => setDraft({ ...draft, enabled: !draft.enabled })}
+ />
</div>
);
}
diff --git a/apps/desktop/src/components/plugins/PluginSettingsSheet.tsx b/apps/desktop/src/components/plugins/PluginSettingsSheet.tsx
index a3444c0b4..201d69979 100644
--- a/apps/desktop/src/components/plugins/PluginSettingsSheet.tsx
+++ b/apps/desktop/src/components/plugins/PluginSettingsSheet.tsx
@@ -15,7 +15,7 @@ import {
} from "@pi-desktop/shared";
import { api } from "../../lib/api";
import { useAppStore } from "../../stores/app-store";
-import { Button, HelpIcon, TooltipButton, cx, Input, Textarea } from "../ui";
+import { Button, HelpIcon, SettingsToggle, TooltipButton, cx, Input, Textarea } from "../ui";
import { IconKeyboard, IconSettings, IconX } from "../icons";
import { SettingsMenuSelect } from "../settings/SettingsMenuSelect";
@@ -203,16 +203,11 @@ export function PluginSettingsSheet({ plugin, platform, onClose, onSaved }: Prop
onChange={(event) => setValue(setting.key, event.target.value === "" ? 0 : Number(event.target.value))}
/>
) : setting.type === "boolean" ? (
- <button
- type="button"
- className={cx("settings-toggle", value === true && "on")}
- role="switch"
- aria-checked={value === true}
- aria-label={setting.title}
- onClick={() => setValue(setting.key, value !== true)}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={value === true}
+ label={setting.title}
+ onChange={() => setValue(setting.key, value !== true)}
+ />
) : setting.type === "select" ? (
<SettingsMenuSelect
label={setting.title}
diff --git a/apps/desktop/src/components/settings/AgentCapabilityLayout.tsx b/apps/desktop/src/components/settings/AgentCapabilityLayout.tsx
index c63a8892b..87f389886 100644
--- a/apps/desktop/src/components/settings/AgentCapabilityLayout.tsx
+++ b/apps/desktop/src/components/settings/AgentCapabilityLayout.tsx
@@ -8,7 +8,7 @@ import { useTranslation } from "react-i18next";
import type { ProjectRecord } from "@pi-desktop/shared";
import { api } from "../../lib/api";
import { useAppStore } from "../../stores/app-store";
-import { Button, TooltipButton, cx } from "../ui";
+import { Button, SegmentedControl, SettingsToggle, TooltipButton, cx } from "../ui";
import { AnchoredMenu } from "./AnchoredMenu";
import { SettingsMenuSelect } from "./SettingsMenuSelect";
import {
@@ -166,18 +166,13 @@ export function CapabilityToggle({
onChange: () => void;
}) {
return (
- <button
- type="button"
- className={cx("settings-toggle", checked && "on", busy && "is-busy")}
- role="switch"
- aria-checked={checked}
- aria-label={label}
- aria-busy={busy || undefined}
- disabled={disabled || busy}
- onClick={onChange}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={checked}
+ label={label}
+ busy={busy}
+ disabled={disabled}
+ onChange={onChange}
+ />
);
}
@@ -247,29 +242,17 @@ export function CapabilityToolbar({
return (
<div className="agent-capability-toolbar">
{filter && onFilterChange && segments.length > 0 ? (
- <div
- className="settings-segment agent-capability-segment"
- role="radiogroup"
- aria-label={t("settings.capabilityFilterLabel")}
- >
- {segments.map((segment) => (
- <button
- key={segment.id}
- type="button"
- role="radio"
- aria-checked={filter === segment.id}
- className={cx(
- "settings-segment-item",
- "agent-capability-segment-btn",
- filter === segment.id && "active",
- )}
- onClick={() => onFilterChange(segment.id)}
- >
- {segment.label}
- <span className="agent-capability-segment-count">{segment.count}</span>
- </button>
- ))}
- </div>
+ <SegmentedControl
+ value={filter}
+ onChange={(value) => onFilterChange(value)}
+ options={segments.map((segment) => ({
+ value: segment.id,
+ label: (<>{segment.label}<span className="agent-capability-segment-count">{segment.count}</span></>),
+ }))}
+ label={t("settings.capabilityFilterLabel")}
+ className="agent-capability-segment"
+ itemClassName="agent-capability-segment-btn"
+ />
) : null}
<div className="agent-capability-search-wrap">
<IconSearch size={13} aria-hidden="true" />
diff --git a/apps/desktop/src/components/settings/ConfigSyncPage.tsx b/apps/desktop/src/components/settings/ConfigSyncPage.tsx
index 520721b55..729f139c6 100644
--- a/apps/desktop/src/components/settings/ConfigSyncPage.tsx
+++ b/apps/desktop/src/components/settings/ConfigSyncPage.tsx
@@ -10,7 +10,7 @@ import type {
ConfigSyncState,
} from "@pi-desktop/shared";
import { api } from "../../lib/api";
-import { Badge, Button, Field, Input, PasswordInput, cx } from "../ui";
+import { Badge, Button, Field, Input, PasswordInput, SettingsToggle } from "../ui";
import { IconCloudDown, IconRefresh, IconShield, IconTrash } from "../icons";
import { SettingsCard, SettingsRow } from "../../features/settings/primitives";
import { configSyncProgressView } from "../../features/settings/config-sync-progress";
@@ -624,16 +624,11 @@ export function ConfigSyncPage() {
title={t("settings.configSync.pauseTitle")}
description={t("settings.configSync.pauseDescription")}
>
- <button
- type="button"
- className={cx("settings-toggle", state?.paused && "on")}
- role="switch"
- aria-checked={state?.paused === true}
- aria-label={t("settings.configSync.pauseTitle")}
- onClick={() => void togglePause()}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={state?.paused === true}
+ label={t("settings.configSync.pauseTitle")}
+ onChange={() => void togglePause()}
+ />
</SettingsRow>
)}
{!locked ? (
diff --git a/apps/desktop/src/components/settings/FontSizeRow.tsx b/apps/desktop/src/components/settings/FontSizeRow.tsx
index 0853ad0db..8fc833b75 100644
--- a/apps/desktop/src/components/settings/FontSizeRow.tsx
+++ b/apps/desktop/src/components/settings/FontSizeRow.tsx
@@ -7,7 +7,7 @@ import {
FONT_SCALE_STEP,
resolveFontScale,
} from "@pi-desktop/shared";
-import { cx } from "../ui";
+import { SegmentedControl } from "../ui";
import { SettingsRow } from "../../features/settings/primitives";
const PRESETS = [
@@ -44,27 +44,12 @@ export function FontSizeRow({
description={t("settings.fontSizeDesc")}
>
<div className="settings-font-size">
- <div
- className="settings-segment"
- role="radiogroup"
- aria-label={t("settings.fontSize")}
- >
- {PRESETS.map((preset) => (
- <button
- key={preset.scale}
- type="button"
- role="radio"
- aria-checked={current === preset.scale}
- className={cx(
- "settings-segment-item",
- current === preset.scale && "active",
- )}
- onClick={() => commit(preset.scale)}
- >
- {t(preset.key)}
- </button>
- ))}
- </div>
+ <SegmentedControl
+ value={String(current)}
+ onChange={(value) => commit(Number(value))}
+ options={PRESETS.map((preset) => ({ value: String(preset.scale), label: t(preset.key) }))}
+ label={t("settings.fontSize")}
+ />
<div className="settings-font-size-slider">
<input
type="range"
diff --git a/apps/desktop/src/components/settings/NetworkProxySection.tsx b/apps/desktop/src/components/settings/NetworkProxySection.tsx
index 3917d5d80..b32af3d07 100644
--- a/apps/desktop/src/components/settings/NetworkProxySection.tsx
+++ b/apps/desktop/src/components/settings/NetworkProxySection.tsx
@@ -14,7 +14,7 @@ import {
validateNetworkProxy,
} from "@pi-desktop/shared";
import { api } from "../../lib/api";
-import { Button, Input, cx } from "../ui";
+import { Button, Input, SegmentedControl, SettingsToggle, cx } from "../ui";
import { SettingsRow } from "../../features/settings/primitives";
const MODES: NetworkProxyMode[] = ["system", "direct", "custom"];
@@ -169,27 +169,15 @@ export function NetworkProxySection({
title={t("settings.proxy")}
description={t("settings.proxyDesc")}
>
- <div
- className="settings-segment"
- role="radiogroup"
- aria-label={t("settings.proxy")}
- >
- {MODES.map((mode) => (
- <button
- key={mode}
- type="button"
- role="radio"
- aria-checked={saved.mode === mode}
- className={cx(
- "settings-segment-item",
- saved.mode === mode && "active",
- )}
- onClick={() => chooseMode(mode)}
- >
- {t(`settings.proxy${mode[0]!.toUpperCase()}${mode.slice(1)}`)}
- </button>
- ))}
- </div>
+ <SegmentedControl
+ value={saved.mode}
+ onChange={(mode) => chooseMode(mode)}
+ options={MODES.map((mode) => ({
+ value: mode,
+ label: t(`settings.proxy${mode[0]!.toUpperCase()}${mode.slice(1)}`),
+ }))}
+ label={t("settings.proxy")}
+ />
</SettingsRow>
<SettingsRow
title={t("settings.networkRelaxedMode")}
@@ -199,18 +187,11 @@ export function NetworkProxySection({
: t("settings.networkRelaxedModeStrictDesc")
}
>
- <button
- type="button"
- className={cx("settings-toggle", relaxed && "on")}
- role="switch"
- aria-checked={relaxed}
- aria-label={t("settings.networkRelaxedMode")}
- onClick={() =>
- void persistNetworkPolicy(relaxed ? "strict" : "relaxed")
- }
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={relaxed}
+ label={t("settings.networkRelaxedMode")}
+ onChange={() => void persistNetworkPolicy(relaxed ? "strict" : "relaxed")}
+ />
</SettingsRow>
{saved.mode === "custom" ? (
diff --git a/apps/desktop/src/components/settings/RemoteHostsPage.tsx b/apps/desktop/src/components/settings/RemoteHostsPage.tsx
index 7c51aa231..c91ad1ab7 100644
--- a/apps/desktop/src/components/settings/RemoteHostsPage.tsx
+++ b/apps/desktop/src/components/settings/RemoteHostsPage.tsx
@@ -14,7 +14,7 @@ import { useTranslation } from "react-i18next";
import type { RemoteHostSshAuth, RemoteHostSummary } from "@pi-desktop/shared";
import { api } from "../../lib/api";
import { useAppStore } from "../../stores/app-store";
-import { Badge, Button, Field, Input, PasswordInput, cx } from "../ui";
+import { Badge, Button, Field, Input, PasswordInput, SegmentedControl, cx } from "../ui";
type AddMode = "ssh" | "pair";
@@ -241,29 +241,17 @@ export function RemoteHostsPage() {
<section className="settings-card-block">
<div className="settings-card-heading-row settings-remote-host-add-heading">
<h3 className="settings-card-heading">{t("settings.remoteHosts.addTitle")}</h3>
- <div
- className="settings-segment"
+ <SegmentedControl
+ value={addMode}
+ onChange={(mode) => setAddMode(mode)}
+ options={[
+ { value: "ssh", label: t("settings.remoteHosts.addSsh") },
+ { value: "pair", label: t("settings.remoteHosts.addPair") },
+ ]}
+ label={t("settings.remoteHosts.addTitle")}
role="tablist"
- aria-label={t("settings.remoteHosts.addTitle")}
- >
- {(["ssh", "pair"] as const).map((mode) => (
- <button
- key={mode}
- type="button"
- role="tab"
- id={`remote-host-add-${mode}`}
- aria-selected={addMode === mode}
- aria-controls={`remote-host-add-panel-${mode}`}
- className={cx("settings-segment-item", addMode === mode && "active")}
- disabled={busy}
- onClick={() => setAddMode(mode)}
- >
- {mode === "ssh"
- ? t("settings.remoteHosts.addSsh")
- : t("settings.remoteHosts.addPair")}
- </button>
- ))}
- </div>
+ disabled={busy}
+ />
</div>
<div className="settings-panel">
<form
@@ -340,31 +328,16 @@ export function RemoteHostsPage() {
>
{t("settings.remoteHosts.sshAuthMode")}
</div>
- <div
- className="settings-segment"
- role="radiogroup"
- aria-labelledby="settings-remote-host-auth-label"
- >
- {(["key", "password"] as const).map((auth) => (
- <button
- key={auth}
- type="button"
- role="radio"
- className={cx(
- "settings-segment-item",
- sshForm.auth === auth && "active",
- )}
- aria-checked={sshForm.auth === auth}
- aria-pressed={sshForm.auth === auth}
- disabled={installing}
- onClick={() => selectSshAuth(auth)}
- >
- {auth === "key"
- ? t("settings.remoteHosts.sshAuthKey")
- : t("settings.remoteHosts.sshAuthPassword")}
- </button>
- ))}
- </div>
+ <SegmentedControl
+ value={sshForm.auth}
+ onChange={(auth) => selectSshAuth(auth)}
+ options={[
+ { value: "key", label: t("settings.remoteHosts.sshAuthKey") },
+ { value: "password", label: t("settings.remoteHosts.sshAuthPassword") },
+ ]}
+ label={t("settings.remoteHosts.sshAuthMode")}
+ disabled={installing}
+ />
</div>
{sshForm.auth === "key" ? (
diff --git a/apps/desktop/src/components/settings/SkillEditorSheet.tsx b/apps/desktop/src/components/settings/SkillEditorSheet.tsx
index b2d2f6ccd..7697ab667 100644
--- a/apps/desktop/src/components/settings/SkillEditorSheet.tsx
+++ b/apps/desktop/src/components/settings/SkillEditorSheet.tsx
@@ -7,7 +7,7 @@ import {
type AgentCapabilityLevel,
type UserSkillRecord,
} from "@pi-desktop/shared";
-import { Button, Field, HelpIcon, Input, Textarea, TooltipButton, cx, portalOverlay } from "../ui";
+import { Button, Field, HelpIcon, Input, SettingsToggle, Textarea, TooltipButton, portalOverlay } from "../ui";
import { IconFolderOpen, IconX } from "../icons";
/** Hard cap host-core enforces on a skill document. */
@@ -130,16 +130,11 @@ function ManagementScope({
/>
</span>
</div>
- <button
- type="button"
- className={cx("settings-toggle", draft.enabled && "on")}
- role="switch"
- aria-checked={draft.enabled}
- aria-label={t("settings.enableCapability", { name: draft.name || draft.id })}
- onClick={() => setDraft({ ...draft, enabled: !draft.enabled })}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={draft.enabled}
+ label={t("settings.enableCapability", { name: draft.name || draft.id })}
+ onChange={() => setDraft({ ...draft, enabled: !draft.enabled })}
+ />
</div>
);
}
diff --git a/apps/desktop/src/components/settings/SubagentEditorSheet.tsx b/apps/desktop/src/components/settings/SubagentEditorSheet.tsx
index 8725bb713..325df202e 100644
--- a/apps/desktop/src/components/settings/SubagentEditorSheet.tsx
+++ b/apps/desktop/src/components/settings/SubagentEditorSheet.tsx
@@ -19,7 +19,7 @@ import {
type UserSubagentRecord,
} from "@pi-desktop/shared";
import { useAppStore } from "../../stores/app-store";
-import { Button, Field, HelpIcon, Input, Textarea, TooltipButton, cx, portalOverlay } from "../ui";
+import { Button, Field, HelpIcon, Input, SettingsToggle, Textarea, TooltipButton, cx, portalOverlay } from "../ui";
import { IconChevronRight, IconFolderOpen, IconX } from "../icons";
import {
groupSubagentModelChoices,
@@ -374,16 +374,11 @@ function ManagementScope({
<HelpIcon label={t("settings.subagentsOnlyGlobal")} />
</span>
</div>
- <button
- type="button"
- className={cx("settings-toggle", draft.enabled && "on")}
- role="switch"
- aria-checked={draft.enabled}
- aria-label={t("settings.enableCapability", { name: draft.name || draft.id })}
- onClick={() => setDraft({ ...draft, enabled: !draft.enabled })}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={draft.enabled}
+ label={t("settings.enableCapability", { name: draft.name || draft.id })}
+ onChange={() => setDraft({ ...draft, enabled: !draft.enabled })}
+ />
</div>
);
}
diff --git a/apps/desktop/src/components/settings/ThinkingDisplayModeRow.tsx b/apps/desktop/src/components/settings/ThinkingDisplayModeRow.tsx
index 03dd053e0..27c3afc76 100644
--- a/apps/desktop/src/components/settings/ThinkingDisplayModeRow.tsx
+++ b/apps/desktop/src/components/settings/ThinkingDisplayModeRow.tsx
@@ -2,7 +2,7 @@ import { useTranslation } from "react-i18next";
import type { AppSettings } from "@pi-desktop/shared";
import { resolveThinkingDisplayMode } from "../../lib/turn-process";
import { SettingsRow } from "../../features/settings/primitives";
-import { cx } from "../ui";
+import { SegmentedControl } from "../ui";
export function ThinkingDisplayModeRow({
settings,
@@ -18,32 +18,15 @@ export function ThinkingDisplayModeRow({
title={t("settings.thinkingDisplayMode")}
description={t("settings.thinkingDisplayModeDesc")}
>
- <div
- className="settings-segment"
- role="radiogroup"
- aria-label={t("settings.thinkingDisplayMode")}
- >
- {([
- ["detailed", "settings.thinkingDisplayDetailed"],
- ["compact", "settings.thinkingDisplayCompact"],
- ] as const).map(([value, labelKey]) => (
- <button
- key={value}
- type="button"
- role="radio"
- aria-checked={current === value}
- className={cx(
- "settings-segment-item",
- current === value && "active",
- )}
- onClick={() =>
- void saveSettings({ thinkingDisplayMode: resolveThinkingDisplayMode(value) })
- }
- >
- {t(labelKey)}
- </button>
- ))}
- </div>
+ <SegmentedControl
+ value={current}
+ onChange={(value) => void saveSettings({ thinkingDisplayMode: resolveThinkingDisplayMode(value) })}
+ options={[
+ { value: "detailed", label: t("settings.thinkingDisplayDetailed") },
+ { value: "compact", label: t("settings.thinkingDisplayCompact") },
+ ]}
+ label={t("settings.thinkingDisplayMode")}
+ />
</SettingsRow>
);
}
diff --git a/apps/desktop/src/components/ui.tsx b/apps/desktop/src/components/ui.tsx
index 463beb910..b4a0376fe 100644
--- a/apps/desktop/src/components/ui.tsx
+++ b/apps/desktop/src/components/ui.tsx
@@ -652,14 +652,113 @@ export function Panel({
return <div className={cx("panel-card", className)}>{children}</div>;
}
+export function SettingsToggle({
+ checked,
+ label,
+ busy,
+ disabled,
+ className,
+ onChange,
+}: {
+ checked: boolean;
+ label: string;
+ busy?: boolean;
+ disabled?: boolean;
+ className?: string;
+ onChange: () => void;
+}) {
+ return (
+ <button
+ type="button"
+ className={cx("settings-toggle", checked && "on", busy && "is-busy", className)}
+ role="switch"
+ aria-checked={checked}
+ aria-label={label}
+ aria-busy={busy || undefined}
+ disabled={disabled || busy}
+ onClick={onChange}
+ >
+ <span className="settings-toggle-thumb" />
+ </button>
+ );
+}
+
+export function SegmentedControl<T extends string>({
+ value,
+ onChange,
+ options,
+ label,
+ role = "radiogroup",
+ className,
+ itemClassName,
+ disabled,
+}: {
+ value: T;
+ onChange: (value: T) => void;
+ options: readonly { readonly value: T; readonly label: ReactNode }[];
+ label: string;
+ role?: "group" | "radiogroup" | "tablist";
+ className?: string;
+ itemClassName?: string;
+ disabled?: boolean;
+}) {
+ const itemRole = role === "tablist" ? "tab" : role === "radiogroup" ? "radio" : undefined;
+ return (
+ <div
+ className={cx("settings-segment", className)}
+ role={role}
+ aria-label={label}
+ >
+ {options.map((option) => (
+ <button
+ key={option.value}
+ type="button"
+ {...(itemRole === "tab"
+ ? { role: "tab", id: `${label}-tab-${option.value}`, "aria-selected": value === option.value }
+ : itemRole === "radio"
+ ? { role: "radio", "aria-checked": value === option.value }
+ : { "aria-pressed": value === option.value })}
+ className={cx(
+ "settings-segment-item",
+ value === option.value && "active",
+ itemClassName,
+ )}
+ disabled={disabled}
+ onClick={() => onChange(option.value)}
+ >
+ {option.label}
+ </button>
+ ))}
+ </div>
+ );
+}
+
+
+export function Checkbox({
+ label,
+ className,
+ ...props
+}: Omit<InputHTMLAttributes<HTMLInputElement>, "type"> & {
+ label: ReactNode;
+}) {
+ return (
+ <label className={cx("ui-checkbox", className)}>
+ <input type="checkbox" {...props} />
+ <span>{label}</span>
+ </label>
+ );
+}
+
export function Badge({
children,
tone = "neutral",
className,
+ style,
}: {
children: ReactNode;
tone?: "neutral" | "success" | "error" | "warning";
className?: string;
+ style?: React.CSSProperties;
}) {
return (
<span
@@ -671,6 +770,7 @@ export function Badge({
tone === "warning" && "badge-warning",
className,
)}
+ style={style}
>
{children}
</span>
diff --git a/apps/desktop/src/features/plugins/PluginDialogs.tsx b/apps/desktop/src/features/plugins/PluginDialogs.tsx
index efecd0b77..7f02a8c5e 100644
--- a/apps/desktop/src/features/plugins/PluginDialogs.tsx
+++ b/apps/desktop/src/features/plugins/PluginDialogs.tsx
@@ -1,4 +1,4 @@
-import { Button, cx } from "../../components/ui";
+import { Button, SettingsToggle, cx } from "../../components/ui";
import { IconCheck, IconShield, IconSparkles, IconTriangleAlert } from "../../components/icons";
import { PluginInstallDialog } from "../../components/plugins/PluginInstallDialog";
import { PluginSettingsSheet } from "../../components/plugins/PluginSettingsSheet";
@@ -127,19 +127,11 @@ export function PluginDialogs({
</div>
<div className="plugins-switch-row">
- <span className="plugins-switch-label">
- {t("plugins.enableAutoUpdateOnInstall")}
- </span>
- <button
- type="button"
- className={cx("settings-toggle", autoUpdate && "on")}
- role="switch"
- aria-checked={autoUpdate}
- aria-label={t("plugins.enableAutoUpdateOnInstall")}
- onClick={() => setAutoUpdate((on) => !on)}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={autoUpdate}
+ label={t("plugins.enableAutoUpdateOnInstall")}
+ onChange={() => setAutoUpdate((on) => !on)}
+ />
</div>
<div className="plugins-modal-actions">
diff --git a/apps/desktop/src/features/settings/SettingsPage.tsx b/apps/desktop/src/features/settings/SettingsPage.tsx
index a483b38bf..582ba67bf 100644
--- a/apps/desktop/src/features/settings/SettingsPage.tsx
+++ b/apps/desktop/src/features/settings/SettingsPage.tsx
@@ -33,7 +33,7 @@ import {
IconCloudDown,
IconMic,
} from "../../components/icons";
-import { Badge, Button, cx } from "../../components/ui";
+import { Badge, Button, cx, SegmentedControl, SettingsToggle } from "../../components/ui";
import { ModelConfigPage } from "../../components/settings/ModelConfigPage";
import { KeyboardShortcutsSection } from "../../components/settings/KeyboardShortcutsSection";
import { FontFamilyRow } from "../../components/settings/FontFamilyRow";
@@ -441,30 +441,17 @@ export function SettingsPage() {
<SettingsCard title={t("settings.defaultsTitle")}>
<SettingsRow title={t("settings.mode")} description={t("settings.modeDesc")}>
- <div
- className="settings-segment"
+ <SegmentedControl
+ value={settings.defaultMode ?? "agent"}
+ onChange={(value) => void saveSettings({ defaultMode: value })}
+ options={[
+ { value: "agent", label: t("settings.modeAgent") },
+ { value: "plan", label: t("settings.modePlan") },
+ { value: "goal", label: t("settings.modeGoal") },
+ ]}
+ label={t("settings.mode")}
role="group"
- aria-label={t("settings.mode")}
- >
- {([
- ["agent", "settings.modeAgent"],
- ["plan", "settings.modePlan"],
- ["goal", "settings.modeGoal"],
- ] as const).map(([value, labelKey]) => (
- <button
- key={value}
- type="button"
- className={cx(
- "settings-segment-item",
- settings.defaultMode === value && "active",
- )}
- aria-pressed={settings.defaultMode === value}
- onClick={() => void saveSettings({ defaultMode: value })}
- >
- {t(labelKey)}
- </button>
- ))}
- </div>
+ />
</SettingsRow>
<CommandShellRow settings={settings} saveSettings={saveSettings} />
<LinkOpenTargetRow settings={settings} saveSettings={saveSettings} />
@@ -477,62 +464,31 @@ export function SettingsPage() {
title={t("settings.enterToSend")}
description={t("settings.enterToSendDesc")}
>
- <button
- type="button"
- className={cx("settings-toggle", settings.enterToSend && "on")}
- role="switch"
- aria-checked={settings.enterToSend}
- aria-label={t("settings.enterToSend")}
- onClick={() =>
- void saveSettings({ enterToSend: !settings.enterToSend })
- }
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={settings.enterToSend}
+ label={t("settings.enterToSend")}
+ onChange={() => void saveSettings({ enterToSend: !settings.enterToSend })}
+ />
</SettingsRow>
<SettingsRow
title={t("settings.infiniteProviderRetry")}
description={t("settings.infiniteProviderRetryDesc")}
>
- <button
- type="button"
- className={cx(
- "settings-toggle",
- settings.infiniteProviderRetry === true && "on",
- )}
- role="switch"
- aria-checked={settings.infiniteProviderRetry === true}
- aria-label={t("settings.infiniteProviderRetry")}
- onClick={() =>
- void saveSettings({
- infiniteProviderRetry: settings.infiniteProviderRetry !== true,
- })
- }
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={settings.infiniteProviderRetry === true}
+ label={t("settings.infiniteProviderRetry")}
+ onChange={() => void saveSettings({ infiniteProviderRetry: settings.infiniteProviderRetry !== true })}
+ />
</SettingsRow>
<SettingsRow
title={t("settings.smoothStreaming")}
description={t("settings.smoothStreamingDesc")}
>
- <button
- type="button"
- className={cx(
- "settings-toggle",
- settings.smoothStreaming !== false && "on",
- )}
- role="switch"
- aria-checked={settings.smoothStreaming !== false}
- aria-label={t("settings.smoothStreaming")}
- onClick={() =>
- void saveSettings({
- smoothStreaming: !(settings.smoothStreaming !== false),
- })
- }
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={settings.smoothStreaming !== false}
+ label={t("settings.smoothStreaming")}
+ onChange={() => void saveSettings({ smoothStreaming: !(settings.smoothStreaming !== false) })}
+ />
</SettingsRow>
<LargePasteThresholdRow
settings={settings}
diff --git a/apps/desktop/src/features/settings/developer-sections.tsx b/apps/desktop/src/features/settings/developer-sections.tsx
index 1761d49e5..76d5ff942 100644
--- a/apps/desktop/src/features/settings/developer-sections.tsx
+++ b/apps/desktop/src/features/settings/developer-sections.tsx
@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
import type { AppSettings, CloseBehavior } from "@pi-desktop/shared";
import { useAppStore } from "../../stores/app-store";
import { api } from "../../lib/api";
-import { Button, cx } from "../../components/ui";
+import { Button, SegmentedControl, SettingsToggle } from "../../components/ui";
import { SettingsCard, SettingsRow } from "./primitives";
export function DeveloperSection({
@@ -31,16 +31,11 @@ export function DeveloperSection({
title={t("settings.developerMode")}
description={t("settings.developerModeDesc")}
>
- <button
- type="button"
- className={cx("settings-toggle", enabled && "on")}
- role="switch"
- aria-checked={enabled}
- aria-label={t("settings.developerMode")}
- onClick={() => void saveSettings({ developerMode: !enabled })}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={enabled}
+ label={t("settings.developerMode")}
+ onChange={() => void saveSettings({ developerMode: !enabled })}
+ />
</SettingsRow>
<SettingsRow
title={t("settings.devTools")}
@@ -100,28 +95,12 @@ export function CloseBehaviorSection() {
title={t("settings.closeBehaviorTitle")}
description={t("settings.closeBehaviorDesc")}
>
- <div
- className="settings-segment"
- role="radiogroup"
- aria-label={t("settings.closeBehaviorTitle")}
- >
- {options.map(([value, labelKey]) => (
- <button
- key={value}
- type="button"
- role="radio"
- aria-checked={behavior === value}
- aria-label={t(labelKey)}
- className={cx(
- "settings-segment-item",
- behavior === value && "active",
- )}
- onClick={() => void choose(value)}
- >
- {t(labelKey)}
- </button>
- ))}
- </div>
+ <SegmentedControl<CloseBehavior>
+ value={behavior ?? ("" as CloseBehavior)}
+ onChange={(value) => void choose(value)}
+ options={options.map(([value, labelKey]) => ({ value, label: t(labelKey) }))}
+ label={t("settings.closeBehaviorTitle")}
+ />
</SettingsRow>
{saveError ? (
<span className="settings-command-shell-state error" role="status">
diff --git a/apps/desktop/src/features/settings/import-page.tsx b/apps/desktop/src/features/settings/import-page.tsx
index e57b0a95a..aecf4cdcb 100644
--- a/apps/desktop/src/features/settings/import-page.tsx
+++ b/apps/desktop/src/features/settings/import-page.tsx
@@ -32,7 +32,7 @@ import {
groupImportCandidates,
type ImportGroupBy,
} from "../../lib/import-groups";
-import { Badge, Button, HelpIcon, cx } from "../../components/ui";
+import { Badge, Button, HelpIcon, SegmentedControl, cx } from "../../components/ui";
import { IconChevronLeft, IconDownload } from "../../components/icons";
import { SettingsMenuSelect } from "../../components/settings/SettingsMenuSelect";
@@ -56,30 +56,18 @@ export function ImportSection() {
return (
<div className="import-page">
- <div
- className="settings-segment import-segment"
+ <SegmentedControl
+ value={kind}
+ onChange={(value) => setKind(value)}
+ options={IMPORT_KINDS.map((entry) => ({
+ value: entry.id,
+ label: t(entry.labelKey),
+ }))}
+ label={t("settings.import")}
role="tablist"
- aria-label={t("settings.import")}
- >
- {IMPORT_KINDS.map((entry) => (
- <button
- key={entry.id}
- type="button"
- role="tab"
- id={`import-tab-${entry.id}`}
- aria-selected={kind === entry.id}
- aria-controls={`import-panel-${entry.id}`}
- className={cx(
- "settings-segment-item",
- "import-segment-btn",
- kind === entry.id && "active",
- )}
- onClick={() => setKind(entry.id)}
- >
- {t(entry.labelKey)}
- </button>
- ))}
- </div>
+ className="import-segment"
+ itemClassName="import-segment-btn"
+ />
{IMPORT_KINDS.map((entry) => (
<div
diff --git a/apps/desktop/src/features/settings/primitives.tsx b/apps/desktop/src/features/settings/primitives.tsx
index a48537f8f..28e7bbbfa 100644
--- a/apps/desktop/src/features/settings/primitives.tsx
+++ b/apps/desktop/src/features/settings/primitives.tsx
@@ -12,7 +12,7 @@ import {
} from "@pi-desktop/shared";
import { api } from "../../lib/api";
import { resolveContextUsageDisplay } from "../../lib/context-usage";
-import { HelpIcon, Input, cx } from "../../components/ui";
+import { HelpIcon, Input, SegmentedControl } from "../../components/ui";
import { SettingsMenuSelect } from "../../components/settings/SettingsMenuSelect";
/**
@@ -227,29 +227,16 @@ export function LinkOpenTargetRow({
const current = settings.linkOpenTarget ?? "workpanel";
return (
<SettingsRow title={t("settings.linkOpenTarget")}>
- <div
- className="settings-segment"
+ <SegmentedControl
+ value={current}
+ onChange={(value) => void saveSettings({ linkOpenTarget: value })}
+ options={[
+ { value: "workpanel", label: t("settings.linkOpenTargetWorkpanel") },
+ { value: "external", label: t("settings.linkOpenTargetExternal") },
+ ]}
+ label={t("settings.linkOpenTarget")}
role="group"
- aria-label={t("settings.linkOpenTarget")}
- >
- {([
- ["workpanel", "settings.linkOpenTargetWorkpanel"],
- ["external", "settings.linkOpenTargetExternal"],
- ] as const).map(([value, labelKey]) => (
- <button
- key={value}
- type="button"
- className={cx(
- "settings-segment-item",
- current === value && "active",
- )}
- aria-pressed={current === value}
- onClick={() => void saveSettings({ linkOpenTarget: value })}
- >
- {t(labelKey)}
- </button>
- ))}
- </div>
+ />
</SettingsRow>
);
}
@@ -270,30 +257,15 @@ export function ContextUsageDisplayRow({
const current = resolveContextUsageDisplay(settings.contextUsageDisplay);
return (
<SettingsRow title={t("settings.contextUsageDisplay")}>
- <div
- className="settings-segment"
- role="radiogroup"
- aria-label={t("settings.contextUsageDisplay")}
- >
- {([
- ["remaining", "settings.contextUsageDisplayRemaining"],
- ["used", "settings.contextUsageDisplayUsed"],
- ] as const).map(([value, labelKey]) => (
- <button
- key={value}
- type="button"
- role="radio"
- aria-checked={current === value}
- className={cx(
- "settings-segment-item",
- current === value && "active",
- )}
- onClick={() => void saveSettings({ contextUsageDisplay: value })}
- >
- {t(labelKey)}
- </button>
- ))}
- </div>
+ <SegmentedControl
+ value={current}
+ onChange={(value) => void saveSettings({ contextUsageDisplay: value })}
+ options={[
+ { value: "remaining", label: t("settings.contextUsageDisplayRemaining") },
+ { value: "used", label: t("settings.contextUsageDisplayUsed") },
+ ]}
+ label={t("settings.contextUsageDisplay")}
+ />
</SettingsRow>
);
}
diff --git a/apps/desktop/src/features/settings/voice/VoiceSettingsSection.tsx b/apps/desktop/src/features/settings/voice/VoiceSettingsSection.tsx
index 07cd79cbb..d1a0cbf4a 100644
--- a/apps/desktop/src/features/settings/voice/VoiceSettingsSection.tsx
+++ b/apps/desktop/src/features/settings/voice/VoiceSettingsSection.tsx
@@ -1,11 +1,13 @@
/**
- * Voice settings panel — matches the project's SettingsRow/SettingsCard pattern.
+ * Voice settings panel — uses project-standard SettingsRow, SettingsCard,
+ * SettingsToggle, Select (field-select), and Button components.
*/
import { useCallback, useEffect, useState } from "react";
import type { TFunction } from "i18next";
import type { AppSettings } from "@pi-desktop/shared";
-import { cx } from "../../../components/ui";
+import { Button, Badge, Checkbox, SettingsToggle } from "../../../components/ui";
+import { SettingsMenuSelect } from "../../../components/settings/SettingsMenuSelect";
import { SettingsRow, SettingsCard } from "../primitives";
import { voiceIpc } from "../../voice/voice-ipc";
@@ -52,9 +54,18 @@ export function VoiceSettingsSection({
const [permission, setPermission] = useState<string>("undetermined");
useEffect(() => {
- voiceIpc.getDevices().then((d) => setDevices(Array.isArray(d) ? d as AudioInputDevice[] : [])).catch(() => {});
- voiceIpc.getModels().then((m) => setModels(Array.isArray(m) ? m as ModelState[] : [])).catch(() => {});
- voiceIpc.checkPermission().then((p) => setPermission(typeof p === "string" ? p : "undetermined")).catch(() => {});
+ voiceIpc
+ .getDevices()
+ .then((d) => setDevices(Array.isArray(d) ? d as AudioInputDevice[] : []))
+ .catch(() => {});
+ voiceIpc
+ .getModels()
+ .then((m) => setModels(Array.isArray(m) ? m as ModelState[] : []))
+ .catch(() => {});
+ voiceIpc
+ .checkPermission()
+ .then((p) => setPermission(typeof p === "string" ? p : "undetermined"))
+ .catch(() => {});
}, []);
useEffect(() => {
@@ -62,7 +73,11 @@ export function VoiceSettingsSection({
setModels((prev) =>
prev.map((m) =>
m.info.id === modelId
- ? { ...m, status: progress >= 1 ? "downloaded" : "downloading", downloadProgress: progress }
+ ? {
+ ...m,
+ status: progress >= 1 ? "downloaded" : "downloading",
+ downloadProgress: progress,
+ }
: m,
),
);
@@ -85,142 +100,168 @@ export function VoiceSettingsSection({
return (
<div className="settings-stack">
- {/* Enable toggle */}
+ {/* ---- Enable ---- */}
<SettingsCard title={t("settings.voice")}>
<SettingsRow title={t("settings.voiceEnable")}>
- <button
- type="button"
- className={cx("settings-toggle", voice.enabled && "on")}
- role="switch"
- aria-checked={voice.enabled}
- aria-label={t("settings.voiceEnable")}
- onClick={() => save({ enabled: !voice.enabled })}
- >
- <span className="settings-toggle-thumb" />
- </button>
+ <SettingsToggle
+ checked={voice.enabled}
+ label={t("settings.voiceEnable")}
+ onChange={() => save({ enabled: !voice.enabled })}
+ />
</SettingsRow>
</SettingsCard>
- {/* Permission warning */}
+ {/* ---- Permission warning ---- */}
{permission === "denied" && (
<SettingsCard title={t("settings.voiceMicDenied")}>
<SettingsRow title={t("settings.voiceMicDeniedDesc")}>
- <button
- type="button"
- className="settings-btn-secondary"
+ <Button
+ size="sm"
+ variant="secondary"
onClick={() => voiceIpc.requestPermission()}
>
{t("settings.voiceOpenSystemSettings")}
- </button>
+ </Button>
</SettingsRow>
</SettingsCard>
)}
- {/* Microphone + Language + Chinese variant */}
+ {/* ---- Input ---- */}
<SettingsCard title={t("settings.voiceMicrophone")}>
<SettingsRow title={t("settings.voiceMicrophone")}>
- <select
- className="settings-select"
+ <SettingsMenuSelect
value={voice.deviceId ?? ""}
+ label={t("settings.voiceMicrophone")}
disabled={!voice.enabled}
- onChange={(e) => save({ deviceId: e.target.value || null })}
- >
- <option value="">{t("settings.voiceSystemDefault")}</option>
- {devices.map((d) => (
- <option key={d.deviceId} value={d.deviceId}>{d.label}</option>
- ))}
- </select>
+ options={[
+ { id: "", label: t("settings.voiceSystemDefault") },
+ ...devices.map((d) => ({ id: d.deviceId, label: d.label })),
+ ]}
+ onChange={(id) => save({ deviceId: id || null })}
+ />
</SettingsRow>
<SettingsRow title={t("settings.voiceLanguages")}>
<div className="voice-lang-checks">
{(["zh", "en", "ja", "ko"] as const).map((code) => (
- <label key={code} className="voice-lang-label">
- <input
- type="checkbox"
- checked={voice.languages.includes(code)}
- disabled={!voice.enabled}
- onChange={(e) => {
- const langs = e.target.checked
- ? [...voice.languages, code]
- : voice.languages.filter((l: string) => l !== code);
- save({ languages: langs.length > 0 ? langs : [code] });
- }}
- />
- {code === "zh" ? "中文" : code === "en" ? "English" : code === "ja" ? "日本語" : "한국어"}
- </label>
+ <Checkbox
+ key={code}
+ className="voice-lang-label"
+ checked={voice.languages.includes(code)}
+ disabled={!voice.enabled}
+ onChange={(e) => {
+ const langs = e.target.checked
+ ? [...voice.languages, code]
+ : voice.languages.filter((l: string) => l !== code);
+ save({ languages: langs.length > 0 ? langs : [code] });
+ }}
+ label={({ zh: "中文", en: "English", ja: "日本語", ko: "한국어" } as const)[code]}
+ />
))}
</div>
</SettingsRow>
<SettingsRow title={t("settings.voiceChineseVariant")}>
- <select
- className="settings-select"
+ <SettingsMenuSelect
value={voice.chineseVariant}
+ label={t("settings.voiceChineseVariant")}
disabled={!voice.enabled}
- onChange={(e) => save({ chineseVariant: e.target.value })}
- >
- <option value="simplified">{t("settings.voiceSimplified")}</option>
- <option value="traditional-taiwan">{t("settings.voiceTraditionalTaiwan")}</option>
- <option value="traditional-hong-kong">{t("settings.voiceTraditionalHK")}</option>
- </select>
+ options={[
+ { id: "simplified", label: t("settings.voiceSimplified") },
+ { id: "traditional-taiwan", label: t("settings.voiceTraditionalTaiwan") },
+ { id: "traditional-hong-kong", label: t("settings.voiceTraditionalHK") },
+ ]}
+ onChange={(id) => save({ chineseVariant: id })}
+ />
</SettingsRow>
</SettingsCard>
- {/* Model selection + management */}
+ {/* ---- Model ---- */}
<SettingsCard title={t("settings.voiceModel")}>
<SettingsRow title={t("settings.voiceModel")}>
- <select
- className="settings-select"
+ <SettingsMenuSelect
value={voice.modelId}
+ label={t("settings.voiceModel")}
disabled={!voice.enabled}
- onChange={(e) => save({ modelId: e.target.value })}
- >
- <option value="">{t("settings.voiceNoModelSelected")}</option>
- {models.map((m) => (
- <option key={m.info.id} value={m.info.id}>
- {m.info.name}{m.info.recommended ? " ★" : ""}
- {m.status === "downloaded" || m.status === "loaded" ? " ✓" : ""}
- </option>
- ))}
- </select>
+ options={[
+ { id: "", label: t("settings.voiceNoModelSelected") },
+ ...models.map((m) => ({
+ id: m.info.id,
+ label: `${m.info.name}${m.info.recommended ? " ★" : ""}${m.status === "downloaded" || m.status === "loaded" ? " ✓" : ""}`,
+ })),
+ ]}
+ onChange={(id) => save({ modelId: id })}
+ />
</SettingsRow>
- {/* Model list */}
{models.map((m) => (
- <SettingsRow key={m.info.id} title={m.info.name} description={`${formatSize(m.info.sizeBytes)}${m.info.recommended ? " · Recommended" : ""}`}>
+ <SettingsRow
+ key={m.info.id}
+ title={m.info.name}
+ detail={
+ <>
+ {formatSize(m.info.sizeBytes)}
+ {m.info.recommended ? (
+ <Badge tone="success" style={{ marginLeft: 6 }}>
+ Recommended
+ </Badge>
+ ) : null}
+ </>
+ }
+ >
{m.status === "downloaded" || m.status === "loaded" ? (
<div className="voice-model-actions">
- <span className="voice-model-badge voice-model-ok">{t("settings.voiceModelDownloaded")}</span>
- <button
- type="button"
- className="voice-model-btn voice-model-btn-danger"
+ <Badge tone="success">
+ {t("settings.voiceModelDownloaded")}
+ </Badge>
+ <Button
+ size="sm"
+ variant="ghost"
onClick={() => {
void voiceIpc.deleteModel(m.info.id);
- setModels((prev) => prev.map((x) => x.info.id === m.info.id ? { ...x, status: "not-downloaded" } : x));
+ setModels((prev) =>
+ prev.map((x) =>
+ x.info.id === m.info.id
+ ? { ...x, status: "not-downloaded" }
+ : x,
+ ),
+ );
}}
>
{t("settings.voiceModelDelete")}
- </button>
+ </Button>
</div>
) : m.status === "downloading" ? (
<div className="voice-model-actions">
<div className="voice-progress-track">
- <div className="voice-progress-fill" style={{ width: `${(m.downloadProgress ?? 0) * 100}%` }} />
+ <div
+ className="voice-progress-fill"
+ style={{
+ width: `${(m.downloadProgress ?? 0) * 100}%`,
+ }}
+ />
</div>
- <span className="voice-model-badge">{Math.round((m.downloadProgress ?? 0) * 100)}%</span>
+ <span className="voice-progress-label">
+ {Math.round((m.downloadProgress ?? 0) * 100)}%
+ </span>
</div>
) : (
- <button
- type="button"
- className="voice-model-btn voice-model-btn-primary"
+ <Button
+ size="sm"
+ variant="secondary"
onClick={() => {
void voiceIpc.downloadModel(m.info.id);
- setModels((prev) => prev.map((x) => x.info.id === m.info.id ? { ...x, status: "downloading", downloadProgress: 0 } : x));
+ setModels((prev) =>
+ prev.map((x) =>
+ x.info.id === m.info.id
+ ? { ...x, status: "downloading", downloadProgress: 0 }
+ : x,
+ ),
+ );
}}
>
{t("settings.voiceModelDownload")}
- </button>
+ </Button>
)}
</SettingsRow>
))}
diff --git a/apps/desktop/src/pages/ProjectsPage.tsx b/apps/desktop/src/pages/ProjectsPage.tsx
index d83e86bea..b8531dfc7 100644
--- a/apps/desktop/src/pages/ProjectsPage.tsx
+++ b/apps/desktop/src/pages/ProjectsPage.tsx
@@ -4,7 +4,7 @@ import type { ProjectGroupRecord } from "@pi-desktop/shared";
import { ErrorCodes } from "@pi-desktop/shared";
import { useAppStore } from "../stores/app-store";
import { api } from "../lib/api";
-import { Button, TooltipButton, cx } from "../components/ui";
+import { Button, TooltipButton, SegmentedControl, cx } from "../components/ui";
import {
IconArchive,
IconArchiveRestore,
@@ -385,27 +385,18 @@ export function ProjectsPage() {
return (
<div className="settings-stack">
<div className="projects-toolbar">
- <div
- className="settings-segment projects-sort"
+ <SegmentedControl
+ value={sort}
+ onChange={(mode) => setSort(mode)}
+ options={[
+ { value: "recent", label: t("project.sortRecent") },
+ { value: "name", label: t("project.sortName") },
+ ]}
+ label={t("project.sortBy")}
role="group"
- aria-label={t("project.sortBy")}
- >
- {(["recent", "name"] as const).map((mode) => (
- <button
- key={mode}
- type="button"
- className={cx(
- "settings-segment-item",
- "projects-sort-btn",
- sort === mode && "active",
- )}
- aria-pressed={sort === mode}
- onClick={() => setSort(mode)}
- >
- {t(mode === "recent" ? "project.sortRecent" : "project.sortName")}
- </button>
- ))}
- </div>
+ className="projects-sort"
+ itemClassName="projects-sort-btn"
+ />
<div className="projects-search-wrap">
<IconSearch size={14} aria-hidden="true" />
<input
diff --git a/docs/spec/04-ux/06-settings-ia.md b/docs/spec/04-ux/06-settings-ia.md
index 3da69ee94..f015b447a 100644
--- a/docs/spec/04-ux/06-settings-ia.md
+++ b/docs/spec/04-ux/06-settings-ia.md
@@ -805,9 +805,10 @@ system while preserving their different data ownership:
clearing the search restores the complete index
14. Info renders disabled, checking, up-to-date, available, downloading,
downloaded, and error update states without adding another destination
-15. Native select option lists remain readable in both light and dark themes,
- including when Chromium delegates the opened list surface to Windows; the
- same global rule covers non-Settings native selects
+15. Settings dropdowns use `SettingsMenuSelect` (anchored menu), never native
+ `<select>`. Native select option lists outside Settings remain readable in
+ both light and dark themes, including when Chromium delegates the opened
+ list surface to Windows
16. Shortcut recording rejects modifier-free non-function keys, reserved
editor/OS chords, and conflicts; successful overrides immediately drive
app behavior and macOS menu accelerators and survive restart
@@ -843,6 +844,17 @@ system while preserving their different data ownership:
27. The Skills page Market view browses public-HTTPS catalogs, previews
the assembled document, and installs only through `skills.create`; oversized
expanded documents are refused and source badges follow `sourceId`
+28. All Settings UI must use shared primitives from `components/ui.tsx` and
+ `components/settings/`:
+ - Boolean toggles → `SettingsToggle` (not inline `<button role="switch">`)
+ - Multi-option selectors → `SegmentedControl` (not inline
+ `<div className="settings-segment">` with manual button loops)
+ - Dropdowns → `SettingsMenuSelect` (not native `Select` / `<select>`)
+ - Checkboxes → `Checkbox` (not inline `<label><input type="checkbox">`)
+ - Buttons → `Button` (not raw `<button>` with manual class names)
+ - Status indicators → `Badge` (not inline `<span>` with manual classes)
+ - Layout → `SettingsCard` + `SettingsRow` from `features/settings/primitives`
+ Inline reimplementation of any shared primitive is a spec violation.
## 5. General chrome metrics
diff --git a/docs/spec/04-ux/07-ui-design-system.md b/docs/spec/04-ux/07-ui-design-system.md
index d5ff5b7bd..b2dd92524 100644
--- a/docs/spec/04-ux/07-ui-design-system.md
+++ b/docs/spec/04-ux/07-ui-design-system.md
@@ -1210,6 +1210,66 @@ Full component contract and usage rules: [08-component-spec.md §17](08-componen
| Motion | enter 200ms ease-out slide-down/fade, exit 150ms ease-in fade; reduced-motion → near-zero duration (not `none`, removal listens for `animationend`) |
| Z-index | z-toast (50) |
+### 11.9 SettingsToggle
+
+Implementation: `components/ui.tsx → SettingsToggle`.
+
+| Property | Value |
+|---|---|
+| Size | 32×20, thumb 16px |
+| CSS class | `.settings-toggle` / `.settings-toggle.on` |
+| Role | `role="switch"` with `aria-checked` |
+| Variants | default, `busy` (`.is-busy`, `aria-busy`, disabled) |
+| Background | neutral accent when on (not green); theme-specific override in `theme-overrides.css` |
+
+Every boolean on/off control in Settings and editor sheets **must** use
+`SettingsToggle`. Inline `<button role="switch">` with manual class
+assembly is prohibited.
+
+### 11.10 SegmentedControl
+
+Implementation: `components/ui.tsx → SegmentedControl<T>`.
+
+| Property | Value |
+|---|---|
+| CSS class | `.settings-segment` / `.settings-segment-item.active` |
+| Roles | `radiogroup` (default), `group`, or `tablist` |
+| Item roles | `radio` / none / `tab` — derived from container role |
+| Generic | `<T extends string>` for type-safe value/onChange |
+| Options | `readonly { value: T; label: ReactNode }[]` — label accepts JSX (e.g. count badge) |
+
+Every multi-option selector rendered as a row of equal buttons **must** use
+`SegmentedControl`. Inline `<div className="settings-segment">` with manual
+button loops is prohibited.
+
+### 11.11 Checkbox
+
+Implementation: `components/ui.tsx → Checkbox`.
+
+| Property | Value |
+|---|---|
+| CSS class | `.ui-checkbox` |
+| Anatomy | `<label> → <input type="checkbox"> + <span>{label}</span>` |
+| Props | Extends `InputHTMLAttributes` (minus `type`) + `label: ReactNode` |
+
+Every standalone labeled checkbox **must** use `Checkbox`. Inline
+`<label><input type="checkbox"/>…</label>` is prohibited.
+
+### 11.12 SettingsMenuSelect
+
+Implementation: `components/settings/SettingsMenuSelect.tsx`.
+
+| Property | Value |
+|---|---|
+| Trigger | Button showing the current label, `IconChevronDown` trailing |
+| Popup | `AnchoredMenu` — portaled, keyboard-navigable, current-value checkmark |
+| Props | `value`, `options: { id, label, disabled? }[]`, `onChange(id)`, `label`, `disabled`, `busy`, `fullWidth` |
+
+Every dropdown / option-list in Settings **must** use `SettingsMenuSelect`
+instead of the native `Select` (`<select>`) component. Native `Select`
+is reserved for non-Settings contexts where OS-level rendering is acceptable.
+
+
## 12. State patterns
### 12.1 Interactive states
@@ -1268,6 +1328,8 @@ Full component contract and usage rules: [08-component-spec.md §17](08-componen
- Use Lucide/Heroicons SVG icons — never emoji as UI affordances
- Use compact padding and tight spacing — developer density, not consumer spacing
- First launch follows the system theme (see §Theme switching); dark is the primary design target
+- Use shared primitives from `components/ui.tsx` (`Button`, `Badge`, `SettingsToggle`, `SegmentedControl`, `Checkbox`, `Input`, `Textarea`, `Select`, `Field`, `Panel`, `HelpIcon`, `TooltipButton`) — never reimplement them inline
+- Use `SettingsMenuSelect` for all Settings dropdowns — never native `<select>` inside Settings
### Don't
@@ -1281,6 +1343,8 @@ Full component contract and usage rules: [08-component-spec.md §17](08-componen
- Don't apply rounded corners to full-width panels (sidebar, topbar)
- Don't use `border-radius: 0` on buttons and inputs (use `radius-sm` minimum)
- Don't show raw API keys in any UI surface
+- Don't write inline `<button role="switch">`, `<div className="settings-segment">`, or `<label><input type="checkbox">` — use the corresponding shared component
+- Don't use native `Select` (`<select>`) in Settings pages — use `SettingsMenuSelect`
## 15. Acceptance criteria