diff --git a/docs/public/scripts/graphiql-theme.js b/docs/public/scripts/graphiql-theme.js new file mode 100644 index 0000000000..b19fe787b9 --- /dev/null +++ b/docs/public/scripts/graphiql-theme.js @@ -0,0 +1,25 @@ +window.addEventListener("DOMContentLoaded", () => { + try { + const themeSwitchElement = document.querySelector("starlight-rapide-theme-select") + if (!themeSwitchElement) return + + const switchButtonElement = themeSwitchElement.children.item(0) + if (!switchButtonElement) return + + switchButtonElement.addEventListener("click", () => { + const newTheme = document.documentElement.getAttribute("data-theme") + const oldTheme = newTheme === "light" ? "dark" : "light" + if (!newTheme) return + + if (document.body.classList.contains(`graphiql-${oldTheme}`)) { + document.body.classList.replace(`graphiql-${oldTheme}`, `graphiql-${newTheme}`) + } else document.body.classList.add(`graphiql-${newTheme}`) + + if (document.documentElement.classList.contains(oldTheme)) { + document.documentElement.classList.replace(oldTheme, newTheme) + } else document.documentElement.classList.add(newTheme) + }) + } catch { + /* empty */ + } +}) diff --git a/docs/src/components/graphiql/GraphiQL.astro b/docs/src/components/graphiql/GraphiQL.astro index 94230558ad..fe5ee8ee80 100644 --- a/docs/src/components/graphiql/GraphiQL.astro +++ b/docs/src/components/graphiql/GraphiQL.astro @@ -33,7 +33,7 @@ interface Props {}