-
Notifications
You must be signed in to change notification settings - Fork 31
Special Error: Stub out support for theming #2076
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
972bcbe
Add theme and variant support to SpecialError page
noisysocks 35937ba
Refactor: Update comment for theme variant background colors
cursoragent bd6ac87
Apply suggestion from @noisysocks
noisysocks c6fcae8
Fix ?display=components not picking up theming
noisysocks 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
58 changes: 58 additions & 0 deletions
58
special-pages/pages/special-error/app/providers/ThemeProvider.js
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,58 @@ | ||
| import { createContext, h } from 'preact'; | ||
| import { useContext, useEffect, useState } from 'preact/hooks'; | ||
| import { useMessaging } from './MessagingProvider.js'; | ||
| import { useEnv } from '../../../../shared/components/EnvironmentProvider.js'; | ||
|
|
||
| /** | ||
| * @typedef {import('../../types/special-error').BrowserTheme} BrowserTheme | ||
| * @typedef {import('../../types/special-error').ThemeVariant} ThemeVariant | ||
| */ | ||
|
|
||
| const ThemeContext = createContext({ | ||
| /** @type {BrowserTheme} */ | ||
| theme: 'light', | ||
| /** @type {ThemeVariant} */ | ||
| themeVariant: 'default', | ||
| }); | ||
|
|
||
| /** | ||
| * @param {object} props | ||
| * @param {import('preact').ComponentChild} props.children | ||
| * @param {BrowserTheme | undefined} props.initialTheme | ||
| * @param {ThemeVariant | undefined} props.initialThemeVariant | ||
| */ | ||
| export function ThemeProvider({ children, initialTheme, initialThemeVariant }) { | ||
| const { isDarkMode } = useEnv(); | ||
| const { messaging } = useMessaging(); | ||
|
|
||
| // Track explicit theme updates from onThemeUpdate subscription | ||
| const [explicitTheme, setExplicitTheme] = useState(/** @type {BrowserTheme | undefined} */ (undefined)); | ||
| const [explicitThemeVariant, setExplicitThemeVariant] = useState(/** @type {ThemeVariant | undefined} */ (undefined)); | ||
|
|
||
| useEffect(() => { | ||
| if (!messaging) return; | ||
| const unsubscribe = messaging.onThemeUpdate((data) => { | ||
| setExplicitTheme(data.theme); | ||
| setExplicitThemeVariant(data.themeVariant); | ||
| }); | ||
| return unsubscribe; | ||
| }, [messaging]); | ||
|
|
||
| // Derive theme from explicit updates, initial theme, or system preference (in that order) | ||
| const theme = explicitTheme ?? initialTheme ?? (isDarkMode ? 'dark' : 'light'); | ||
| const themeVariant = explicitThemeVariant ?? initialThemeVariant ?? 'default'; | ||
|
|
||
| // Sync theme attributes to <body> | ||
| useEffect(() => { | ||
| document.body.dataset.theme = theme; | ||
| }, [theme]); | ||
| useEffect(() => { | ||
| document.body.dataset.themeVariant = themeVariant; | ||
| }, [themeVariant]); | ||
|
|
||
| return <ThemeContext.Provider value={{ theme, themeVariant }}>{children}</ThemeContext.Provider>; | ||
| } | ||
|
|
||
| export function useTheme() { | ||
| return useContext(ThemeContext); | ||
| } |
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
54 changes: 54 additions & 0 deletions
54
special-pages/pages/special-error/integration-tests/special-error-theme.spec.js
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,54 @@ | ||
| import { test } from '@playwright/test'; | ||
| import { SpecialErrorPage } from './special-error.js'; | ||
|
|
||
| test.describe('special-error theme and theme variants', () => { | ||
| test('setting theme = dark and themeVariant via initialSetup', async ({ page }, workerInfo) => { | ||
| const sp = SpecialErrorPage.create(page, workerInfo); | ||
| await sp.openPage({ additional: { theme: 'dark', themeVariant: 'violet' } }); | ||
| await sp.hasTheme('dark', 'violet'); | ||
| await sp.hasBackgroundColor({ hex: '#2e2158' }); | ||
| }); | ||
|
|
||
| test('setting theme = light and themeVariant via initialSetup', async ({ page }, workerInfo) => { | ||
| const sp = SpecialErrorPage.create(page, workerInfo); | ||
| await sp.openPage({ additional: { theme: 'light', themeVariant: 'coolGray' } }); | ||
| await sp.hasTheme('light', 'coolGray'); | ||
| await sp.hasBackgroundColor({ hex: '#d2d5e3' }); | ||
| }); | ||
|
|
||
| test('light theme and default themeVariant when unspecified', async ({ page }, workerInfo) => { | ||
| const sp = SpecialErrorPage.create(page, workerInfo); | ||
| await sp.openPage(); | ||
| await sp.hasTheme('light', 'default'); | ||
| await sp.hasBackgroundColor({ hex: '#eeeeee' }); | ||
| }); | ||
|
|
||
| test('dark theme and default themeVariant when unspecified', async ({ page }, workerInfo) => { | ||
| const sp = SpecialErrorPage.create(page, workerInfo); | ||
| await sp.darkMode(); | ||
| await sp.openPage(); | ||
| await sp.hasTheme('dark', 'default'); | ||
| const isIOS = sp.platform.name === 'ios'; // iOS has a different default background color | ||
| await sp.hasBackgroundColor({ hex: isIOS ? '#222222' : '#333333' }); | ||
| }); | ||
|
|
||
| test('changing theme to dark and themeVariant using onThemeUpdate', async ({ page }, workerInfo) => { | ||
| const sp = SpecialErrorPage.create(page, workerInfo); | ||
| await sp.openPage({ additional: { theme: 'light', themeVariant: 'desert' } }); | ||
| await sp.hasTheme('light', 'desert'); | ||
| await sp.hasBackgroundColor({ hex: '#eee9e1' }); | ||
| await sp.acceptsThemeUpdate('dark', 'slateBlue'); | ||
| await sp.hasTheme('dark', 'slateBlue'); | ||
| await sp.hasBackgroundColor({ hex: '#1e3347' }); | ||
| }); | ||
|
|
||
| test('changing theme to light and themeVariant using onThemeUpdate', async ({ page }, workerInfo) => { | ||
| const sp = SpecialErrorPage.create(page, workerInfo); | ||
| await sp.openPage({ additional: { theme: 'dark', themeVariant: 'rose' } }); | ||
| await sp.hasTheme('dark', 'rose'); | ||
| await sp.hasBackgroundColor({ hex: '#5b194b' }); | ||
| await sp.acceptsThemeUpdate('light', 'green'); | ||
| await sp.hasTheme('light', 'green'); | ||
| await sp.hasBackgroundColor({ hex: '#e3eee1' }); | ||
| }); | ||
| }); |
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
13 changes: 13 additions & 0 deletions
13
special-pages/pages/special-error/messages/onThemeUpdate.subscribe.json
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,13 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "type": "object", | ||
| "required": ["theme", "themeVariant"], | ||
| "properties": { | ||
| "theme": { | ||
| "$ref": "./types/browser-theme.json" | ||
| }, | ||
| "themeVariant": { | ||
| "$ref": "./types/theme-variant.json" | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
special-pages/pages/special-error/messages/types/browser-theme.json
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,8 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "title": "Browser Theme", | ||
| "enum": [ | ||
| "light", | ||
| "dark" | ||
| ] | ||
| } |
14 changes: 14 additions & 0 deletions
14
special-pages/pages/special-error/messages/types/theme-variant.json
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,14 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "title": "Theme Variant", | ||
| "enum": [ | ||
| "default", | ||
| "coolGray", | ||
| "slateBlue", | ||
| "green", | ||
| "violet", | ||
| "rose", | ||
| "orange", | ||
| "desert" | ||
| ] | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.