generated from openmcp-project/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Support themes #200
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
Support themes #200
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82da253
Support themes
andreaskienle cd33b4b
Refactor
andreaskienle fe770e2
Preserve theme after redirect
andreaskienle 2346be7
Merge branch 'main' into feat/theming
andreaskienle 0e7e78d
Merge branch 'main' into feat/theming
andreaskienle 2bf4e08
Merge branch 'main' into feat/theming
andreaskienle 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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { resolveTheme } from './ThemeManager.tsx'; | ||
|
|
||
| describe('ThemeManager', () => { | ||
| describe('resolveTheme()', () => { | ||
| it('returns theme coming from URL when it is truthy', () => { | ||
| expect(resolveTheme('sap_fiori_3', true)).toBe('sap_fiori_3'); | ||
| expect(resolveTheme('custom_theme', false)).toBe('custom_theme'); | ||
| }); | ||
|
|
||
| it('falls back to dark default when URL theme is falsy and user prefers dark mode', () => { | ||
| expect(resolveTheme(null, true)).toBe('sap_horizon_dark'); | ||
| expect(resolveTheme('', true)).toBe('sap_horizon_dark'); | ||
| }); | ||
|
|
||
| it('falls back to light default when URL theme is falsy and user prefers light mode', () => { | ||
| expect(resolveTheme(null, false)).toBe('sap_horizon'); | ||
| expect(resolveTheme('', false)).toBe('sap_horizon'); | ||
| }); | ||
| }); | ||
| }); |
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,25 @@ | ||
| import { useEffect } from 'react'; | ||
| import { setTheme } from '@ui5/webcomponents-base/dist/config/Theme.js'; | ||
| import { useIsDarkModePreferred } from '../../hooks/useIsDarkModePreferred.ts'; | ||
|
|
||
| const DEFAULT_THEME_LIGHT = 'sap_horizon'; | ||
| const DEFAULT_THEME_DARK = 'sap_horizon_dark'; | ||
|
|
||
| export function resolveTheme(themeFromUrl: string | null, isDarkModePreferred: boolean): string { | ||
| if (themeFromUrl) { | ||
| return themeFromUrl; | ||
| } | ||
| return isDarkModePreferred ? DEFAULT_THEME_DARK : DEFAULT_THEME_LIGHT; | ||
| } | ||
|
|
||
| export function ThemeManager() { | ||
| const isDarkModePreferred = useIsDarkModePreferred(); | ||
| const themeFromUrl = new URL(window.location.href).searchParams.get('sap-theme'); | ||
|
|
||
| useEffect(() => { | ||
| const resolvedTheme = resolveTheme(themeFromUrl, isDarkModePreferred); | ||
| void setTheme(resolvedTheme); | ||
| }, [isDarkModePreferred, themeFromUrl]); | ||
|
|
||
| return null; | ||
| } | ||
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,22 @@ | ||
| import { useSyncExternalStore } from 'react'; | ||
|
|
||
| function makeMediaQueryStore(mediaQuery: string) { | ||
| function getSnapshot() { | ||
| return window.matchMedia(mediaQuery).matches; | ||
| } | ||
|
|
||
| function subscribe(callback: () => void) { | ||
| const mediaQueryList = window.matchMedia(mediaQuery); | ||
| mediaQueryList.addEventListener('change', callback); | ||
|
|
||
| return () => { | ||
| mediaQueryList.removeEventListener('change', callback); | ||
| }; | ||
| } | ||
|
|
||
| return function useMediaQuery() { | ||
| return useSyncExternalStore(subscribe, getSnapshot); | ||
| }; | ||
| } | ||
|
|
||
| export const useIsDarkModePreferred = makeMediaQueryStore('(prefers-color-scheme: dark)'); |
This file was deleted.
Oops, something went wrong.
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
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.