Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(theme): preview themes on hover/highlight in cmd+k and settings (#4745)
Eric Hayes39dd86d9fc1f
diff --git a/apps/web/src/components/app/GlobalHotkeys.tsx b/apps/web/src/components/app/GlobalHotkeys.tsxindex 8a839ce4d8..0e8ce905e8 100644--- a/apps/web/src/components/app/GlobalHotkeys.tsx+++ b/apps/web/src/components/app/GlobalHotkeys.tsx@@ -53,7 +53,11 @@ import {themes,} from '@theme/signals/themeSignals';import type { ThemeV2 } from '@theme/types/themeTypes';-import { applyTheme } from '@theme/utils/themeUtils';+import {+ applyTheme,+ clearThemePreview,+ previewTheme,+} from '@theme/utils/themeUtils';import { type Component, onCleanup } from 'solid-js';import { useSplitLayout } from './split-layout/layout';@@ -373,6 +377,8 @@ export default function GlobalShortcuts() {},runWithInputFocused: true,displayComponent: () => <ThemeDisplay theme={theme} />,+ onHighlight: () => previewTheme(theme.id),+ onHighlightEnd: clearThemePreview,});});@@ -397,6 +403,8 @@ export default function GlobalShortcuts() {},runWithInputFocused: true,displayComponent: () => <ThemeDisplay theme={theme} />,+ onHighlight: () => previewTheme(theme.id),+ onHighlightEnd: clearThemePreview,});});@@ -421,6 +429,8 @@ export default function GlobalShortcuts() {},runWithInputFocused: true,displayComponent: () => <ThemeDisplay theme={theme} />,+ onHighlight: () => previewTheme(theme.id),+ onHighlightEnd: clearThemePreview,});});diff --git a/apps/web/src/features/command/CommandMenu.tsx b/apps/web/src/features/command/CommandMenu.tsxindex c128cf08c1..728e626324 100644--- a/apps/web/src/features/command/CommandMenu.tsx+++ b/apps/web/src/features/command/CommandMenu.tsx@@ -15,7 +15,7 @@ import {setActiveScope,setPressedKeys,} from '@core/hotkey/state';-import type { RegisterHotkeyReturn } from '@core/hotkey/types';+import type { HotkeyCommand, RegisterHotkeyReturn } from '@core/hotkey/types';import { runCommand } from '@core/hotkey/utils';import { debouncedDependent } from '@core/util/debounce';import { openExternalUrl } from '@core/util/url';@@ -31,6 +31,7 @@ import {For,Match,on,+ onCleanup,onMount,Show,Switch,@@ -170,6 +171,23 @@ export function CommandMenuInner(props: {return items[index];};+ // Fire command highlight hooks (e.g. live theme preview) as the selection+ // moves via hover or arrow keys. The outgoing command's onHighlightEnd runs+ // before the incoming command's onHighlight; unmount (menu close) ends any+ // active highlight.+ let highlightedCommand: HotkeyCommand | undefined;+ const setHighlightedCommand = (command: HotkeyCommand | undefined) => {+ if (command === highlightedCommand) return;+ highlightedCommand?.onHighlightEnd?.();+ highlightedCommand = command;+ command?.onHighlight?.();+ };+ createEffect(() => {+ const item = selectedItem();+ setHighlightedCommand(item && isCommandItem(item) ? item.data : undefined);+ });+ onCleanup(() => setHighlightedCommand(undefined));+const selectedIsCommand = () => {const item = selectedItem();return item && isCommandItem(item);diff --git a/apps/web/src/features/settings/Appearance.tsx b/apps/web/src/features/settings/Appearance.tsxindex bee9059512..b38c90ae25 100644--- a/apps/web/src/features/settings/Appearance.tsx+++ b/apps/web/src/features/settings/Appearance.tsx@@ -30,10 +30,12 @@ import {import type { ThemeV2 } from '@theme/types/themeTypes';import {applyTheme,+ clearThemePreview,deleteTheme,exportTheme,getLiveTheme,isTokensDark,+ previewTheme,saveTheme,updateTheme,} from '@theme/utils/themeUtils';@@ -136,7 +138,9 @@ function ThemePreferenceRow(props: {><div class="text-sm">{props.label}</div><div class="flex items-center gap-1">- <Dropdown>+ {/* Preview only lasts while browsing: picking a default doesn't change+ the active theme, so closing always restores the live tokens. */}+ <Dropdown onOpenChange={(open) => !open && clearThemePreview()}><KobalteDropdownMenu.Triggeras={ThemeChipPill}class="h-auto text-xs rounded-lg border border-edge-muted py-1 pl-1 pr-2 hover:bg-ink/4"@@ -155,6 +159,7 @@ function ThemePreferenceRow(props: {<Dropdown.Itemclass="group touch:min-h-10"onSelect={() => props.onSelect(theme.id)}+ onFocus={() => previewTheme(theme.id)}><span class="flex min-w-0 flex-1 items-center gap-2"><ThemeChips theme={theme} size="sm" />@@ -210,6 +215,7 @@ function InterfaceThemeSelect(props: {<Dropdown.Itemclass="group touch:min-h-10"onSelect={() => props.onPick(theme.id)}+ onFocus={() => previewTheme(theme.id)}><span class="flex min-w-0 flex-1 items-center gap-2"><ThemeChips theme={theme} size="sm" />@@ -255,7 +261,15 @@ function InterfaceThemeSelect(props: {return (<div class="flex items-center gap-1">- <Dropdown open={open()} onOpenChange={setOpen}>+ <Dropdown+ open={open()}+ onOpenChange={(isOpen) => {+ setOpen(isOpen);+ // Closing without picking reverts the preview; a pick commits via+ // applyTheme first, which makes this a no-op.+ if (!isOpen) clearThemePreview();+ }}+ ><KobalteDropdownMenu.Triggeras={ThemeChipPill}class="h-auto text-xs rounded-lg border border-edge-muted py-1 pl-1 pr-2 hover:bg-ink/4"@@ -270,6 +284,7 @@ function InterfaceThemeSelect(props: {// hairline like the settings cards, rather than the heavier b4 border.as="div"class="w-60 overflow-hidden border border-ink/[0.05] bg-surface shadow-menu"+ onMouseLeave={clearThemePreview}onOpenAutoFocus={(e: Event) => {// Focus the filter input instead of the first item.e.preventDefault();@@ -286,8 +301,23 @@ function InterfaceThemeSelect(props: {type="text"value={filter()}onInput={(e) => setFilter(e.currentTarget.value)}- // Keep typing in the box rather than triggering the menu's typeahead.- onKeyDown={(e) => e.stopPropagation()}+ // Keep typing in the box rather than triggering menu typeahead.+ // Arrow into the results explicitly; item focus then drives+ // both Kobalte's keyboard navigation and the theme preview.+ onKeyDown={(e) => {+ e.stopPropagation();+ if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;+ e.preventDefault();+ const items = Array.from(+ e.currentTarget+ .closest('[role="menu"]')+ ?.querySelectorAll<HTMLElement>(+ '[role="menuitem"]:not([data-disabled])'+ ) ?? []+ );+ const item = e.key === 'ArrowDown' ? items[0] : items.at(-1);+ item?.focus();+ }}placeholder="Filter themes…"spellcheck={false}class="h-8 w-full rounded-md border border-edge-muted bg-transparent px-2.5 text-sm text-ink outline-none placeholder:text-ink-extra-muted focus:border-accent"@@ -317,7 +347,11 @@ function InterfaceThemeSelect(props: {</div><Dropdown.Group>- <Dropdown.Item class="touch:min-h-10" onSelect={props.onNewTheme}>+ <Dropdown.Item+ class="touch:min-h-10"+ onSelect={props.onNewTheme}+ onFocus={clearThemePreview}+ ><span class="flex items-center gap-2 text-ink-muted"><PlusIcon class="size-4" />New theme@@ -363,7 +397,9 @@ export function Appearance() {const startNewTheme = () => {// Initialize the new theme from the current theme's variables (already live// in the editor); mark it unsaved so the editor treats it as a new, nameable- // theme rather than the saved one it was copied from.+ // theme rather than the saved one it was copied from. Any hover preview is+ // reverted first so it doesn't become the new theme's starting point.+ clearThemePreview();setEditingThemeId(undefined);setIsThemeSaved(false);setThemeName('New Theme');@@ -411,6 +447,10 @@ export function Appearance() {};const deleteThemeById = (theme: ThemeV2) => {+ // The delete button sits inside the theme's (hovered, so previewed) row and+ // closes the dropdown programmatically, which skips onOpenChange — revert+ // the preview here so the deleted theme's colors don't linger.+ clearThemePreview();deleteTheme(theme.id);// If the editor was open on the deleted theme, close it.if (editingThemeId() === theme.id) closeEditor();diff --git a/apps/web/src/features/theme/utils/themeUtils.ts b/apps/web/src/features/theme/utils/themeUtils.tsindex 38c8f05376..4e21c7c3cb 100644--- a/apps/web/src/features/theme/utils/themeUtils.ts+++ b/apps/web/src/features/theme/utils/themeUtils.ts@@ -49,15 +49,9 @@ function isThemeV2(value: unknown): value is ThemeV2 {});}-export function applyTheme(id: string): void{- let theme = themes().find((t) => t.id === id);- if(!theme){- console.error(`theme not found: ${id}`);- theme = themes().find((t) => t.id === DEFAULT_DARK_THEME)!;- }- setCurrentThemeId(theme.id);-- // Set theme overrides+/** Writes a theme's semantic-token overrides to the document root, clearing+ * tokens the theme doesn't override. */+function setThemeOverrides(theme: ThemeV2): void{for (const token of semanticTokens) {const themeOverride = theme.overrides?.find((o) => o.token === token)if (themeOverride) {@@ -66,22 +60,85 @@ export function applyTheme(id: string): void{document.documentElement.style.removeProperty(`--theme-${token}`)}}+}+/** Writes a token set + depth to the live theme signals (the CSS variables). */+function setLiveTokens(tokens: ThemeV2Tokens, depth: number): void{batch(() => {- (Object.keys(theme!.tokens) as Array<keyof ThemeV2Tokens>).forEach((tokenKey) => {- (Object.keys(theme!.tokens[tokenKey]) as Array<'l' | 'c' | 'h'>).forEach((prop) => {- themeReactive[tokenKey][prop][1](theme!.tokens[tokenKey][prop]);+ (Object.keys(tokens) as Array<keyof ThemeV2Tokens>).forEach((tokenKey) => {+ (Object.keys(tokens[tokenKey]) as Array<'l' | 'c' | 'h'>).forEach((prop) => {+ themeReactive[tokenKey][prop][1](tokens[tokenKey][prop]);});});- setThemeDepth(theme!.depth ?? 0.15);- queueMicrotask(() => {/* scuffed af */- setIsThemeSaved(true);- syncHtmlColor();- });+ setThemeDepth(depth);});}+/** The live tokens/overrides as they were when a preview started; restored+ * when the preview ends. Null while no preview is active. */+let previewSnapshot: {+ tokens: ThemeV2Tokens;+ depth: number;+ overrides: Record<string, string>;+} | null = null;++export function applyTheme(id: string): void{+ let theme = themes().find((t) => t.id === id);+ if(!theme){+ console.error(`theme not found: ${id}`);+ theme = themes().find((t) => t.id === DEFAULT_DARK_THEME)!;+ }+ setCurrentThemeId(theme.id);+ // Committing a theme supersedes any in-flight preview; drop the snapshot so+ // clearThemePreview doesn't revert the commit.+ previewSnapshot = null;++ setThemeOverrides(theme);+ setLiveTokens(theme.tokens, theme.depth ?? 0.15);+ queueMicrotask(() => {/* scuffed af */+ setIsThemeSaved(true);+ syncHtmlColor();+ });+}++/** Temporarily shows a theme (e.g. while it's hovered/highlighted in a picker)+ * without selecting it: only the live token signals and override CSS vars+ * change — currentThemeId, saved-state, and the persisted first-paint color+ * are untouched. Revert with clearThemePreview; committing via applyTheme+ * makes the preview permanent. */+export function previewTheme(id: string): void{+ const theme = themes().find((t) => t.id === id);+ if(!theme){return}+ if(!previewSnapshot){+ const overrides: Record<string, string> = {};+ for(const token of semanticTokens){+ overrides[token] = document.documentElement.style.getPropertyValue(`--theme-${token}`);+ }+ // Snapshot the live tokens (not the selected theme id) so ending the+ // preview restores unsaved in-editor edits too.+ previewSnapshot = { tokens: getCurrentTokens(), depth: themeDepth(), overrides };+ }+ setThemeOverrides(theme);+ setLiveTokens(theme.tokens, theme.depth ?? 0.15);+}++/** Ends an active theme preview, restoring the pre-preview tokens. No-op when+ * nothing is being previewed. */+export function clearThemePreview(): void{+ if(!previewSnapshot){return}+ for(const token of semanticTokens){+ const value = previewSnapshot.overrides[token];+ if(value){+ document.documentElement.style.setProperty(`--theme-${token}`, value);+ } else {+ document.documentElement.style.removeProperty(`--theme-${token}`);+ }+ }+ setLiveTokens(previewSnapshot.tokens, previewSnapshot.depth);+ previewSnapshot = null;+}+/** 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). */diff --git a/apps/web/src/lib/core/hotkey/hotkeys.ts b/apps/web/src/lib/core/hotkey/hotkeys.tsindex ea1ecc4eed..92d6ece56e 100644--- a/apps/web/src/lib/core/hotkey/hotkeys.ts+++ b/apps/web/src/lib/core/hotkey/hotkeys.ts@@ -126,6 +126,8 @@ export function registerHotkey(icon,commandPaletteIcon,displayComponent,+ onHighlight,+ onHighlightEnd,tags,keywords,surfaceNestedCommands,@@ -234,6 +236,8 @@ export function registerHotkey(icon,commandPaletteIcon,displayComponent,+ onHighlight,+ onHighlightEnd,tags,keywords,surfaceNestedCommands,diff --git a/apps/web/src/lib/core/hotkey/types.ts b/apps/web/src/lib/core/hotkey/types.tsindex e27ace3ca1..e253ac8f09 100644--- a/apps/web/src/lib/core/hotkey/types.ts+++ b/apps/web/src/lib/core/hotkey/types.ts@@ -48,6 +48,10 @@ export interface HotkeyCommand {commandPaletteIcon?: Component<{ class?: string }>;// Optional component to display in the command palettedisplayComponent?: Component<any>;+ // Called when the command becomes the highlighted item in the command palette (hover or keyboard selection). Use for side effects like live previews.+ onHighlight?: () => void;+ // Called when the command stops being the highlighted item in the command palette (selection moved, menu closed). Pair with onHighlight to undo its side effects.+ onHighlightEnd?: () => void;// Optional tags for categorizing in the command palette.tags?: string[];// Optional related search terms for the command palette.@@ -174,6 +178,18 @@ export interface HotkeyRegistrationOptions {* Optional component to display in command palette rather than description.*/displayComponent?: Component<any>;+ /**+ * Called when the command becomes the highlighted item in the command+ * palette (hover or keyboard selection). Use for side effects like live+ * previews.+ */+ onHighlight?: () => void;+ /**+ * Called when the command stops being the highlighted item in the command+ * palette (selection moved, menu closed). Pair with onHighlight to undo its+ * side effects.+ */+ onHighlightEnd?: () => void;/*** Optional tags for categorizing in the command palette.*/