mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-15 02:54:07 +00:00
settings: replace darkMode with useDarkMode hook
This is a minor breaking change for users that don't have dark mode set to the default value since the localStorage key has changed (hard- coded in 3rd party library).
This commit is contained in:
+1
-16
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2021 The Pybricks Authors
|
||||
|
||||
import { isAndroid, isMacOS, isWindows, prefersDarkMode } from './os';
|
||||
import { isAndroid, isMacOS, isWindows } from './os';
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
@@ -39,18 +39,3 @@ describe('isWindows', () => {
|
||||
expect(isWindows()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('prefersDarkMode', () => {
|
||||
test('is true', () => {
|
||||
jest.spyOn(window, 'matchMedia').mockReturnValue({
|
||||
matches: true,
|
||||
} as MediaQueryList);
|
||||
expect(prefersDarkMode()).toBeTruthy();
|
||||
});
|
||||
test('is false', () => {
|
||||
jest.spyOn(window, 'matchMedia').mockReturnValue({
|
||||
matches: false,
|
||||
} as MediaQueryList);
|
||||
expect(prefersDarkMode()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,11 +29,3 @@ export function isMacOS(): boolean {
|
||||
export function isWindows(): boolean {
|
||||
return /win/i.test(navigator.platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the OS is set to dark mode.
|
||||
* @returns: `true` if dark mode should be preferred, otherwise `false`.
|
||||
*/
|
||||
export function prefersDarkMode(): boolean {
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user