Skip to content

Commit

Permalink
fix: use html data-theme to detect current
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Nov 23, 2024
1 parent 71171a0 commit 54e8192
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions docs/public/scripts/graphiql-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ window.addEventListener("DOMContentLoaded", () => {
const switchButtonElement = themeSwitchElement.children.item(0)
if (!switchButtonElement) return

switchButtonElement.addEventListener("click", event => {
switchButtonElement.addEventListener("click", () => {
const newTheme = document.documentElement.getAttribute("data-theme")
const oldTheme = newTheme === "light" ? "dark" : "light"
if (!newTheme) return

document.body.classList.replace(`graphiql-${oldTheme}`, `graphiql-${newTheme}`)
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)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/graphiql/GraphiQL.astro
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface Props {}
height: 100% !important;
}

body.graphiql-dark {
html[data-theme='dark'] {
& .graphiql-toolbar,
.graphiql-editor-tool,
.graphiql-editor-tools,
Expand Down

0 comments on commit 54e8192

Please sign in to comment.