Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(themes): restore light / dark preferences (#4151)

Aidan Holloway-Bidwell0c653eaff537
diff --git a/js/app/packages/app/component/GlobalHotkeys.tsx b/js/app/packages/app/component/GlobalHotkeys.tsx
index 512e2498ef..2006ba784f 100644
--- a/js/app/packages/app/component/GlobalHotkeys.tsx
+++ b/js/app/packages/app/component/GlobalHotkeys.tsx
@@ -32,7 +32,13 @@ import { ThemeChips } from '@theme/components/ThemeChips';
import type { ThemeV2 } from '@theme/types/themeTypes';
import { registerHotkey } from 'core/hotkey/hotkeys';
import { type Component, onCleanup } from 'solid-js';
-import { themes } from '../../theme/signals/themeSignals';
+import {
+ setDarkModeTheme,
+ setLightModeTheme,
+ setThemeShouldMatchSystem,
+ themeShouldMatchSystem,
+ themes,
+} from '../../theme/signals/themeSignals';
import { applyTheme } from '../../theme/utils/themeUtils';
import { globalSplitManager } from '../signal/splitLayout';
@@ -311,6 +317,65 @@ export default function GlobalShortcuts() {
});
});
+ const setPreferredLightScope = registerHotkey({
+ scopeId: 'global',
+ description: 'Set default light theme',
+ keyDownHandler: () => {
+ return true;
+ },
+ activateCommandScope: true,
+ runWithInputFocused: true,
+ });
+
+ themes().forEach((theme) => {
+ registerHotkey({
+ scopeId: setPreferredLightScope.commandScopeId,
+ description: `${theme.name}`,
+ keyDownHandler: () => {
+ setLightModeTheme(theme.id);
+ analytics.track('theme_changed', { themeId: theme.id });
+ return true;
+ },
+ runWithInputFocused: true,
+ displayComponent: () => <ThemeDisplay theme={theme} />,
+ });
+ });
+
+ const setPreferredDarkScope = registerHotkey({
+ scopeId: 'global',
+ description: 'Set default dark theme',
+ keyDownHandler: () => {
+ return true;
+ },
+ activateCommandScope: true,
+ runWithInputFocused: true,
+ });
+
+ themes().forEach((theme) => {
+ registerHotkey({
+ scopeId: setPreferredDarkScope.commandScopeId,
+ description: `${theme.name}`,
+ keyDownHandler: () => {
+ setDarkModeTheme(theme.id);
+ analytics.track('theme_changed', { themeId: theme.id });
+ return true;
+ },
+ runWithInputFocused: true,
+ displayComponent: () => <ThemeDisplay theme={theme} />,
+ });
+ });
+
+ registerHotkey({
+ scopeId: 'global',
+ description: () =>
+ `${themeShouldMatchSystem() ? 'Turn off a' : 'A'}uto-detect color scheme`,
+ keyDownHandler: () => {
+ setThemeShouldMatchSystem((prev) => !prev);
+ return true;
+ },
+ runWithInputFocused: true,
+ });
+
registerHotkey({
scopeId: 'global',
description: 'Upload files',
diff --git a/js/app/packages/app/component/Root.tsx b/js/app/packages/app/component/Root.tsx
index f82b13ddc1..bccc3824d3 100644
--- a/js/app/packages/app/component/Root.tsx
+++ b/js/app/packages/app/component/Root.tsx
@@ -86,6 +86,7 @@ import { currentThemeId } from '../../theme/signals/themeSignals';
import {
applyTheme,
ensureMinimalThemeContrast,
+ systemThemeEffect,
} from '../../theme/utils/themeUtils';
import { Login } from './auth/Login';
import { setCookie } from './auth/Shared';
@@ -420,6 +421,9 @@ function UserInfoSideEffects() {
// Set user info for observability and analytics
const userInfo = useUserInfo();
+ // Keep the active theme following the OS color scheme when auto-detect is on.
+ systemThemeEffect();
+
let identified = false;
createEffect(
on(userInfo, (user) => {
diff --git a/js/app/packages/app/component/settings/Appearance.tsx b/js/app/packages/app/component/settings/Appearance.tsx
index 4ee44eb985..60661f9b5c 100644
--- a/js/app/packages/app/component/settings/Appearance.tsx
+++ b/js/app/packages/app/component/settings/Appearance.tsx
@@ -4,19 +4,83 @@ import { ThemeEditorBasic, randomizeTheme } from '@theme/components/ThemeEditorB
import ThemeTools from '@theme/components/ThemeTools';
import ThemeList from '@theme/components/ThemeList';
import { isMobile } from '@core/mobile/isMobile';
-import { createSignal, Show } from 'solid-js';
+import { createSignal, For, Show } from 'solid-js';
import { TabsInset } from '@core/component/TabsInset';
import IconDice from '@phosphor-icons/core/regular/dice-five.svg?component-solid';
import IconFunnel from '@phosphor-icons/core/regular/funnel-simple.svg?component-solid';
-import { setShowDarkThemes, setShowLightThemes, showDarkThemes, showLightThemes } from '@theme/signals/themeSignals';
-import { Button, InlineCheckbox, Panel, ToggleSwitch } from '@ui';
+import { darkModeTheme, lightModeTheme, setDarkModeTheme, setLightModeTheme, setShowDarkThemes, setShowLightThemes, setThemeShouldMatchSystem, showDarkThemes, showLightThemes, themes, themeShouldMatchSystem } from '@theme/signals/themeSignals';
+import { isTokensDark } from '@theme/utils/themeUtils';
+import { ThemeChips } from '@theme/components/ThemeChips';
+import { ThemeChipPill } from '@theme/components/ThemeChipPill';
+import type { ThemeV2 } from '@theme/types/themeTypes';
+import { DropdownMenu as KobalteDropdownMenu } from '@kobalte/core/dropdown-menu';
+import { Button, cn, Dropdown, InlineCheckbox, Panel, ToggleSwitch } from '@ui';
type PanelA = 'basic' | 'advanced';
type PanelB ='themes' | 'ui'
+function ThemePreferenceRow(props: {
+ label: string;
+ value: () => string;
+ options: () => ThemeV2[];
+ onSelect: (id: string) => void;
+ // Default themes only take effect while auto-detect is on, so the control is
+ // dimmed and non-interactive otherwise.
+ disabled?: () => boolean;
+}) {
+ const selectedTheme = () =>
+ themes().find((theme) => theme.id === props.value());
+
+ return (
+ <div
+ class={cn(
+ // Nested under the auto-detect toggle: the indent marks these as
+ // sub-settings that only apply while auto-detect is on. Shorter than the
+ // top-level rows so they cluster tightly beneath the toggle.
+ 'bg-surface flex items-center justify-between h-11 px-6 pl-10 transition-opacity',
+ props.disabled?.() && 'opacity-50 pointer-events-none'
+ )}
+ aria-disabled={props.disabled?.()}
+ >
+ <div class="text-sm">{props.label}</div>
+ <Dropdown>
+ {/* Same pill as the theme mention chip; `as` makes it the dropdown trigger. */}
+ <KobalteDropdownMenu.Trigger
+ as={ThemeChipPill}
+ class="h-auto"
+ disabled={props.disabled?.()}
+ theme={selectedTheme()}
+ name={selectedTheme()?.name ?? props.value()}
+ />
+ <Dropdown.Content>
+ <Dropdown.Group>
+ <For each={props.options()}>
+ {(theme) => (
+ <Dropdown.Item
+ class="touch:min-h-10"
+ onSelect={() => props.onSelect(theme.id)}
+ >
+ <span class="flex items-center gap-2">
+ <ThemeChips theme={theme} size="sm" />
+ {theme.name}
+ </span>
+ </Dropdown.Item>
+ )}
+ </For>
+ </Dropdown.Group>
+ </Dropdown.Content>
+ </Dropdown>
+ </div>
+ );
+}
+
function UserInterface() {
+ const lightThemes = () =>
+ themes().filter((theme) => !isTokensDark(theme.tokens));
+ const darkThemes = () => themes().filter((theme) => isTokensDark(theme.tokens));
+
return (
- <div class="grid gap-px bg-edge-muted border-b border-edge-muted">
+ <div class="flex flex-col">
<div class="bg-surface flex items-center justify-between h-15.25 px-6">
<div class="text-sm">Monochrome Icons</div>
<ToggleSwitch
@@ -33,6 +97,35 @@ function UserInterface() {
/>
</div>
+ <div class="bg-surface flex items-center justify-between h-15.25 px-6">
+ <div class="flex flex-col gap-0.5">
+ <div class="text-sm">Auto-detect color scheme</div>
+ <div class="text-xs text-ink-muted">
+ Switch theme with your system's light/dark mode
+ </div>
+ </div>
+ <ToggleSwitch
+ onChange={setThemeShouldMatchSystem}
+ checked={themeShouldMatchSystem()}
+ />
+ </div>
+
+ <ThemePreferenceRow
+ label="Default light theme"
+ value={lightModeTheme}
+ options={lightThemes}
+ onSelect={setLightModeTheme}
+ disabled={() => !themeShouldMatchSystem()}
+ />
+
+ <ThemePreferenceRow
+ label="Default dark theme"
+ value={darkModeTheme}
+ options={darkThemes}
+ onSelect={setDarkModeTheme}
+ disabled={() => !themeShouldMatchSystem()}
+ />
+
</div>
);
}
@@ -42,16 +135,34 @@ export function Appearance() {
const [activeTabB, setActiveTabB] = createSignal<PanelB>('themes');
const [showFilters, setShowFilters] = createSignal(false);
+ // The top panel sizes to the active editor; Advanced needs a fixed, scrollable
+ // height since its per-token list is taller than the panel.
+ const rowA = () =>
+ activeTabA() === 'advanced'
+ ? isMobile()
+ ? '322.5px'
+ : '432.5px'
+ : 'min-content';
+ // On mobile the whole panel scrolls as one column, so the bottom panel sizes to
+ // its content rather than filling (and being clipped by) a fixed viewport row.
+ const rowB = () => (isMobile() ? 'min-content' : '1fr');
+
return (
- <div class="h-full overflow-hidden flex justify-center p-2">
+ <div
+ class={cn(
+ 'h-full flex justify-center p-2',
+ // Mobile: scroll the whole settings column. Desktop: fixed two-pane layout.
+ isMobile() ? 'overflow-y-auto items-start' : 'overflow-hidden'
+ )}
+ >
<div
- class="max-w-200 size-full"
+ class={cn('max-w-200 w-full', !isMobile() && 'h-full')}
style={{
// Basic editor shrinks to fit its content; Advanced needs a fixed,
// scrollable height since its per-token list is taller than the panel.
- 'grid-template-rows': `${activeTabA() === 'advanced' ? (isMobile() ? '322.5px' : '432.5px') : 'min-content'} 1fr`,
+ 'grid-template-rows': `${rowA()} ${rowB()}`,
'grid-template-columns': '1fr',
- 'overflow': 'hidden',
+ 'overflow': isMobile() ? 'visible' : 'hidden',
'display': 'grid',
'gap': '8px',
}}
@@ -67,17 +178,9 @@ export function Appearance() {
value={activeTabA()}
defaultValue="basic"
/>
- <Show when={!isMobile()}>
- <ThemeTools class="flex-1 min-w-0" />
- </Show>
+ <ThemeTools class="flex-1 min-w-0" />
</Panel.Header>
- <Show when={isMobile()}>
- <Panel.Toolbar>
- <ThemeTools class="flex-1 min-w-0" />
- </Panel.Toolbar>
- </Show>
-
<Panel.Body scroll={activeTabA() === 'advanced'}>
<Show when={activeTabA() === 'basic'}>
<ThemeEditorBasic />
@@ -91,7 +194,7 @@ export function Appearance() {
<Panel depth={2}>
<Panel.Header>
<TabsInset
- onChange={(value) => setActiveTabB(value as PanelB)}
+ onChange={(value) => setActiveTabB(value as PanelB)}
list={[
{ value: 'themes', label: 'Themes' },
{ value: 'ui', label: 'UI' },
@@ -125,7 +228,7 @@ export function Appearance() {
<span class="text-xs text-ink-extra-muted">Filter themes</span>
<button
type="button"
- class="inline-flex items-center gap-1.5 text-xs text-ink-muted hover:text-ink"
+ class="inline-flex items-center gap-1.5 text-xs text-ink-muted hover:text-ink touch:min-h-9 touch:pr-2"
onClick={() => setShowLightThemes((v) => !v)}
>
<InlineCheckbox checked={showLightThemes()} />
@@ -133,7 +236,7 @@ export function Appearance() {
</button>
<button
type="button"
- class="inline-flex items-center gap-1.5 text-xs text-ink-muted hover:text-ink"
+ class="inline-flex items-center gap-1.5 text-xs text-ink-muted hover:text-ink touch:min-h-9 touch:pr-2"
onClick={() => setShowDarkThemes((v) => !v)}
>
<InlineCheckbox checked={showDarkThemes()} />
diff --git a/js/app/packages/app/index.css b/js/app/packages/app/index.css
index 6931a084ea..3ed6d27de6 100644
--- a/js/app/packages/app/index.css
+++ b/js/app/packages/app/index.css
@@ -191,6 +191,9 @@
--z-index-modal-content: 120;
--z-index-tool-tip: 200;
+ /* Soft drop shadow for floating menus/popovers (use the `shadow-menu` utility). */
+ --shadow-menu: 0 8px 24px -16px rgb(0 0 0 / 0.24), 0 2px 8px -6px rgb(0 0 0 / 0.18);
+
/* Shared label column width for side-panel two-column grids so labels line
up across sub-panels (Details, Properties, ...). Consumers should use
`grid-cols-[var(--sidepanel-label-width,auto)_1fr]` so the column falls
diff --git a/js/app/packages/core/component/ContextMenu.tsx b/js/app/packages/core/component/ContextMenu.tsx
index 5167845f5c..249a40c162 100644
--- a/js/app/packages/core/component/ContextMenu.tsx
+++ b/js/app/packages/core/component/ContextMenu.tsx
@@ -302,7 +302,7 @@ const menuWidths: Record<MenuWidth, string> = {
screen: 'w-screen',
};
-export const MENU_CONTENT_CLASS = `flex flex-col justify-start items-start bg-surface shadow-[0_8px_24px_-16px_rgba(0,0,0,0.24),0_2px_8px_-6px_rgba(0,0,0,0.18)] ring-1 ring-edge rounded-xl p-1.5 cursor-default select-none max-w-full max-h-[calc(100dvh-10rem)] overflow-y-auto z-modal`;
+export const MENU_CONTENT_CLASS = `flex flex-col justify-start items-start bg-surface shadow-menu ring-1 ring-edge rounded-xl p-1.5 cursor-default select-none max-w-full max-h-[calc(100dvh-10rem)] overflow-y-auto z-modal`;
type MenuContentProps = ParentProps<{
class?: string;
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/ThemeMention.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/ThemeMention.tsx
index e58a06b898..1ff4525bc9 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/ThemeMention.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/ThemeMention.tsx
@@ -1,12 +1,12 @@
import { useSettingsState } from '@core/constant/SettingsState';
import type { ThemeMentionDecoratorProps } from '@lexical-core';
-import { ThemeChips } from '@theme/components/ThemeChips';
+import { ThemeChipPill } from '@theme/components/ThemeChipPill';
import { setUserThemes, themes, userThemes } from '@theme/signals/themeSignals';
import type { ThemeV2 } from '@theme/types/themeTypes';
import { applyTheme } from '@theme/utils/themeUtils';
import { isThemeV2 } from '@theme/utils/themeValidation';
import { cn } from '@ui';
-import { Show, useContext } from 'solid-js';
+import { useContext } from 'solid-js';
import { LexicalWrapperContext } from '../../context/LexicalWrapperContext';
export function ThemeMention(props: ThemeMentionDecoratorProps) {
@@ -39,22 +39,15 @@ export function ThemeMention(props: ThemeMentionDecoratorProps) {
};
return (
- <button
+ <ThemeChipPill
+ type="button"
+ onClick={handleClick}
class={cn(
- 'pointer-events-auto mx-0.5 inline-flex items-stretch gap-0.75 align-baseline overflow-hidden py-0 pl-0 pr-1 rounded-md border border-edge-muted bg-transparent',
+ 'pointer-events-auto mx-0.5 align-baseline',
isSelectedAsNode() && 'bg-active'
)}
- onClick={handleClick}
- type="button"
- >
- <Show when={theme()}>
- {(t) => (
- <span class="rounded-md inline-flex self-stretch [&>span]:h-full [&>span]:border-0 [&>span]:rounded-[5px]">
- <ThemeChips theme={t()} size="sm" />
- </span>
- )}
- </Show>
- <span class="mx-0.5 flex items-center cursor-default">{props.name}</span>
- </button>
+ theme={theme()}
+ name={props.name}
+ />
);
}
diff --git a/js/app/packages/theme/components/ThemeChipPill.tsx b/js/app/packages/theme/components/ThemeChipPill.tsx
new file mode 100644
index 0000000000..4b423971c5
--- /dev/null
+++ b/js/app/packages/theme/components/ThemeChipPill.tsx
@@ -0,0 +1,44 @@
+import { type ComponentProps, Show, splitProps, type ValidComponent } from 'solid-js';
+import { Dynamic } from 'solid-js/web';
+import { cn } from '@ui';
+import type { ThemeV2 } from '../types/themeTypes';
+import { ThemeChips } from './ThemeChips';
+
+type ThemeChipPillProps = {
+ /** Element/component to render as. Defaults to a <button>. */
+ as?: ValidComponent;
+ /** Theme whose swatch is shown; when absent, only the name renders. */
+ theme?: ThemeV2 | null;
+ /** Label shown beside the swatch. */
+ name: string;
+} & ComponentProps<'button'>;
+
+/**
+ * A theme swatch + name inside a bordered, rounded-md pill: the swatch sits flush
+ * on the left (its own border stripped, inner corners rounded-[5px]) and fills the
+ * pill height. Polymorphic via `as` so the same pill can be a plain button (the
+ * theme mention chip) or a dropdown trigger (the preferred-theme picker in
+ * settings/Appearance) and stay visually identical.
+ */
+export function ThemeChipPill(props: ThemeChipPillProps) {
+ const [local, rest] = splitProps(props, ['as', 'theme', 'name', 'class']);
+ return (
+ <Dynamic
+ component={local.as ?? 'button'}
+ class={cn(
+ 'inline-flex items-stretch gap-0.75 overflow-hidden rounded-md border border-edge-muted bg-transparent py-0 pl-0 pr-1',
+ local.class
+ )}
+ {...rest}
+ >
+ <Show when={local.theme}>
+ {(theme) => (
+ <span class="inline-flex self-stretch rounded-md [&>span]:h-full [&>span]:rounded-[5px] [&>span]:border-0">
+ <ThemeChips theme={theme()} size="sm" />
+ </span>
+ )}
+ </Show>
+ <span class="mx-0.5 flex items-center cursor-default">{local.name}</span>
+ </Dynamic>
+ );
+}
diff --git a/js/app/packages/theme/components/ThemeChips.tsx b/js/app/packages/theme/components/ThemeChips.tsx
index 7b124e36b8..8983d06f59 100644
--- a/js/app/packages/theme/components/ThemeChips.tsx
+++ b/js/app/packages/theme/components/ThemeChips.tsx
@@ -19,7 +19,7 @@ const sizeStyles: Record<
icon: 'size-[18px]',
},
sm: {
- root: 'gap-1 py-[3px] px-[5px] rounded-md',
+ root: 'gap-1 py-[3px] px-[5px] rounded-sm',
accent: 'size-[9px]',
icon: 'size-3',
},
diff --git a/js/app/packages/theme/components/ThemeCrud.tsx b/js/app/packages/theme/components/ThemeCrud.tsx
index 42461eec5b..5032256a75 100644
--- a/js/app/packages/theme/components/ThemeCrud.tsx
+++ b/js/app/packages/theme/components/ThemeCrud.tsx
@@ -1,9 +1,9 @@
import IconClipboard from '@phosphor-icons/core/regular/clipboard.svg?component-solid';
-import IconTrash from '@phosphor-icons/core/regular/trash.svg?component-solid';
+import IconDotsThreeVertical from '@phosphor/dots-three-vertical.svg';
import { deleteTheme, exportTheme } from '../utils/themeUtils';
-import { userThemes } from '../signals/themeSignals';
+import { setDarkModeTheme, setLightModeTheme, userThemes } from '../signals/themeSignals';
import { createMemo, Show } from 'solid-js';
-import { Button } from '@ui';
+import { Button, Dropdown } from '@ui';
interface ThemeCrudProps { themeId: string; }
@@ -30,18 +30,39 @@ export function ThemeCrud(props: ThemeCrudProps) {
<IconClipboard />
</Button>
- <Show when={isUserTheme()}>
- <Button
- onPointerDown={() => {
- deleteTheme(props.themeId);
- }}
- label="Delete Theme"
- variant="ghost"
- size="icon-sm"
- >
- <IconTrash />
- </Button>
- </Show>
+ <Dropdown placement="bottom-end">
+ <Dropdown.Trigger label="Theme options" variant="ghost" size="icon-sm">
+ <IconDotsThreeVertical />
+ </Dropdown.Trigger>
+ <Dropdown.Content class="shadow-menu">
+ <Dropdown.Group>
+ <Dropdown.Item
+ class="touch:min-h-10"
+ onSelect={() => setDarkModeTheme(props.themeId)}
+ >
+ Set default dark theme
+ </Dropdown.Item>
+ <Dropdown.Item
+ class="touch:min-h-10"
+ onSelect={() => setLightModeTheme(props.themeId)}
+ >
+ Set default light theme
+ </Dropdown.Item>
+ </Dropdown.Group>
+ {/* Separate group renders a divider (gap-px) above the destructive
+ action; only user themes can be deleted. */}
+ <Show when={isUserTheme()}>
+ <Dropdown.Group>
+ <Dropdown.Item
+ class="text-failure touch:min-h-10"
+ onSelect={() => deleteTheme(props.themeId)}
+ >
+ Delete
+ </Dropdown.Item>
+ </Dropdown.Group>
+ </Show>
+ </Dropdown.Content>
+ </Dropdown>
</div>
);
}
diff --git a/js/app/packages/theme/components/ThemeEditorBasic.tsx b/js/app/packages/theme/components/ThemeEditorBasic.tsx
index 325a85bae4..112bf65d8f 100644
--- a/js/app/packages/theme/components/ThemeEditorBasic.tsx
+++ b/js/app/packages/theme/components/ThemeEditorBasic.tsx
@@ -471,7 +471,7 @@ export function ThemeEditorBasic(){
--b4: color-mix(in oklch, oklch(var(--b4l) var(--b4c) var(--b4h)), oklch(var(--c4l) var(--c4c) var(--c4h)) 30%);
"
>
- <div class="flex items-center gap-3 @2xl:flex-col @2xl:items-stretch @2xl:gap-[3px]">
+ <div class="flex items-center gap-2 @2xl:flex-col @2xl:items-stretch @2xl:gap-[3px]">
<div class="w-[9ch] shrink-0 @2xl:w-auto">Chroma</div>
<div class="flex flex-1 items-center gap-3 min-w-0 @2xl:flex-none">
<div
@@ -546,7 +546,7 @@ export function ThemeEditorBasic(){
</div>
</div>
- <div class="flex items-center gap-3 @2xl:flex-col @2xl:items-stretch @2xl:gap-[3px]">
+ <div class="flex items-center gap-2 @2xl:flex-col @2xl:items-stretch @2xl:gap-[3px]">
<div class="w-[9ch] shrink-0 @2xl:w-auto">Tint</div>
<div class="flex flex-1 items-center gap-3 min-w-0 @2xl:flex-none">
<div
@@ -640,7 +640,7 @@ export function ThemeEditorBasic(){
</div>
</div>
- <div class="flex items-center gap-3 @2xl:flex-col @2xl:items-stretch @2xl:gap-[3px]">
+ <div class="flex items-center gap-2 @2xl:flex-col @2xl:items-stretch @2xl:gap-[3px]">
<div class="w-[9ch] shrink-0 @2xl:w-auto">Contrast</div>
<div class="flex flex-1 items-center gap-3 min-w-0 @2xl:flex-none">
<div
@@ -750,7 +750,7 @@ export function ThemeEditorBasic(){
</div>
</div>
- <div class="flex items-center gap-3 @2xl:flex-col @2xl:items-stretch @2xl:gap-[3px]">
+ <div class="flex items-center gap-2 @2xl:flex-col @2xl:items-stretch @2xl:gap-[3px]">
<div class="w-[9ch] shrink-0 @2xl:w-auto">Depth</div>
<div class="flex flex-1 items-center gap-3 min-w-0 @2xl:flex-none">
<div
diff --git a/js/app/packages/theme/components/ThemeTools.tsx b/js/app/packages/theme/components/ThemeTools.tsx
index b568d2e125..e27b509869 100644
--- a/js/app/packages/theme/components/ThemeTools.tsx
+++ b/js/app/packages/theme/components/ThemeTools.tsx
@@ -1,6 +1,7 @@
import { currentThemeId, isThemeSaved, themes } from '../signals/themeSignals';
import { saveTheme } from '../utils/themeUtils';
import IconSave from '@phosphor-icons/core/regular/floppy-disk-back.svg?component-solid';
+import { isMobile } from '@core/mobile/isMobile';
import { createMemo, Show } from 'solid-js';
import { Button, cn } from '@ui';
@@ -67,7 +68,8 @@ function ThemeTools(props: { class?: string }) {
)}
style={{
'white-space': 'nowrap',
- 'flex': '0 1 13rem',
+ // Narrower on mobile so it fits on the same line as the Basic/Advanced tabs.
+ 'flex': isMobile() ? '0 1 7.5rem' : '0 1 13rem',
'min-width': '0',
}}
contentEditable={true}
diff --git a/js/app/packages/theme/signals/themeSignals.ts b/js/app/packages/theme/signals/themeSignals.ts
index 34661bcb0c..f38dda186c 100644
--- a/js/app/packages/theme/signals/themeSignals.ts
+++ b/js/app/packages/theme/signals/themeSignals.ts
@@ -1,4 +1,4 @@
-import { DEFAULT_DARK_THEME, DEFAULT_THEMES } from '../constants';
+import { DEFAULT_DARK_THEME, DEFAULT_LIGHT_THEME, DEFAULT_THEMES } from '../constants';
import { createMemo, createSignal } from 'solid-js';
import type { ThemeV0, ThemeV1, ThemeV2 } from '../types/themeTypes';
import { convertThemev0v1, convertThemev1v2 } from '../utils/themeMigrations';
@@ -32,6 +32,42 @@ export const [currentThemeId, setCurrentThemeId] = makePersisted(
export const themes = createMemo(() => [...DEFAULT_THEMES, ...userThemes()]);
+// Per-mode theme preferences, persisted to localStorage. Applied by
+// systemThemeEffect (themeUtils.ts) when themeShouldMatchSystem is on and the OS
+// color scheme is (or becomes) the matching mode.
+export const [lightModeTheme, setLightModeTheme] = makePersisted(
+ createSignal<string>(DEFAULT_LIGHT_THEME),
+ {name: 'macro-light-mode-theme'}
+);
+
+export const [darkModeTheme, setDarkModeTheme] = makePersisted(
+ createSignal<string>(DEFAULT_DARK_THEME),
+ {name: 'macro-dark-mode-theme'}
+);
+
+export const [themeShouldMatchSystem, setThemeShouldMatchSystem] = makePersisted(
+ createSignal<boolean>(true),
+ {name: 'macro-theme-should-match-system'}
+);
+
+const supportsMatchMedia =
+ typeof window !== 'undefined' && typeof window.matchMedia === 'function';
+
+// Tracks the OS color scheme so the active theme can follow it when
+// themeShouldMatchSystem is on.
+export const [systemMode, setSystemMode] = createSignal<'dark' | 'light'>(
+ supportsMatchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
+ ? 'dark'
+ : 'light'
+);
+
+if (supportsMatchMedia) {
+ const darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)');
+ darkModeQuery.addEventListener('change', (e: MediaQueryListEvent) => {
+ setSystemMode(e.matches ? 'dark' : 'light');
+ });
+}
+
// Theme-list filters: whether light and/or dark themes are shown in the list.
export const [showLightThemes, setShowLightThemes] = makePersisted(
createSignal<boolean>(true),
diff --git a/js/app/packages/theme/utils/themeUtils.ts b/js/app/packages/theme/utils/themeUtils.ts
index 44dd4ea2c9..7636420a1a 100644
--- a/js/app/packages/theme/utils/themeUtils.ts
+++ b/js/app/packages/theme/utils/themeUtils.ts
@@ -1,8 +1,8 @@
-import { currentThemeId, setCurrentThemeId, setHtmlColor, setIsThemeSaved, setThemeDepth, setUserThemes, themeDepth, themes, userThemes} from '../signals/themeSignals';
+import { currentThemeId, darkModeTheme, lightModeTheme, setCurrentThemeId, setHtmlColor, setIsThemeSaved, setThemeDepth, setUserThemes, systemMode, themeDepth, themes, themeShouldMatchSystem, userThemes} from '../signals/themeSignals';
import type { ThemeV2, ThemeV2Tokens } from '../types/themeTypes';
import { themeReactive } from '../signals/themeReactive';
import { toast } from '@core/component/Toast/Toast';
-import { batch } from 'solid-js';
+import { batch, createEffect, on } from 'solid-js';
import { DEFAULT_DARK_THEME } from '../constants';
export function exportTheme(themeId?: string){
@@ -72,6 +72,29 @@ export function applyTheme(id: string): void{
});
}
+/** When auto-detect is on, keeps the active theme in sync with the OS color
+ * scheme by applying the preferred light or dark theme as the system flips.
+ * Call once from a reactive root (see Root.tsx). */
+export function systemThemeEffect(): void{
+ createEffect(
+ on(
+ // Only react to the OS color scheme flipping or auto-detect turning on —
+ // deliberately NOT to darkModeTheme/lightModeTheme. `on` runs its callback
+ // untracked, so reading the defaults below does not subscribe to them. This
+ // keeps "Set default light/dark theme" from re-applying the current mode's
+ // default and clobbering the active theme; a new default takes effect on the
+ // next mode change (or when auto-detect is toggled on).
+ [themeShouldMatchSystem, systemMode],
+ () => {
+ if(themeShouldMatchSystem()){
+ applyTheme(systemMode() === 'dark' ? darkModeTheme() : lightModeTheme());
+ }
+ },
+ { defer: true }
+ )
+ );
+}
+
/** Persists the live background color, used for the pre-hydration first paint. */
function syncHtmlColor(): void{
setHtmlColor({color: `oklch(${themeReactive.b0.l[0]()} ${themeReactive.b0.c[0]()} ${themeReactive.b0.h[0]()}deg)`});
diff --git a/js/app/packages/ui/components/Dropdown.tsx b/js/app/packages/ui/components/Dropdown.tsx
index 1f094ddeb5..34a2e4093e 100644
--- a/js/app/packages/ui/components/Dropdown.tsx
+++ b/js/app/packages/ui/components/Dropdown.tsx
@@ -26,7 +26,7 @@ import { Surface, type SurfaceProps } from './Surface';
// trigger and the shared signal closes the sibling.
*/
-// const DROPDOWN_CONTENT_CLASS = 'z-action-menu bg-surface rounded-xl ring-1 ring-edge shadow-[0_8px_24px_-16px_rgba(0,0,0,0.24),0_2px_8px_-6px_rgba(0,0,0,0.18)] p-1.5';
+// const DROPDOWN_CONTENT_CLASS = 'z-action-menu bg-surface rounded-xl ring-1 ring-edge shadow-menu p-1.5';
// const DROPDOWN_ITEM_CLASS = 'rounded-md hover:bg-ink/3 focus:bg-ink/3 data-[highlighted]:bg-ink/3';
type PortalMount = ComponentProps<typeof KobalteDropdownMenu.Portal>['mount'];