Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(studio): add spot colour control to Appearance (#50782)

Danny White0cb8bd95dd68
diff --git a/apps/studio/components/interfaces/Account/Preferences/ThemeColorSettings.tsx b/apps/studio/components/interfaces/Account/Preferences/ThemeColorSettings.tsx
index c43cdefb926..5905353c086 100644
--- a/apps/studio/components/interfaces/Account/Preferences/ThemeColorSettings.tsx
+++ b/apps/studio/components/interfaces/Account/Preferences/ThemeColorSettings.tsx
@@ -1,58 +1,120 @@
+import { useFlag } from 'common'
import { useCallback, useEffect, useRef, useState } from 'react'
-import { Button, CardContent, Slider } from 'ui'
+import { Button, CardContent, cn, Slider } from 'ui'
+import { sliderTrackStyle } from './ThemeColorSettings.utils'
import { useThemeOverrides } from '@/hooks/misc/useThemeOverrides'
import {
+ APPEARANCE_SPOT_COLOR_FLAG,
applyThemeOverrides,
getThemeOverrideValue,
hasThemeOverrides,
previewThemeOverride,
+ resolveThemeOverridesForFlags,
sliderValueToThemeOverride,
THEME_OVERRIDE_KNOBS,
ThemeOverrideKey,
+ ThemeOverrideKnob,
ThemeOverrides,
themeOverrideToSliderValue,
} from '@/lib/theme-overrides'
+const PRIMARY_SWATCHES = [
+ { label: 'Solid', variable: '--primary-solid' },
+ { label: 'Primary', variable: '--primary' },
+ { label: 'Bright', variable: '--primary-bright' },
+] as const
+
+// `background` shorthand (not transparent + background-image) avoids a dark
+// hairline at rounded caps in dark mode.
+const SPECTRUM_SLIDER_CLASS = cn(
+ // eslint-disable-next-line shadcn/no-arbitrary-values -- Dynamic theme preview gradient uses the background shorthand for rounded caps.
+ '[&_[data-slot=slider-track]]:[background:var(--slider-track-fill)]',
+ '[&_[data-slot=slider-range]]:invisible'
+)
+
export const ThemeColorSettings = () => {
+ const isSpotColorEnabled = useFlag(APPEARANCE_SPOT_COLOR_FLAG)
const { mode, overrides, setOverride, resetOverrides } = useThemeOverrides()
+ const visibleOverrides = resolveThemeOverridesForFlags(overrides, { isSpotColorEnabled })
const [draft, setDraft] = useState<ThemeOverrides>({})
const draftRef = useRef<ThemeOverrides>({})
+ const interactionRafRef = useRef<number | null>(null)
+ const pendingPreviewRef = useRef<{ knob: ThemeOverrideKnob; raw: number } | null>(null)
+ const isSpotColorEnabledRef = useRef(isSpotColorEnabled)
const modeRef = useRef(mode)
- const overridesRef = useRef(overrides)
+ const overridesRef = useRef(visibleOverrides)
+ isSpotColorEnabledRef.current = isSpotColorEnabled
modeRef.current = mode
- overridesRef.current = overrides
+ overridesRef.current = visibleOverrides
+
+ const knobs = THEME_OVERRIDE_KNOBS.filter(
+ (knob) => knob.key !== 'primaryHue' || isSpotColorEnabled
+ )
+
+ const cancelQueuedInteraction = useCallback(() => {
+ if (interactionRafRef.current === null) return
+ cancelAnimationFrame(interactionRafRef.current)
+ interactionRafRef.current = null
+ }, [])
+
+ const flushDraft = useCallback(
+ (next: ThemeOverrides) => {
+ cancelQueuedInteraction()
+ draftRef.current = next
+ setDraft(next)
+ },
+ [cancelQueuedInteraction]
+ )
- const writeDraft = useCallback((next: ThemeOverrides) => {
- draftRef.current = next
- setDraft(next)
+ /** One React paint + one CSS preview per frame while dragging. */
+ const queueInteraction = useCallback((knob: ThemeOverrideKnob, raw: number) => {
+ draftRef.current = { ...draftRef.current, [knob.key]: raw }
+ pendingPreviewRef.current = { knob, raw }
+ if (interactionRafRef.current !== null) return
+
+ interactionRafRef.current = requestAnimationFrame(() => {
+ interactionRafRef.current = null
+ setDraft(draftRef.current)
+ const pending = pendingPreviewRef.current
+ if (pending === null) return
+ if (pending.knob.key === 'primaryHue' && !isSpotColorEnabledRef.current) return
+ previewThemeOverride(pending.knob, modeRef.current, pending.raw)
+ })
}, [])
- useEffect(() => writeDraft({}), [mode, writeDraft])
+ useEffect(() => {
+ flushDraft({})
+ applyThemeOverrides(document.documentElement, modeRef.current, overridesRef.current)
+ }, [mode, isSpotColorEnabled, flushDraft])
useEffect(
() => () => {
+ cancelQueuedInteraction()
applyThemeOverrides(document.documentElement, modeRef.current, overridesRef.current)
},
- []
+ [cancelQueuedInteraction]
)
const handleReset = useCallback(() => {
- writeDraft({})
+ flushDraft({})
resetOverrides()
- }, [resetOverrides, writeDraft])
+ }, [flushDraft, resetOverrides])
const commitDraft = useCallback(
(key: ThemeOverrideKey, committed?: number) => {
const pending = draftRef.current[key] ?? committed
if (pending === undefined) return
+ const knob = THEME_OVERRIDE_KNOBS.find((candidate) => candidate.key === key)
+ if (knob !== undefined) previewThemeOverride(knob, modeRef.current, pending)
+
setOverride(key, pending)
const { [key]: _flushed, ...rest } = draftRef.current
- writeDraft(rest)
+ flushDraft(rest)
},
- [setOverride, writeDraft]
+ [flushDraft, setOverride]
)
return (
@@ -62,7 +124,7 @@ export const ThemeColorSettings = () => {
<p className="text-sm text-foreground-lighter">
Changes are saved separately for light and dark mode.
</p>
- {hasThemeOverrides(overrides) && (
+ {hasThemeOverrides(visibleOverrides) && (
<Button variant="default" size="tiny" className="self-start" onClick={handleReset}>
Reset
</Button>
@@ -70,13 +132,21 @@ export const ThemeColorSettings = () => {
</div>
<div className="col-span-full md:col-span-8 flex flex-col gap-6 pb-2">
- {THEME_OVERRIDE_KNOBS.map((knob) => {
- const rawValue = draft[knob.key] ?? getThemeOverrideValue(knob, mode, overrides)
+ {knobs.map((knob) => {
+ const isSpotHue = knob.key === 'primaryHue'
+ const rawValue = draft[knob.key] ?? getThemeOverrideValue(knob, mode, visibleOverrides)
const sliderValue = themeOverrideToSliderValue(knob, mode, rawValue)
+ const roundedHue = Math.round(rawValue)
+ const trackStyle = sliderTrackStyle(knob.key, mode)
return (
<div key={knob.key} className="flex flex-col gap-2">
- <div className="grid grid-cols-[minmax(0,1fr)_2rem] items-start gap-4">
+ <div
+ className={cn(
+ 'grid items-start gap-4',
+ isSpotHue ? 'grid-cols-[minmax(0,1fr)_auto]' : 'grid-cols-[minmax(0,1fr)_2rem]'
+ )}
+ >
<div className="min-w-0 flex flex-col gap-1">
<span
id={`theme-color-${knob.key}-label`}
@@ -86,22 +156,39 @@ export const ThemeColorSettings = () => {
</span>
<span className="text-sm text-foreground-light">{knob.description}</span>
</div>
- <span className="text-right text-sm text-foreground-light tabular-nums">
- {sliderValue}
- </span>
+ {isSpotHue ? (
+ <span className="flex items-center justify-end gap-2 text-sm text-foreground-light">
+ <span className="flex items-center gap-1" aria-hidden>
+ {PRIMARY_SWATCHES.map((swatch) => (
+ <span
+ key={swatch.variable}
+ title={swatch.label}
+ className="size-2.5 rounded-full border border-foreground/15"
+ style={{ background: `var(${swatch.variable})` }}
+ />
+ ))}
+ </span>
+ <span className="tabular-nums">{roundedHue}°</span>
+ </span>
+ ) : (
+ <span className="text-right text-sm text-foreground-light tabular-nums">
+ {sliderValue}
+ </span>
+ )}
</div>
<Slider
- className="[&_[data-slot=slider-track]]:bg-input"
+ className={
+ trackStyle ? SPECTRUM_SLIDER_CLASS : '[&_[data-slot=slider-track]]:bg-input'
+ }
+ style={trackStyle}
aria-labelledby={`theme-color-${knob.key}-label`}
- aria-valuetext={`${sliderValue} out of 100`}
+ aria-valuetext={isSpotHue ? `${roundedHue} degrees` : `${sliderValue} out of 100`}
min={0}
max={100}
step={1}
value={[sliderValue]}
onValueChange={([next]) => {
- const raw = sliderValueToThemeOverride(knob, mode, next)
- writeDraft({ ...draftRef.current, [knob.key]: raw })
- previewThemeOverride(knob, mode, raw)
+ queueInteraction(knob, sliderValueToThemeOverride(knob, mode, next))
}}
onValueCommit={([next]) =>
commitDraft(knob.key, sliderValueToThemeOverride(knob, mode, next))
diff --git a/apps/studio/components/interfaces/Account/Preferences/ThemeColorSettings.utils.ts b/apps/studio/components/interfaces/Account/Preferences/ThemeColorSettings.utils.ts
new file mode 100644
index 00000000000..0cf96f49f75
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/Preferences/ThemeColorSettings.utils.ts
@@ -0,0 +1,50 @@
+import type { CSSProperties } from 'react'
+
+import type { ThemeOverrideKey, ThemeOverrideMode } from '@/lib/theme-overrides'
+
+/** Full-hue OKLCH spectrum for the spot color track. */
+const HUE_SPECTRUM_TRACK =
+ 'linear-gradient(to right, oklch(0.7 0.14 0), oklch(0.7 0.14 60), oklch(0.7 0.14 120), oklch(0.7 0.14 180), oklch(0.7 0.14 240), oklch(0.7 0.14 300), oklch(0.7 0.14 360))'
+
+type SliderTrackStyle = CSSProperties & {
+ '--slider-track-fill': string
+}
+
+export function sliderTrackStyle(
+ key: ThemeOverrideKey,
+ mode: ThemeOverrideMode
+): SliderTrackStyle | undefined {
+ switch (key) {
+ case 'primaryHue':
+ return { '--slider-track-fill': HUE_SPECTRUM_TRACK }
+ case 'chroma':
+ // Grey → tinted at the live surface hue (follows spot via CSS offset).
+ return {
+ '--slider-track-fill':
+ mode === 'dark'
+ ? 'linear-gradient(to right, oklch(0.4 0 var(--surface-hue)), oklch(0.4 0.07 var(--surface-hue)))'
+ : 'linear-gradient(to right, oklch(0.9 0 var(--surface-hue)), oklch(0.9 0.05 var(--surface-hue)))',
+ }
+ case 'contrast':
+ return {
+ '--slider-track-fill':
+ mode === 'dark'
+ ? 'linear-gradient(to right, oklch(0.35 0 0), oklch(0.9 0 0))'
+ : 'linear-gradient(to right, oklch(0.82 0 0), oklch(0.2 0 0))',
+ }
+ case 'surface':
+ // Chroma 0 at the ends avoids out-of-gamut flashes at the caps.
+ return {
+ '--slider-track-fill':
+ 'linear-gradient(to right, oklch(0.14 0 0), oklch(0.5 0.015 var(--surface-hue)), oklch(0.97 0 0))',
+ }
+ case 'elevationStep':
+ // Flat → stronger lift between layers (smooth ramp, not hard bands).
+ return {
+ '--slider-track-fill':
+ mode === 'dark'
+ ? 'linear-gradient(to right, oklch(0.28 0 var(--surface-hue)), oklch(0.55 0 var(--surface-hue)))'
+ : 'linear-gradient(to right, oklch(0.92 0 var(--surface-hue)), oklch(0.99 0 var(--surface-hue)))',
+ }
+ }
+}
diff --git a/apps/studio/components/interfaces/App/AppearanceSettingsProvider.tsx b/apps/studio/components/interfaces/App/AppearanceSettingsProvider.tsx
index 29bf52eaad2..99e9ac4bca1 100644
--- a/apps/studio/components/interfaces/App/AppearanceSettingsProvider.tsx
+++ b/apps/studio/components/interfaces/App/AppearanceSettingsProvider.tsx
@@ -1,17 +1,23 @@
-import { useIsomorphicLayoutEffect } from 'common'
+import { useFlag, useIsomorphicLayoutEffect } from 'common'
import { useTheme } from 'next-themes'
import { useThemeOverrides } from '@/hooks/misc/useThemeOverrides'
-import { applyThemeOverrides } from '@/lib/theme-overrides'
+import {
+ APPEARANCE_SPOT_COLOR_FLAG,
+ applyThemeOverrides,
+ resolveThemeOverridesForFlags,
+} from '@/lib/theme-overrides'
export const AppearanceSettingsProvider = () => {
const { resolvedTheme } = useTheme()
const { mode, overrides } = useThemeOverrides()
+ const isSpotColorEnabled = useFlag(APPEARANCE_SPOT_COLOR_FLAG)
+ const effectiveOverrides = resolveThemeOverridesForFlags(overrides, { isSpotColorEnabled })
useIsomorphicLayoutEffect(() => {
if (resolvedTheme === undefined) return
- applyThemeOverrides(document.documentElement, mode, overrides)
- }, [mode, overrides, resolvedTheme])
+ applyThemeOverrides(document.documentElement, mode, effectiveOverrides)
+ }, [mode, effectiveOverrides, resolvedTheme])
return null
}
diff --git a/apps/studio/lib/__tests__/theme-overrides.test.ts b/apps/studio/lib/__tests__/theme-overrides.test.ts
index 601ac2967f5..63823bf4af9 100644
--- a/apps/studio/lib/__tests__/theme-overrides.test.ts
+++ b/apps/studio/lib/__tests__/theme-overrides.test.ts
@@ -9,6 +9,7 @@ import {
mergeThemeOverride,
parseThemeOverridesByMode,
resolveThemeOverrideMode,
+ resolveThemeOverridesForFlags,
sliderValueToThemeOverride,
THEME_OVERRIDE_DEFAULTS,
THEME_OVERRIDE_KNOBS,
@@ -141,11 +142,32 @@ describe('theme override application', () => {
expect(root.style.getPropertyValue('--contrast')).toBe('')
})
+ it('applies a spot hue via --primary-hue and leaves brand and surface hues alone', () => {
+ const root = document.createElement('html')
+ applyThemeOverrides(root, 'dark', { primaryHue: 48 })
+
+ expect(root.style.getPropertyValue('--primary-hue')).toBe('48')
+ expect(root.style.getPropertyValue('--surface-hue')).toBe('')
+ expect(root.style.getPropertyValue('--brand-default')).toBe('')
+
+ applyThemeOverrides(root, 'dark', {})
+ expect(root.style.getPropertyValue('--primary-hue')).toBe('')
+ })
+
it('reports whether a mode has overrides', () => {
expect(hasThemeOverrides({})).toBe(false)
expect(hasThemeOverrides({ chroma: 0.02 })).toBe(true)
})
+ it('strips spot hue when the employee-only flag is off', () => {
+ expect(
+ resolveThemeOverridesForFlags({ primaryHue: 48, chroma: 0.02 }, { isSpotColorEnabled: false })
+ ).toEqual({ chroma: 0.02 })
+ expect(
+ resolveThemeOverridesForFlags({ primaryHue: 48, chroma: 0.02 }, { isSpotColorEnabled: true })
+ ).toEqual({ primaryHue: 48, chroma: 0.02 })
+ })
+
it('resolves classic dark as dark for legacy stored themes', () => {
expect(resolveThemeOverrideMode('dark')).toBe('dark')
expect(resolveThemeOverrideMode('light')).toBe('light')
diff --git a/apps/studio/lib/theme-overrides.ts b/apps/studio/lib/theme-overrides.ts
index d363f6fb072..dee967a9f84 100644
--- a/apps/studio/lib/theme-overrides.ts
+++ b/apps/studio/lib/theme-overrides.ts
@@ -1,8 +1,11 @@
import * as z from 'zod'
-export type ThemeOverrideKey = 'chroma' | 'contrast' | 'surface' | 'elevationStep'
+export type ThemeOverrideKey = 'primaryHue' | 'chroma' | 'contrast' | 'surface' | 'elevationStep'
export type ThemeOverrideMode = 'dark' | 'light'
+/** ConfigCat flag: Spot color control (employee-only via Supabase Team Email segment). */
+export const APPEARANCE_SPOT_COLOR_FLAG = 'appearanceSpotColor'
+
type ThemeOverrideRange = { min: number; max: number }
export interface ThemeOverrideKnob {
@@ -14,11 +17,18 @@ export interface ThemeOverrideKnob {
}
export const THEME_OVERRIDE_KNOBS: readonly ThemeOverrideKnob[] = [
+ {
+ key: 'primaryHue',
+ cssVar: '--primary-hue',
+ label: 'Spot color',
+ description: 'Changes the hue of primary controls and the canvas.',
+ ranges: { dark: { min: 0, max: 360 }, light: { min: 0, max: 360 } },
+ },
{
key: 'chroma',
cssVar: '--chroma',
- label: 'Color intensity',
- description: 'Controls how vivid interface colors appear.',
+ label: 'Surface tint',
+ description: 'Controls how much color tints backgrounds, text, and borders.',
ranges: { dark: { min: 0, max: 0.04 }, light: { min: 0, max: 0.03 } },
},
{
@@ -48,8 +58,8 @@ export const THEME_OVERRIDE_DEFAULTS: Record<
ThemeOverrideMode,
Record<ThemeOverrideKey, number>
> = {
- dark: { chroma: 0.005, contrast: 0.5, surface: 0.19, elevationStep: 0.025 },
- light: { chroma: 0, contrast: 0.53, surface: 0.995, elevationStep: 0.024 },
+ dark: { primaryHue: 157.5, chroma: 0.005, contrast: 0.5, surface: 0.19, elevationStep: 0.025 },
+ light: { primaryHue: 157.5, chroma: 0, contrast: 0.53, surface: 0.995, elevationStep: 0.024 },
}
export type ThemeOverrides = Partial<Record<ThemeOverrideKey, number>>
@@ -57,6 +67,7 @@ export type ThemeOverridesByMode = Partial<Record<ThemeOverrideMode, ThemeOverri
const themeOverridesSchema = z
.object({
+ primaryHue: z.number().finite().optional(),
chroma: z.number().finite().optional(),
contrast: z.number().finite().optional(),
surface: z.number().finite().optional(),
@@ -156,6 +167,16 @@ export function hasThemeOverrides(overrides: ThemeOverrides): boolean {
return THEME_OVERRIDE_KNOBS.some((knob) => overrides[knob.key] !== undefined)
}
+/** Drops the Spot color override when the employee-only flag is off. */
+export function resolveThemeOverridesForFlags(
+ overrides: ThemeOverrides,
+ { isSpotColorEnabled }: { isSpotColorEnabled: boolean }
+): ThemeOverrides {
+ if (isSpotColorEnabled || overrides.primaryHue === undefined) return overrides
+ const { primaryHue: _removed, ...rest } = overrides
+ return rest
+}
+
function sanitizeThemeOverrides(
mode: ThemeOverrideMode,
overrides: ThemeOverrides
diff --git a/apps/studio/tests/components/interfaces/Account/Preferences/ThemeColorSettings.test.tsx b/apps/studio/tests/components/interfaces/Account/Preferences/ThemeColorSettings.test.tsx
index d0bc1d73299..ab3c04ee6a7 100644
--- a/apps/studio/tests/components/interfaces/Account/Preferences/ThemeColorSettings.test.tsx
+++ b/apps/studio/tests/components/interfaces/Account/Preferences/ThemeColorSettings.test.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, screen } from '@testing-library/react'
+import { fireEvent, screen, waitFor } from '@testing-library/react'
import type { ComponentProps } from 'react'
import type * as UI from 'ui'
import { beforeEach, describe, expect, it, vi } from 'vitest'
@@ -8,11 +8,20 @@ import { customRender } from '@/tests/lib/custom-render'
type SliderProps = ComponentProps<typeof UI.Slider>
-const { resetOverrides, setOverride } = vi.hoisted(() => ({
+const { resetOverrides, setOverride, mockUseFlag } = vi.hoisted(() => ({
resetOverrides: vi.fn(),
setOverride: vi.fn(),
+ mockUseFlag: vi.fn(() => true),
}))
+vi.mock('common', async (importOriginal) => {
+ const actual = await importOriginal<typeof import('common')>()
+ return {
+ ...actual,
+ useFlag: mockUseFlag,
+ }
+})
+
vi.mock('@/hooks/misc/useThemeOverrides', () => ({
useThemeOverrides: () => ({
mode: 'dark',
@@ -23,7 +32,7 @@ vi.mock('@/hooks/misc/useThemeOverrides', () => ({
}))
vi.mock('ui', async (importOriginal) => {
- const actual = await importOriginal<typeof import('ui')>()
+ const actual = await importOriginal<typeof UI>()
return {
...actual,
@@ -45,14 +54,17 @@ describe('ThemeColorSettings', () => {
beforeEach(() => {
resetOverrides.mockReset()
setOverride.mockReset()
+ mockUseFlag.mockReset()
+ mockUseFlag.mockReturnValue(true)
document.documentElement.style.removeProperty('--chroma')
+ document.documentElement.style.removeProperty('--primary-hue')
document.documentElement.dataset.theme = 'dark'
})
it('persists a rapid pointer change for the active mode', () => {
customRender(<ThemeColorSettings />)
- const slider = screen.getByRole('slider', { name: 'Color intensity' })
+ const slider = screen.getByRole('slider', { name: 'Surface tint' })
fireEvent.click(slider)
fireEvent.lostPointerCapture(slider)
@@ -62,13 +74,50 @@ describe('ThemeColorSettings', () => {
it('persists an ordinary committed change', () => {
customRender(<ThemeColorSettings />)
- const slider = screen.getByRole('slider', { name: 'Color intensity' })
+ const slider = screen.getByRole('slider', { name: 'Surface tint' })
fireEvent.click(slider)
fireEvent.keyUp(slider)
expect(setOverride).toHaveBeenCalledWith('chroma', 0.04)
})
+ it('previews and saves the spot color hue when the flag is on', async () => {
+ customRender(<ThemeColorSettings />)
+
+ expect(screen.getByText('158°')).toBeInTheDocument()
+
+ const slider = screen.getByRole('slider', { name: 'Spot color' })
+ fireEvent.click(slider)
+
+ await waitFor(() => {
+ expect(document.documentElement.style.getPropertyValue('--primary-hue')).toBe('360')
+ })
+ expect(await screen.findByText('360°')).toBeInTheDocument()
+
+ fireEvent.keyUp(slider)
+ expect(setOverride).toHaveBeenCalledWith('primaryHue', 360)
+ })
+
+ it('hides the spot color control when the employee-only flag is off', () => {
+ mockUseFlag.mockReturnValue(false)
+ customRender(<ThemeColorSettings />)
+
+ expect(screen.queryByRole('slider', { name: 'Spot color' })).not.toBeInTheDocument()
+ expect(screen.getByRole('slider', { name: 'Surface tint' })).toBeInTheDocument()
+ })
+
+ it('cancels a queued hue preview when the flag turns off', async () => {
+ const { rerender } = customRender(<ThemeColorSettings />)
+ fireEvent.click(screen.getByRole('slider', { name: 'Spot color' }))
+
+ mockUseFlag.mockReturnValue(false)
+ rerender(<ThemeColorSettings />)
+
+ await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))
+ expect(document.documentElement.style.getPropertyValue('--primary-hue')).toBe('')
+ expect(screen.queryByRole('slider', { name: 'Spot color' })).not.toBeInTheDocument()
+ })
+
it('resets the active mode', () => {
customRender(<ThemeColorSettings />)
@@ -77,11 +126,13 @@ describe('ThemeColorSettings', () => {
expect(resetOverrides).toHaveBeenCalledOnce()
})
- it('restores persisted values when an active preview unmounts', () => {
+ it('restores persisted values when an active preview unmounts', async () => {
const { unmount } = customRender(<ThemeColorSettings />)
- fireEvent.click(screen.getByRole('slider', { name: 'Color intensity' }))
- expect(document.documentElement.style.getPropertyValue('--chroma')).toBe('0.04')
+ fireEvent.click(screen.getByRole('slider', { name: 'Surface tint' }))
+ await waitFor(() => {
+ expect(document.documentElement.style.getPropertyValue('--chroma')).toBe('0.04')
+ })
unmount()
diff --git a/apps/studio/tests/components/interfaces/Account/Preferences/ThemeColorSettings.utils.test.ts b/apps/studio/tests/components/interfaces/Account/Preferences/ThemeColorSettings.utils.test.ts
new file mode 100644
index 00000000000..84a6b766cd8
--- /dev/null
+++ b/apps/studio/tests/components/interfaces/Account/Preferences/ThemeColorSettings.utils.test.ts
@@ -0,0 +1,51 @@
+import { describe, expect, it } from 'vitest'
+
+import { sliderTrackStyle } from '@/components/interfaces/Account/Preferences/ThemeColorSettings.utils'
+import type { ThemeOverrideKey, ThemeOverrideMode } from '@/lib/theme-overrides'
+
+describe('sliderTrackStyle', () => {
+ const cases: Array<{
+ key: ThemeOverrideKey
+ mode: ThemeOverrideMode
+ start: string
+ end: string
+ }> = [
+ { key: 'primaryHue', mode: 'dark', start: '0.7 0.14 0', end: '0.7 0.14 360' },
+ { key: 'primaryHue', mode: 'light', start: '0.7 0.14 0', end: '0.7 0.14 360' },
+ {
+ key: 'chroma',
+ mode: 'dark',
+ start: '0.4 0 var(--surface-hue)',
+ end: '0.4 0.07 var(--surface-hue)',
+ },
+ {
+ key: 'chroma',
+ mode: 'light',
+ start: '0.9 0 var(--surface-hue)',
+ end: '0.9 0.05 var(--surface-hue)',
+ },
+ { key: 'contrast', mode: 'dark', start: '0.35 0 0', end: '0.9 0 0' },
+ { key: 'contrast', mode: 'light', start: '0.82 0 0', end: '0.2 0 0' },
+ { key: 'surface', mode: 'dark', start: '0.14 0 0', end: '0.97 0 0' },
+ { key: 'surface', mode: 'light', start: '0.14 0 0', end: '0.97 0 0' },
+ {
+ key: 'elevationStep',
+ mode: 'dark',
+ start: '0.28 0 var(--surface-hue)',
+ end: '0.55 0 var(--surface-hue)',
+ },
+ {
+ key: 'elevationStep',
+ mode: 'light',
+ start: '0.92 0 var(--surface-hue)',
+ end: '0.99 0 var(--surface-hue)',
+ },
+ ]
+
+ it.each(cases)('illustrates the $key range in $mode mode', ({ key, mode, start, end }) => {
+ const gradient = sliderTrackStyle(key, mode)?.['--slider-track-fill']
+ expect(gradient).toMatch(/^linear-gradient\(to right, /)
+ expect(gradient).toContain(`oklch(${start})`)
+ expect(gradient).toContain(`oklch(${end})`)
+ })
+})
diff --git a/packages/ui/build/css/source/semantic.css b/packages/ui/build/css/source/semantic.css
index 4a51e400faa..fb9de6df356 100644
--- a/packages/ui/build/css/source/semantic.css
+++ b/packages/ui/build/css/source/semantic.css
@@ -9,17 +9,17 @@
:root {
/*
- * Hue inputs. A single --hue used to drive both the neutral surface/text ramp
- * and the brand, so the two could never drift apart. They are now split so a
- * theme can run, say, a cool-gray surface against the green brand:
- * --surface-hue tints backgrounds, text and borders (the neutral ramp)
- * --primary-hue is the spot hue that functional primary colors use
- * Both default to --hue (Supabase green ≈157.5° in OKLCH), so a theme that only
- * sets --hue keeps surfaces and brand locked together as before; override
- * either one to let them diverge. */
+ * Hue inputs. --primary-hue is the spot colour; --surface-hue tints the
+ * neutral ramp (backgrounds, text, borders). Surface is derived from primary
+ * plus a theme offset so canvases stay coupled when spot changes:
+ * dark offset 0 → same hue as spot (subtle brand tint)
+ * light offset 180 → complementary canvas tint (brand green → rose)
+ * Themes can still set --surface-hue directly to break the link.
+ */
--hue: 157.5;
- --surface-hue: var(--hue);
--primary-hue: var(--hue);
+ --surface-hue-offset: 0;
+ --surface-hue: calc(var(--primary-hue) + var(--surface-hue-offset));
/* Root defaults mirror the dark theme (the app's default appearance). */
--chroma: 0.016;
--surface: 0.17;
diff --git a/packages/ui/build/css/themes/light.css b/packages/ui/build/css/themes/light.css
index 492040b6607..b87596d70bf 100644
--- a/packages/ui/build/css/themes/light.css
+++ b/packages/ui/build/css/themes/light.css
@@ -2,7 +2,8 @@
.light {
--helpers-os-appearance: Light;
--hue: 157.5;
- --surface-hue: 34;
+ /* Complementary canvas tint relative to --primary-hue (157.5° → ≈337.5°). */
+ --surface-hue-offset: 180;
--chroma: 0;
/*
* Soft-gray canvas (not pure white) so elevated surfaces have headroom to