Skip to content

Commit 5db47a8

Browse files
feat(desktop): add neutral accent color (#563)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5e6083e commit 5db47a8

2 files changed

Lines changed: 50 additions & 22 deletions

File tree

desktop/src/features/settings/ui/SettingsPanels.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import type {
2222
} from "@/features/notifications/hooks";
2323
import { RelayMembersSettingsCard } from "@/features/relay-members/ui/RelayMembersSettingsCard";
2424
import { cn } from "@/shared/lib/cn";
25-
import { ACCENT_COLORS, useTheme } from "@/shared/theme/ThemeProvider";
25+
import {
26+
ACCENT_COLORS,
27+
NEUTRAL_ACCENT,
28+
useTheme,
29+
} from "@/shared/theme/ThemeProvider";
2630
import { SYNTAX_THEMES, isLightTheme } from "@/shared/theme/theme-loader";
2731
import { ChannelTemplatesSettingsCard } from "./ChannelTemplatesSettingsCard";
2832
import { DoctorSettingsPanel } from "./DoctorSettingsPanel";
@@ -128,7 +132,8 @@ function formatThemeLabel(name: string): string {
128132
}
129133

130134
function ThemeSettingsCard() {
131-
const { setTheme, themeName, accentColor, setAccentColor } = useTheme();
135+
const { setTheme, themeName, isDark, accentColor, setAccentColor } =
136+
useTheme();
132137
const [search, setSearch] = useState("");
133138
const didScrollRef = useRef(false);
134139
const activeRef = (node: HTMLButtonElement | null) => {
@@ -209,25 +214,34 @@ function ThemeSettingsCard() {
209214
<div className="mt-4">
210215
<h3 className="mb-2 text-sm font-medium">Accent Color</h3>
211216
<div className="flex gap-2">
212-
{ACCENT_COLORS.map((color) => (
213-
<button
214-
className={cn(
215-
"flex h-7 w-7 items-center justify-center rounded-full transition-transform hover:scale-110",
216-
accentColor === color.value &&
217-
"ring-2 ring-ring ring-offset-2 ring-offset-background",
218-
)}
219-
data-testid={`accent-color-${color.name.toLowerCase()}`}
220-
key={color.value}
221-
onClick={() => setAccentColor(color.value)}
222-
style={{ backgroundColor: color.value }}
223-
title={color.name}
224-
type="button"
225-
>
226-
{accentColor === color.value && (
227-
<Check className="h-3.5 w-3.5 text-white" />
228-
)}
229-
</button>
230-
))}
217+
{ACCENT_COLORS.map((color) => {
218+
const isNeutral = color.value === NEUTRAL_ACCENT;
219+
const swatchColor = isNeutral
220+
? "hsl(var(--foreground))"
221+
: color.value;
222+
const checkClassName =
223+
isNeutral && isDark ? "text-black" : "text-white";
224+
225+
return (
226+
<button
227+
className={cn(
228+
"flex h-7 w-7 items-center justify-center rounded-full border border-border/50 transition-transform hover:scale-110",
229+
accentColor === color.value &&
230+
"ring-2 ring-ring ring-offset-2 ring-offset-background",
231+
)}
232+
data-testid={`accent-color-${color.name.toLowerCase()}`}
233+
key={color.value}
234+
onClick={() => setAccentColor(color.value)}
235+
style={{ backgroundColor: swatchColor }}
236+
title={color.name}
237+
type="button"
238+
>
239+
{accentColor === color.value && (
240+
<Check className={cn("h-3.5 w-3.5", checkClassName)} />
241+
)}
242+
</button>
243+
);
244+
})}
231245
</div>
232246
</div>
233247
</section>

desktop/src/shared/theme/ThemeProvider.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import {
1818
const STORAGE_KEY = "sprout-theme";
1919
const CACHE_KEY = "sprout-theme-cache";
2020
const ACCENT_KEY = "sprout-accent-color";
21+
export const NEUTRAL_ACCENT = "neutral";
2122

2223
export const ACCENT_COLORS = [
24+
{ name: "Neutral", value: NEUTRAL_ACCENT },
2325
{ name: "Blue", value: "#3b82f6" },
2426
{ name: "Cyan", value: "#06b6d4" },
2527
{ name: "Green", value: "#22c55e" },
@@ -75,8 +77,20 @@ function getContrastColor(hex: string): string {
7577
return lum > 0.5 ? "#000000" : "#ffffff";
7678
}
7779

78-
function applyAccentColor(hex: string) {
80+
function applyAccentColor(value: string) {
7981
const root = document.documentElement;
82+
if (value === NEUTRAL_ACCENT) {
83+
const styles = window.getComputedStyle(root);
84+
const foreground = styles.getPropertyValue("--foreground").trim();
85+
const background = styles.getPropertyValue("--background").trim();
86+
root.style.setProperty("--primary", foreground);
87+
root.style.setProperty("--primary-foreground", background);
88+
root.style.setProperty("--sidebar-primary", foreground);
89+
root.style.setProperty("--sidebar-primary-foreground", background);
90+
return;
91+
}
92+
93+
const hex = value;
8094
const accentHsl = hexToHsl(hex);
8195
const fgHsl = hexToHsl(getContrastColor(hex));
8296
root.style.setProperty("--primary", accentHsl);

0 commit comments

Comments
 (0)