Skip to content

Commit ef78eee

Browse files
committed
feat: better dark mode detection
1 parent 32a55ca commit ef78eee

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/browser/src/global/media.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
* Get the current color scheme of the user.
33
*/
44
export function getColorScheme() {
5-
return window.matchMedia("(prefers-color-scheme: dark)").matches
5+
const { colorScheme } = window.getComputedStyle(document.body);
6+
return colorScheme === "dark" ||
7+
colorScheme === "dark only" ||
8+
window.matchMedia("(prefers-color-scheme: dark)").matches
69
? "dark"
710
: "light";
811
}

packages/storybook/stories/button.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
:root {
22
--button-bg: #1ea7fd;
33
--button-text: #fff;
4+
color-scheme: light;
45
}
56

67
.dark {
78
--button-bg: #fff;
89
--button-text: #333;
910
background: #000;
11+
color-scheme: dark;
1012
}
1113

1214
.storybook-button {

0 commit comments

Comments
 (0)