UNPKG

@graphiql/react

Version:

[Changelog](https://github.com/graphql/graphiql/blob/main/packages/graphiql-react/CHANGELOG.md) | [API Docs](https://graphiql-test.netlify.app/typedoc/modules/graphiql_react.html) | [NPM](https://www.npmjs.com/package/@graphiql/react)

40 lines (39 loc) 1.06 kB
import { STORAGE_KEY } from "../constants.js"; import { monacoStore } from "./monaco.js"; const createThemeSlice = ({ editorTheme }) => (set, get) => ({ theme: null, actions: { setTheme(theme) { const { storage } = get(); storage.set(STORAGE_KEY.theme, theme ?? ""); document.body.classList.remove("graphiql-light", "graphiql-dark"); if (theme) { document.body.classList.add(`graphiql-${theme}`); } const { monaco } = monacoStore.getState(); const resolvedTheme = theme ?? getSystemTheme(); const monacoTheme = editorTheme[resolvedTheme]; monaco == null ? void 0 : monaco.editor.setTheme(monacoTheme); set({ theme, monacoTheme }); } } }); function getSystemTheme() { const mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)"); const isDark = mediaQueryList.matches; const systemTheme = isDark ? "dark" : "light"; return systemTheme; } export { createThemeSlice }; //# sourceMappingURL=theme.js.map