mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## What kind of change does this PR introduce? Feature. ## What is the current behaviour? Studio Appearance preferences only select a theme mode. The underlying theme colours cannot be adjusted, and the existing proof of concept allowed unsafe combinations and introduced a bespoke Slider variant. ## What is the new behaviour? - Preserves the existing System, Dark, Light, and Classic Dark theme options. Classic Dark remains a fixed preset. - Adds four theme colour controls using the existing Supabase Slider unchanged. Each control presents a consistent 0 to 100 scale mapped to bounded light and dark ranges. - Previews colour changes while dragging and persists them once the interaction finishes, including rapid pointer gestures. - Stores light and dark overrides separately, validates stored values, clamps legacy values, and removes overrides that return to their shipped defaults. - Adds concise descriptions for Chroma, Contrast, Surface, and Elevation step, with a scoped Reset action shown only when the active theme differs from its defaults. - Keeps Slider in a stable shared chunk so production builds do not create a circular dependency between generated UI chunks. | Before | After | | --- | --- | | <img width="1448" height="1284" alt="CleanShot 2026-09-15 at 14 33 53@2x" src="https://github.com/user-attachments/assets/d55151c7-b2a9-40c6-9468-e77ae685ac38" /> | <img width="1454" height="1958" alt="CleanShot 2026-09-15 at 17 48 47@2x" src="https://github.com/user-attachments/assets/9d302e67-76cc-4341-948c-81713dea2e93" /> | ## To test 1. Open `/account/me` and scroll to Appearance. 2. Switch between System, Dark, Light, and Classic Dark. Confirm the same four modes remain available in the account theme menu. 3. Confirm Classic Dark retains its existing appearance and does not show theme colour controls. 4. In System, Dark, or Light, move each Theme colors slider to both ends. Confirm the dashboard previews the change, remains readable, and the theme cards do not shift or remount. 5. Reload the page and confirm colour changes persist separately for Light and Dark. 6. Return all sliders to their defaults, or select Reset, and confirm the Reset action disappears. 7. In System mode, change the operating system theme and confirm each resolved mode restores its own colour settings. --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { LOCAL_STORAGE_KEYS, safeLocalStorage } from 'common'
|
|
import { useTheme } from 'next-themes'
|
|
import { useCallback, useMemo } from 'react'
|
|
|
|
import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage'
|
|
import {
|
|
clearThemeOverridesForMode,
|
|
mergeThemeOverride,
|
|
parseThemeOverridesByMode,
|
|
resolveThemeOverrideMode,
|
|
ThemeOverrideKey,
|
|
ThemeOverrideMode,
|
|
ThemeOverrides,
|
|
ThemeOverridesByMode,
|
|
} from '@/lib/theme-overrides'
|
|
|
|
const EMPTY_OVERRIDES: ThemeOverrides = {}
|
|
|
|
function readStoredThemeOverrides(): ThemeOverridesByMode {
|
|
const stored = safeLocalStorage.getItem(LOCAL_STORAGE_KEYS.UI_THEME_OVERRIDES)
|
|
if (stored === null) return {}
|
|
|
|
try {
|
|
return parseThemeOverridesByMode(JSON.parse(stored))
|
|
} catch {
|
|
return {}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reads and writes the colour-system overrides for the currently resolved
|
|
* theme mode. Stored alongside the other appearance preferences in
|
|
* localStorage under a single key, keyed by mode.
|
|
*/
|
|
export function useThemeOverrides() {
|
|
const { resolvedTheme } = useTheme()
|
|
const mode: ThemeOverrideMode = resolveThemeOverrideMode(resolvedTheme)
|
|
|
|
const [storedOverrides, setStoredOverrides] = useLocalStorageQuery<unknown>(
|
|
LOCAL_STORAGE_KEYS.UI_THEME_OVERRIDES,
|
|
readStoredThemeOverrides()
|
|
)
|
|
const overridesByMode = useMemo(
|
|
() => parseThemeOverridesByMode(storedOverrides),
|
|
[storedOverrides]
|
|
)
|
|
|
|
const overrides = overridesByMode[mode] ?? EMPTY_OVERRIDES
|
|
|
|
const setOverride = useCallback(
|
|
(key: ThemeOverrideKey, value: number) => {
|
|
setStoredOverrides((current: unknown) =>
|
|
mergeThemeOverride(parseThemeOverridesByMode(current), mode, key, value)
|
|
)
|
|
},
|
|
[mode, setStoredOverrides]
|
|
)
|
|
|
|
const resetOverrides = useCallback(() => {
|
|
setStoredOverrides((current: unknown) =>
|
|
clearThemeOverridesForMode(parseThemeOverridesByMode(current), mode)
|
|
)
|
|
}, [mode, setStoredOverrides])
|
|
|
|
return useMemo(
|
|
() => ({ mode, overrides, setOverride, resetOverrides }),
|
|
[mode, overrides, setOverride, resetOverrides]
|
|
)
|
|
}
|