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.

feat(themes): restyle theme menu for clarity (#4037)

Aidan Holloway-Bidwell25041242b155
diff --git a/js/app/packages/app/component/GlobalHotkeys.tsx b/js/app/packages/app/component/GlobalHotkeys.tsx
index b1e02fdf51..0da5663c52 100644
--- a/js/app/packages/app/component/GlobalHotkeys.tsx
+++ b/js/app/packages/app/component/GlobalHotkeys.tsx
@@ -25,14 +25,8 @@ import { debounce } from '@solid-primitives/scheduled';
import { ThemeChips } from '@theme/components/ThemeChips';
import type { ThemeV2 } from '@theme/types/themeTypes';
import { registerHotkey } from 'core/hotkey/hotkeys';
-import { type Component, createMemo, onCleanup } from 'solid-js';
-import {
- setDarkModeTheme,
- setLightModeTheme,
- setThemeShouldMatchSystem,
- themeShouldMatchSystem,
- themes,
-} from '../../theme/signals/themeSignals';
+import { type Component, onCleanup } from 'solid-js';
+import { themes } from '../../theme/signals/themeSignals';
import { applyTheme } from '../../theme/utils/themeUtils';
import { globalSplitManager } from '../signal/splitLayout';
@@ -297,67 +291,6 @@ export default function GlobalShortcuts() {
});
});
- const setPreferredLightScope = registerHotkey({
- scopeId: 'global',
- description: 'Set preferred light mode 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 preferred dark mode 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: createMemo(
- () =>
- `${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 2f06a8f711..68075e4ff5 100644
--- a/js/app/packages/app/component/Root.tsx
+++ b/js/app/packages/app/component/Root.tsx
@@ -85,7 +85,6 @@ import { currentThemeId } from '../../theme/signals/themeSignals';
import {
applyTheme,
ensureMinimalThemeContrast,
- systemThemeEffect,
} from '../../theme/utils/themeUtils';
import { Login } from './auth/Login';
import { setCookie } from './auth/Shared';
@@ -501,7 +500,6 @@ export function Root() {
});
onMount(() => {
- systemThemeEffect();
applyTheme(currentThemeId());
ensureMinimalThemeContrast();
});
diff --git a/js/app/packages/app/component/settings/Appearance.tsx b/js/app/packages/app/component/settings/Appearance.tsx
index 067a95cdcf..4ee44eb985 100644
--- a/js/app/packages/app/component/settings/Appearance.tsx
+++ b/js/app/packages/app/component/settings/Appearance.tsx
@@ -1,12 +1,15 @@
import { monochromeIcons, setMonochromeIcons, setTooltipsEnabled, tooltipsEnabled } from '@ui/signals/signals';
import { ThemeEditorAdvanced } from '@theme/components/ThemeEditorAdvanced';
-import { ThemeEditorBasic } from '@theme/components/ThemeEditorBasic';
+import { ThemeEditorBasic, randomizeTheme } from '@theme/components/ThemeEditorBasic';
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 { TabsInset } from '@core/component/TabsInset';
-import { Panel, ToggleSwitch } from '@ui';
+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';
type PanelA = 'basic' | 'advanced';
type PanelB ='themes' | 'ui'
@@ -37,13 +40,16 @@ function UserInterface() {
export function Appearance() {
const [activeTabA, setActiveTabA] = createSignal<PanelA>('basic');
const [activeTabB, setActiveTabB] = createSignal<PanelB>('themes');
+ const [showFilters, setShowFilters] = createSignal(false);
return (
<div class="h-full overflow-hidden flex justify-center p-2">
<div
class="max-w-200 size-full"
style={{
- 'grid-template-rows': `${isMobile() ? '322.5px' : '432.5px'} 1fr`,
+ // 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-columns': '1fr',
'overflow': 'hidden',
'display': 'grid',
@@ -72,7 +78,7 @@ export function Appearance() {
</Panel.Toolbar>
</Show>
- <Panel.Body scroll>
+ <Panel.Body scroll={activeTabA() === 'advanced'}>
<Show when={activeTabA() === 'basic'}>
<ThemeEditorBasic />
</Show>
@@ -93,7 +99,48 @@ export function Appearance() {
value={activeTabB()}
defaultValue="list"
/>
+ <div class="flex-1" />
+ <Show when={activeTabB() === 'themes'}>
+ <Button
+ label="Filter Themes"
+ onPointerDown={() => setShowFilters((v) => !v)}
+ variant={showFilters() ? 'cta' : 'ghost'}
+ size="icon-sm"
+ >
+ <IconFunnel />
+ </Button>
+ </Show>
+ <Button
+ label="Randomize Theme"
+ onPointerDown={randomizeTheme}
+ variant="ghost"
+ size="icon-sm"
+ class="ml-1.5"
+ >
+ <IconDice />
+ </Button>
</Panel.Header>
+ <Show when={activeTabB() === 'themes' && showFilters()}>
+ <Panel.Toolbar class="gap-4 pl-5">
+ <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"
+ onClick={() => setShowLightThemes((v) => !v)}
+ >
+ <InlineCheckbox checked={showLightThemes()} />
+ Light
+ </button>
+ <button
+ type="button"
+ class="inline-flex items-center gap-1.5 text-xs text-ink-muted hover:text-ink"
+ onClick={() => setShowDarkThemes((v) => !v)}
+ >
+ <InlineCheckbox checked={showDarkThemes()} />
+ Dark
+ </button>
+ </Panel.Toolbar>
+ </Show>
<Panel.Body scroll>
<Show when={activeTabB() === 'themes'}>
<ThemeList />
diff --git a/js/app/packages/theme/components/ThemeChips.tsx b/js/app/packages/theme/components/ThemeChips.tsx
index 6bfb09eb13..50d390bae6 100644
--- a/js/app/packages/theme/components/ThemeChips.tsx
+++ b/js/app/packages/theme/components/ThemeChips.tsx
@@ -1,29 +1,41 @@
-import type { ThemeV2 } from "@theme/types/themeTypes";
+import type { ThemeV2 } from '@theme/types/themeTypes';
+import IconTextA from '@phosphor-icons/core/regular/text-a-underline.svg?component-solid';
+type Token = { l: number; c: number; h: number };
+
+/** A theme swatch: an encompassing square of the theme's panel surface with the
+ * accent and ink (A) inside. Always shows the theme's original intended colors
+ * — each theme is intrinsically light or dark. */
export function ThemeChips(props: { theme: ThemeV2 }) {
- const oklch = (token: { l: number; c: number; h: number }) => {
- if (!token) return 'transparent';
+ const oklch = (token: Token) => {
+ if (!token) { return 'transparent'; }
return `oklch(${token.l} ${token.c} ${token.h}deg)`;
};
- const a0 = () => oklch(props.theme.tokens.a0);
- const b0 = () => oklch(props.theme.tokens.b0);
- const c0 = () => oklch(props.theme.tokens.c0);
+ // Approximate the app's prevalent panel surface rather than the darkest base
+ // background: lift b0's lightness by the theme's depth, matching how Layer
+ // elevates surfaces (b0l + (layer/5) * themeDepth) at a typical panel depth.
+ // Flat b0 made the swatches read too dark and blend together.
+ const PANEL_LAYER = 2;
+ const bg = () => {
+ const b0 = props.theme.tokens.b0;
+ const l = b0.l + (PANEL_LAYER / 5) * (props.theme.depth ?? 0.15);
+ return `oklch(${l} ${b0.c} ${b0.h}deg)`;
+ };
+ const accent = () => oklch(props.theme.tokens.a0);
+ const ink = () => oklch(props.theme.tokens.c0);
+ // Uniform padding around and gap between the items so the spacing reads evenly.
return (
- <span class="inline-flex items-center gap-0.5">
- <span
- class="inline-block size-2.5 rounded-xs border border-edge-muted"
- style={{ 'background-color': a0() }}
- />
- <span
- class="inline-block size-2.5 rounded-xs border border-edge-muted"
- style={{ 'background-color': b0() }}
- />
+ <span
+ class="inline-flex items-center rounded-sm border border-edge-muted"
+ style={{ 'background-color': bg(), padding: '8px', gap: '8px' }}
+ >
<span
- class="inline-block size-2.5 rounded-xs border border-edge-muted"
- style={{ 'background-color': c0() }}
+ class="inline-block rounded-xs"
+ style={{ 'background-color': accent(), width: '13px', height: '13px' }}
/>
+ <IconTextA style={{ color: ink(), width: '18px', height: '18px' }} />
</span>
- )
+ );
}
diff --git a/js/app/packages/theme/components/ThemeCrud.tsx b/js/app/packages/theme/components/ThemeCrud.tsx
index 1720744f90..42461eec5b 100644
--- a/js/app/packages/theme/components/ThemeCrud.tsx
+++ b/js/app/packages/theme/components/ThemeCrud.tsx
@@ -16,20 +16,10 @@ export function ThemeCrud(props: ThemeCrudProps) {
return (
<div
- style="
- grid-auto-columns: min-content;
- background-color: var(--b0);
- grid-auto-flow: column;
- box-sizing: border-box;
- align-items: center;
- direction: rtl;
- padding: 0 12px;
- display: grid;
- height: 100%;
- gap: 4.5px;
- "
+ class="flex shrink-0 items-center gap-0.5"
onClick={stop}
onPointerDown={stop}
+ onKeyDown={stop}
>
<Button
label="Copy To Clipboard"
diff --git a/js/app/packages/theme/components/ThemeEditorBasic.tsx b/js/app/packages/theme/components/ThemeEditorBasic.tsx
index 9f9c984606..325a85bae4 100644
--- a/js/app/packages/theme/components/ThemeEditorBasic.tsx
+++ b/js/app/packages/theme/components/ThemeEditorBasic.tsx
@@ -1,7 +1,9 @@
-import { batch, createEffect, createSignal, onCleanup, onMount } from 'solid-js';
+import { batch, createEffect, createSignal, type JSX, onCleanup, onMount, untrack } from 'solid-js';
import { setThemeDepth, themeDepth } from '../signals/themeSignals';
import { themeReactive } from '../signals/themeReactive';
+import { flipLightDark } from '../utils/themeUtils';
import { isMobile } from '@core/mobile/isMobile';
+import IconFlip from '@phosphor-icons/core/regular/circle-half-tilt.svg?component-solid';
function setLightness(lightness: number) {
batch(() => {
@@ -112,6 +114,87 @@ export function randomizeTheme(){
});
}
+/** Numeric value box shown to the right of each slider. Displays/edits the value
+ * on a display scale (default 0-100) mapped from the control's internal range.
+ * Pass displayMin/displayMax for a centered scale, e.g. -100..100 for Contrast.
+ * Keeps its own text state while typing (mirroring ThemeEditorAdvanced) so
+ * reactive updates from the slider don't fight the user's input. */
+function NumberInput(props: {
+ get: () => number;
+ set: (n: number) => void;
+ min: number;
+ max: number;
+ displayMin?: number;
+ displayMax?: number;
+ action?: JSX.Element;
+}) {
+ const dMin = () => props.displayMin ?? 0;
+ const dMax = () => props.displayMax ?? 100;
+ const toDisplay = (v: number) =>
+ dMin() + ((v - props.min) / (props.max - props.min)) * (dMax() - dMin());
+ const fromDisplay = (d: number) =>
+ props.min + ((d - dMin()) / (dMax() - dMin())) * (props.max - props.min);
+
+ const [text, setText] = createSignal('');
+ const [isSetByInput, setIsSetByInput] = createSignal(false);
+
+ createEffect(() => {
+ const value = props.get();
+ if (untrack(isSetByInput)) { setIsSetByInput(false); }
+ else { setText(Math.round(toDisplay(value)).toString()); }
+ });
+
+ return (
+ <div style="display: flex; align-items: center; gap: 4px; flex: none;">
+ <div
+ style="
+ background-color: var(--b1);
+ border: 1px solid var(--b4);
+ box-sizing: border-box;
+ align-items: center;
+ border-radius: 4px;
+ padding: 3px 6px;
+ display: flex;
+ width: 8ch;
+ gap: 3px;
+ "
+ >
+ {props.action}
+ <input
+ class="theme-editor-basic-num"
+ type="number"
+ value={text()}
+ min={dMin()}
+ max={dMax()}
+ step={1}
+ onInput={(e) => {
+ const raw = e.currentTarget.value;
+ setIsSetByInput(true);
+ setText(raw);
+ const d = parseFloat(raw);
+ if (!Number.isNaN(d)) { props.set(fromDisplay(Math.max(dMin(), Math.min(dMax(), d)))); }
+ }}
+ onBlur={() => setText(Math.round(toDisplay(props.get())).toString())}
+ style="
+ font-family: var(--font-mono);
+ background: transparent;
+ box-sizing: border-box;
+ text-align: right;
+ color: var(--c0);
+ font-size: 12px;
+ min-width: 0;
+ outline: none;
+ border: none;
+ padding: 0;
+ flex: 1;
+ "
+ />
+ </div>
+ <span style="color: var(--c2); font-size: 12px;">%</span>
+ </div>
+ );
+}
+
export function ThemeEditorBasic(){
const [canvasThumbDrag, setCanvasThumbDrag] = createSignal(false);
@@ -321,9 +404,18 @@ export function ThemeEditorBasic(){
.theme-editor-basic-slider::-moz-range-thumb {
opacity: 0;
}
+ .theme-editor-basic-num::-webkit-inner-spin-button,
+ .theme-editor-basic-num::-webkit-outer-spin-button {
+ -webkit-appearance: none;
+ margin: 0;
+ }
+ .theme-editor-basic-num {
+ -moz-appearance: textfield;
+ }
`}</style>
<div
+ class="@container"
style="
font-family: var(--font-sans);
padding: 8px 20px 12px 20px;
@@ -332,15 +424,14 @@ export function ThemeEditorBasic(){
height: min-content;
font-weight: 500;
font-size: 12px;
- display: grid;
- gap: 20px;
"
>
+ <div class="grid gap-5 @2xl:grid-cols-2 @2xl:items-start">
<div
onPointerDown={handleCanvasPointerDown}
ref={canvasContainerRef}
+ class={isMobile() ? 'h-[140px]' : 'h-[250px]'}
style={{
- 'height': isMobile() ? '140px' : '250px',
'border': '1px solid var(--b4)',
'border-radius': '6px',
'position': 'relative',
@@ -375,32 +466,21 @@ export function ThemeEditorBasic(){
</div>
<div
+ class="grid h-min w-full gap-3 @2xl:gap-5"
style="
- grid-template-columns: 11ch 1fr;
- height: min-content;
- gap: 20px 10px;
- display: grid;
- width: 100%;
+ --b4: color-mix(in oklch, oklch(var(--b4l) var(--b4c) var(--b4h)), oklch(var(--c4l) var(--c4c) var(--c4h)) 30%);
"
>
- <div style="position: relative;">
- <div
- style="
- transform: translateY(-50%);
- position: absolute;
- top: 50%;
- left: 0;
- "
- >
- Chroma
- </div>
- </div>
+ <div class="flex items-center gap-3 @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
style="
box-sizing: border-box;
position: relative;
height: 10px;
- width: 100%;
+ min-width: 0;
+ flex: 1;
"
>
<div
@@ -428,7 +508,7 @@ export function ThemeEditorBasic(){
'border-radius': '2px',
'position': 'absolute',
'height': '18px',
- 'width': '18px',
+ 'width': '9px',
'top': '50%',
}}
/>
@@ -457,25 +537,25 @@ export function ThemeEditorBasic(){
min="0.0"
/>
</div>
-
- <div style="position: relative;">
- <div
- style="
- transform: translateY(-50%);
- position: absolute;
- top: 50%;
- left: 0;
- "
- >
- Saturation
- </div>
+ <NumberInput
+ get={() => themeReactive.a0.c[0]()}
+ set={(n) => setChroma(n, parseFloat(sliderSaturationRef.value))}
+ min={0}
+ max={0.37}
+ />
+ </div>
</div>
+
+ <div class="flex items-center gap-3 @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
style="
box-sizing: border-box;
position: relative;
height: 10px;
- width: 100%;
+ min-width: 0;
+ flex: 1;
"
>
<div
@@ -518,7 +598,7 @@ export function ThemeEditorBasic(){
'border-radius': '2px',
'position': 'absolute',
'height': '18px',
- 'width': '18px',
+ 'width': '9px',
'top': '50%',
}}
/>
@@ -548,25 +628,28 @@ export function ThemeEditorBasic(){
min="0.0"
/>
</div>
-
- <div style="position: relative;">
- <div
- style="
- transform: translateY(-50%);
- position: absolute;
- top: 50%;
- left: 0;
- "
- >
- Contrast
- </div>
+ <NumberInput
+ get={() => {
+ const denom = themeReactive.a0.c[0]() * 0.37 * 0.6;
+ return denom ? themeReactive.b0.c[0]() / denom : 0;
+ }}
+ set={(n) => setSaturation(n)}
+ min={0}
+ max={1}
+ />
</div>
+ </div>
+
+ <div class="flex items-center gap-3 @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
style="
box-sizing: border-box;
position: relative;
height: 10px;
- width: 100%;
+ min-width: 0;
+ flex: 1;
"
>
<div
@@ -613,7 +696,7 @@ export function ThemeEditorBasic(){
'border-radius': '2px',
'position': 'absolute',
'height': '18px',
- 'width': '18px',
+ 'width': '9px',
'top': '50%',
}}
/>
@@ -645,27 +728,38 @@ export function ThemeEditorBasic(){
min="0.0"
/>
</div>
-
-
-
- <div style="position: relative;">
- <div
- style="
- transform: translateY(-50%);
- position: absolute;
- top: 50%;
- left: 0;
- "
- >
- Depth
- </div>
+ <NumberInput
+ get={() => getContrastFromY(themeReactive.b0.l[0]())}
+ set={(n) => setContrast(n)}
+ min={0}
+ max={0.8}
+ displayMin={-100}
+ displayMax={100}
+ action={
+ <button
+ type="button"
+ aria-label="Flip light / dark"
+ onPointerDown={flipLightDark}
+ class="flex shrink-0 cursor-pointer items-center justify-center text-ink-muted hover:text-ink"
+ style="width: 14px; height: 14px; padding: 0; border: none; background: none;"
+ >
+ <IconFlip style={{ width: '14px', height: '14px' }} />
+ </button>
+ }
+ />
</div>
+ </div>
+
+ <div class="flex items-center gap-3 @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
style="
box-sizing: border-box;
position: relative;
height: 10px;
- width: 100%;
+ min-width: 0;
+ flex: 1;
"
>
<div
@@ -708,7 +802,7 @@ export function ThemeEditorBasic(){
'border-radius': '2px',
'position': 'absolute',
'height': '18px',
- 'width': '18px',
+ 'width': '9px',
'top': '50%',
}}
/>
@@ -740,7 +834,16 @@ export function ThemeEditorBasic(){
min="0.0"
/>
</div>
+ <NumberInput
+ get={() => themeDepth()}
+ set={(n) => setThemeDepth(n)}
+ min={0}
+ max={0.4}
+ />
+ </div>
+ </div>
</div>
+ </div>
</div>
</>
);
diff --git a/js/app/packages/theme/components/ThemeList.tsx b/js/app/packages/theme/components/ThemeList.tsx
index 1b1d6a1a5d..8d28f675a8 100644
--- a/js/app/packages/theme/components/ThemeList.tsx
+++ b/js/app/packages/theme/components/ThemeList.tsx
@@ -1,97 +1,65 @@
-import { currentThemeId, isThemeSaved, themes } from '../signals/themeSignals';
+import { currentThemeId, isThemeSaved, showDarkThemes, showLightThemes, themes } from '../signals/themeSignals';
import { useAnalytics } from 'app/component/analytics-context';
-import { applyTheme } from '../utils/themeUtils';
-import { ColorSwatch } from './ColorSwatch';
+import { applyTheme, isTokensDark } from '../utils/themeUtils';
+import { ThemeChips } from './ThemeChips';
import { ThemeCrud } from './ThemeCrud';
+import { cn } from '@ui';
-import { For } from 'solid-js';
+import { createMemo, For } from 'solid-js';
function ThemeList() {
const analytics = useAnalytics()
- return (
- <>
- <style>{`
- .theme-list-item-name.current-theme{
- transition: none !important;
- color: var(--a0) !important;
- }
-
- @media(hover){
- .theme-list-item-name:hover{
- transition: none !important;
- color: var(--a0) !important;
- }
- }
- `}</style>
+ const visibleThemes = createMemo(() =>
+ themes().filter((theme) =>
+ isTokensDark(theme.tokens) ? showDarkThemes() : showLightThemes()
+ )
+ );
- <div
- style="
- grid-template-columns: min-content 1fr min-content;
- background-color: var(--b3);
- box-sizing: border-box;
- grid-auto-rows: 61px;
- overflow-x: hidden;
- font-size: 14px;
- display: grid;
- gap: 1px 0px;
- "
- >
- <For each={themes()}>
- {(theme) => (
- <>
- <div
- style="
- background-color: var(--b0);
- box-sizing: border-box;
- align-items: center;
- padding: 0 20px;
- display: flex;
- height: 100%;
- width: 100%;
- gap: 5px;
- "
- >
- <ColorSwatch
- color={`oklch(${theme.tokens.a0.l} ${theme.tokens.a0.c} ${theme.tokens.a0.h}deg)`}
- width={'10px'}
- />
- <ColorSwatch
- color={`oklch(${theme.tokens.b0.l} ${theme.tokens.b0.c} ${theme.tokens.b0.h}deg)`}
- width={'10px'}
- />
- <ColorSwatch
- color={`oklch(${theme.tokens.c0.l} ${theme.tokens.c0.c} ${theme.tokens.c0.h}deg)`}
- width={'10px'}
- />
- </div>
+ return (
+ <div class="@container p-2">
+ <div class="grid grid-cols-1 gap-2 @md:grid-cols-2 @2xl:grid-cols-3">
+ <For each={visibleThemes()}>
+ {(theme) => {
+ const selected = () => theme.id === currentThemeId() && isThemeSaved();
+ const select = () => {
+ analytics.track('theme_changed', { themeId: theme.id })
+ applyTheme(theme.id)
+ };
+ return (
+ // role="button" (not <button>) because the card contains ThemeCrud's
+ // own buttons, and nesting native buttons is invalid HTML.
<div
- class={`theme-list-item-name ${theme.id === currentThemeId() && isThemeSaved() ? 'current-theme' : ''}`}
- onClick={() => {
- analytics.track('theme_changed', {themeId: theme.id})
- applyTheme(theme.id)
+ role="button"
+ tabIndex={0}
+ class={cn(
+ 'flex min-w-0 cursor-pointer items-center gap-2 rounded-lg border bg-surface p-2 transition-colors duration-[var(--transition)]',
+ selected() ? 'border-accent' : 'border-edge-muted hover:border-ink-muted'
+ )}
+ onClick={select}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ e.preventDefault()
+ select()
+ }
}}
- style="
- transition: color var(--transition);
- background-color: var(--b0);
- box-sizing: border-box;
- white-space: nowrap;
- align-items: center;
- padding: 0 20px;
- cursor: pointer;
- display: flex;
- height: 100%;
- width: 100%;
- "
>
- {theme.name}
+ <ThemeChips theme={theme} />
+ <span
+ class={cn(
+ 'min-w-0 flex-1 truncate text-sm',
+ selected() ? 'text-accent' : 'text-ink'
+ )}
+ >
+ {theme.name}
+ </span>
+ <ThemeCrud themeId={theme.id} />
</div>
- <ThemeCrud themeId={theme.id} />
- </>
- )}
+ )
+ }}
</For>
</div>
- </>
+ </div>
);
}
diff --git a/js/app/packages/theme/components/ThemeTools.tsx b/js/app/packages/theme/components/ThemeTools.tsx
index 5acbae64f4..b568d2e125 100644
--- a/js/app/packages/theme/components/ThemeTools.tsx
+++ b/js/app/packages/theme/components/ThemeTools.tsx
@@ -1,8 +1,5 @@
import { currentThemeId, isThemeSaved, themes } from '../signals/themeSignals';
-import IconLightDark from '@icon/macro-light-dark.svg';
-import { invertTheme, saveTheme } from '../utils/themeUtils';
-import { randomizeTheme } from './ThemeEditorBasic';
-import IconDice from '@phosphor-icons/core/regular/dice-five.svg?component-solid';
+import { saveTheme } from '../utils/themeUtils';
import IconSave from '@phosphor-icons/core/regular/floppy-disk-back.svg?component-solid';
import { createMemo, Show } from 'solid-js';
import { Button, cn } from '@ui';
@@ -44,24 +41,6 @@ function ThemeTools(props: { class?: string }) {
</Button>
</Show>
- <Button
- label="Randomize Theme"
- onPointerDown={randomizeTheme}
- variant="ghost"
- size="icon-sm"
- >
- <IconDice />
- </Button>
-
- <Button
- label="Toggle Light / Dark"
- onPointerDown={invertTheme}
- variant="ghost"
- size="icon-sm"
- >
- <IconLightDark />
- </Button>
-
<div
onKeyDown={(e) => {
if(e.key === 'Enter'){
diff --git a/js/app/packages/theme/signals/themeSignals.ts b/js/app/packages/theme/signals/themeSignals.ts
index 5aa438a4c2..34661bcb0c 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_LIGHT_THEME, DEFAULT_THEMES } from '../constants';
+import { DEFAULT_DARK_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';
@@ -25,51 +25,21 @@ setUserThemes(
})
);
-export const [currentThemeId, setCurrentThemeId_] = makePersisted(
+export const [currentThemeId, setCurrentThemeId] = makePersisted(
createSignal<string>(DEFAULT_DARK_THEME),
{name: 'macro-selected-theme'}
);
-// If theme should match system, when we set current theme, we also set the corresponding mode's theme
-// This avoids the issue where a user sets a theme, and then refreshes, and gets reverted to their preferred mode's theme.
-export const setCurrentThemeId = ( ...args: Parameters<typeof setCurrentThemeId_> ) => {
- setCurrentThemeId_(...args);
- if(themeShouldMatchSystem()){
- systemMode() === 'dark' ? setDarkModeTheme(...args) : setLightModeTheme(...args);
- }
-};
-
export const themes = createMemo(() => [...DEFAULT_THEMES, ...userThemes()]);
-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(
+// Theme-list filters: whether light and/or dark themes are shown in the list.
+export const [showLightThemes, setShowLightThemes] = makePersisted(
createSignal<boolean>(true),
- {name: 'macro-theme-should-match-system'}
+ {name: 'macro-show-light-themes'}
);
-
-const supportsMatchMedia =
- typeof window !== 'undefined' && typeof window.matchMedia === 'function';
-
-export const [systemMode, setSystemMode] = createSignal<'dark' | 'light'>(
- supportsMatchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
- ? 'dark'
- : 'light'
+export const [showDarkThemes, setShowDarkThemes] = makePersisted(
+ createSignal<boolean>(true),
+ {name: 'macro-show-dark-themes'}
);
-if (supportsMatchMedia) {
- const darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)');
- darkModeQuery.addEventListener('change', (e: MediaQueryListEvent) => {
- setSystemMode(e.matches ? 'dark' : 'light');
- });
-}
-
export const [themeDepth, setThemeDepth] = createSignal<number>(0.15);
diff --git a/js/app/packages/theme/utils/themeUtils.ts b/js/app/packages/theme/utils/themeUtils.ts
index 305f326e72..44dd4ea2c9 100644
--- a/js/app/packages/theme/utils/themeUtils.ts
+++ b/js/app/packages/theme/utils/themeUtils.ts
@@ -1,8 +1,8 @@
-import { currentThemeId, darkModeTheme, lightModeTheme, setCurrentThemeId, setHtmlColor, setIsThemeSaved, setThemeDepth, setUserThemes, systemMode, themeDepth, themeShouldMatchSystem, themes, userThemes} from '../signals/themeSignals';
+import { currentThemeId, setCurrentThemeId, setHtmlColor, setIsThemeSaved, setThemeDepth, setUserThemes, themeDepth, themes, 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, createEffect, on } from 'solid-js';
+import { batch } from 'solid-js';
import { DEFAULT_DARK_THEME } from '../constants';
export function exportTheme(themeId?: string){
@@ -49,20 +49,6 @@ function isThemeV2(value: unknown): value is ThemeV2 {
});
}
-export function systemThemeEffect(){
- createEffect(
- on(
- [themeShouldMatchSystem, systemMode, darkModeTheme, lightModeTheme],
- () => {
- if(themeShouldMatchSystem()){
- applyTheme(systemMode() === 'dark' ? darkModeTheme() : lightModeTheme());
- }
- },
- { defer: true }
- )
- );
-}
-
export function applyTheme(id: string): void{
let theme = themes().find((t) => t.id === id);
if(!theme){
@@ -81,16 +67,23 @@ export function applyTheme(id: string): void{
setThemeDepth(theme!.depth ?? 0.15);
queueMicrotask(() => {/* scuffed af */
setIsThemeSaved(true);
- setHtmlColor({color: `oklch(${themeReactive.b0.l[0]()} ${themeReactive.b0.c[0]()} ${themeReactive.b0.h[0]()}deg)`});
+ syncHtmlColor();
});
});
}
-export function invertTheme(): void{
+/** 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)`});
+}
+
+/** Flips the lightness of every background (b*) and text (c*) token, leaving
+ * chroma and hue untouched. The shared primitive behind light/dark mode. */
+function invertLightness(): void{
batch(() => {
themeReactive.b0.l[1](1 - themeReactive.b0.l[0]());
- themeReactive.b2.l[1](1 - themeReactive.b2.l[0]());
themeReactive.b1.l[1](1 - themeReactive.b1.l[0]());
+ themeReactive.b2.l[1](1 - themeReactive.b2.l[0]());
themeReactive.b3.l[1](1 - themeReactive.b3.l[0]());
themeReactive.b4.l[1](1 - themeReactive.b4.l[0]());
themeReactive.c0.l[1](1 - themeReactive.c0.l[0]());
@@ -101,6 +94,32 @@ export function invertTheme(): void{
});
}
+/** Flips the theme between light and dark by inverting the background/text lightness
+ * — the same axis as the contrast slider's sign. Treated as an edit: marks the theme
+ * unsaved, unless the flip lands back on the stored theme (then it's saved again). */
+export function flipLightDark(): void{
+ invertLightness();
+ queueMicrotask(() => {
+ setIsThemeSaved(liveMatchesStoredTheme());
+ syncHtmlColor();
+ });
+}
+
+/** True when the live theme equals the currently-selected stored theme, within a
+ * float tolerance (1 − (1 − l) from a double flip isn't bit-exact). */
+function liveMatchesStoredTheme(): boolean{
+ const stored = themes().find((t) => t.id === currentThemeId());
+ if(!stored){return false}
+ const live = getCurrentTokens();
+ const close = (a: number, b: number) => Math.abs(a - b) < 1e-6;
+ const tokensMatch = (Object.keys(stored.tokens) as Array<keyof ThemeV2Tokens>).every((k) =>
+ close(live[k].l, stored.tokens[k].l) &&
+ close(live[k].c, stored.tokens[k].c) &&
+ close(live[k].h, stored.tokens[k].h)
+ );
+ return tokensMatch && close(themeDepth(), stored.depth ?? 0.15);
+}
+
function getCurrentTokens(): ThemeV2Tokens{
const themeTokens: ThemeV2Tokens = {
a0: { l: themeReactive.a0.l[0](), c: themeReactive.a0.c[0](), h: themeReactive.a0.h[0]()},
@@ -145,9 +164,9 @@ export function deleteTheme(id: string): void{
}
}
-/** Returns true when the current theme has a dark background (ink lightness > panel lightness). */
-function _isThemeDark(): boolean {
- return themeReactive.c0.l[0]() > themeReactive.b0.l[0]();
+/** Intrinsic darkness of a stored theme: dark when text is lighter than background. */
+export function isTokensDark(tokens: ThemeV2Tokens): boolean {
+ return tokens.c0.l > tokens.b0.l;
}
/** Checks if the theme contrast is too low, and if so, applies a readable theme. This is to prevent malicious actors sending "Theme Viruses" which make a user's theme unusable. */