From 5dac546a5d57aa42b3a7b66079464520b5ce6e69 Mon Sep 17 00:00:00 2001 From: o-az Date: Fri, 22 Nov 2024 22:00:51 -0800 Subject: [PATCH 1/3] fix: graphiql light mode theme --- docs/public/scripts/graphiql-theme.js | 23 ++++++++++ docs/src/components/graphiql/GraphiQL.astro | 51 +++++++++++---------- docs/src/components/graphiql/setup.ts | 4 +- docs/src/content/docs/reference/graphql.mdx | 4 ++ 4 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 docs/public/scripts/graphiql-theme.js diff --git a/docs/public/scripts/graphiql-theme.js b/docs/public/scripts/graphiql-theme.js new file mode 100644 index 0000000000..26575b95d7 --- /dev/null +++ b/docs/public/scripts/graphiql-theme.js @@ -0,0 +1,23 @@ +window.addEventListener("DOMContentLoaded", () => { + const themeSwitchElement = document.querySelector("starlight-rapide-theme-select") + if (!themeSwitchElement) return + + const switchButtonElement = themeSwitchElement.children.item(0) + if (!switchButtonElement) return + + switchButtonElement.addEventListener("click", event => { + try { + 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.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..428145ad1f 100644 --- a/docs/src/components/graphiql/GraphiQL.astro +++ b/docs/src/components/graphiql/GraphiQL.astro @@ -33,7 +33,7 @@ interface Props {}