mirror of
https://github.com/wavetermdev/waveterm
synced 2026-05-23 08:48:28 +00:00
Emit dark mode update event when system setting changes (#881)
This commit is contained in:
parent
061949354c
commit
11d09f1740
1 changed files with 5 additions and 2 deletions
|
|
@ -1,15 +1,18 @@
|
|||
import { FORCE_RE_RENDER } from "@storybook/core-events";
|
||||
import { addons } from "@storybook/manager-api";
|
||||
import { UPDATE_DARK_MODE_EVENT_NAME } from "storybook-dark-mode";
|
||||
import { dark, light } from "../../theme";
|
||||
|
||||
addons.register("theme-switcher", (api) => {
|
||||
const query = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const channel = addons.getChannel();
|
||||
const update = () => {
|
||||
const theme = query.matches ? dark : light;
|
||||
api.setOptions({ theme });
|
||||
addons.getChannel().emit(FORCE_RE_RENDER);
|
||||
channel.emit(FORCE_RE_RENDER);
|
||||
channel.emit(UPDATE_DARK_MODE_EVENT_NAME);
|
||||
};
|
||||
|
||||
addons.getChannel().on("storiesConfigured", update);
|
||||
channel.on("storiesConfigured", update);
|
||||
query.addEventListener("change", update);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue