mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Emit dark mode update event when system setting changes (#881)
This commit is contained in:
parent
061949354c
commit
11d09f1740
@ -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 New Issue
Block a user