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:
David Lechner
2022-03-14 16:39:17 -05:00
parent 062968ed9d
commit 9518a21241
11 changed files with 29 additions and 170 deletions
+1 -16
View File
@@ -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();
});
});
-8
View File
@@ -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;
}