-
-
Notifications
You must be signed in to change notification settings - Fork 470
feat(web): add color theme presets #964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NightWatcher314
wants to merge
4
commits into
tiann:main
Choose a base branch
from
NightWatcher314:feature/color-theme-presets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1217325
feat(web): add color theme presets
NightWatcher314 07c7e91
fix(web): preserve presets with custom colors
NightWatcher314 d34ec68
fix(web): sync color theme across tabs
NightWatcher314 9de345d
fix(web): clear boot theme background
NightWatcher314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { act, renderHook } from '@testing-library/react' | ||
| import { beforeEach, describe, expect, it } from 'vitest' | ||
| import { | ||
| applyColorTheme, | ||
| getColorThemeStorageKey, | ||
| getStoredColorTheme, | ||
| parseColorTheme, | ||
| useColorTheme, | ||
| } from './useColorTheme' | ||
|
|
||
| const THEME_VARS = ['--app-bg', '--app-fg', '--app-link', '--app-button', '--app-secondary-bg'] | ||
|
|
||
| describe('useColorTheme', () => { | ||
| beforeEach(() => { | ||
| localStorage.clear() | ||
| document.documentElement.removeAttribute('data-color-theme') | ||
| document.documentElement.setAttribute('data-theme', 'light') | ||
| for (const name of THEME_VARS) document.documentElement.style.removeProperty(name) | ||
| }) | ||
|
|
||
| it('parses invalid or missing stored values as default', () => { | ||
| expect(parseColorTheme(null)).toBe('default') | ||
| expect(parseColorTheme('unknown')).toBe('default') | ||
| expect(parseColorTheme('notion')).toBe('notion') | ||
| }) | ||
|
|
||
| it('reads the stored color theme preference', () => { | ||
| localStorage.setItem(getColorThemeStorageKey(), 'rose-pine') | ||
| expect(getStoredColorTheme()).toBe('rose-pine') | ||
| }) | ||
|
|
||
| it('applies a preset palette to the document css variables', () => { | ||
| applyColorTheme('one', 'light') | ||
| expect(document.documentElement).toHaveAttribute('data-color-theme', 'one') | ||
| expect(document.documentElement.style.getPropertyValue('--app-bg')).toBe('#fbfbff') | ||
| expect(document.documentElement.style.getPropertyValue('--app-link')).toBe('#526fff') | ||
| }) | ||
|
|
||
| it('removes palette css variables when reset to default', () => { | ||
| applyColorTheme('one', 'dark') | ||
| applyColorTheme('default', 'dark') | ||
|
|
||
| expect(document.documentElement).toHaveAttribute('data-color-theme', 'default') | ||
| expect(document.documentElement.style.getPropertyValue('--app-bg')).toBe('') | ||
| expect(document.documentElement.style.getPropertyValue('--app-link')).toBe('') | ||
| }) | ||
|
|
||
| it('persists non-default selections and removes the key for default', () => { | ||
| const { result } = renderHook(() => useColorTheme()) | ||
|
|
||
| act(() => result.current.setColorTheme('night-owl')) | ||
| expect(localStorage.getItem(getColorThemeStorageKey())).toBe('night-owl') | ||
| expect(document.documentElement.style.getPropertyValue('--app-bg')).toBe('#fbfdff') | ||
|
|
||
| act(() => result.current.setColorTheme('default')) | ||
| expect(localStorage.getItem(getColorThemeStorageKey())).toBeNull() | ||
| expect(document.documentElement.style.getPropertyValue('--app-bg')).toBe('') | ||
| }) | ||
|
|
||
| it('uses the current dark scheme when applying from the hook', () => { | ||
| document.documentElement.setAttribute('data-theme', 'dark') | ||
| const { result } = renderHook(() => useColorTheme()) | ||
|
|
||
| act(() => result.current.setColorTheme('notion')) | ||
| expect(document.documentElement.style.getPropertyValue('--app-bg')).toBe('#191919') | ||
| expect(document.documentElement.style.getPropertyValue('--app-fg')).toBe('#d9d9d8') | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MINOR] This inline
backgroundColoris set during boot, but the runtime theme path never clears or updatesdocument.documentElement.style.backgroundColor;applyTheme()only updatesdata-theme, preset CSS variables, and the meta tag. Since inline style outranks the laterhtml[data-theme]rules, the document canvas can retain the launch appearance/preset color after a user changes appearance or color theme.Suggested fix: