Skip to content

feat(website): add light mode toggle to Docusaurus site#2504

Draft
sympatheticmoose wants to merge 2 commits intomainfrom
moose-bring-the-light
Draft

feat(website): add light mode toggle to Docusaurus site#2504
sympatheticmoose wants to merge 2 commits intomainfrom
moose-bring-the-light

Conversation

@sympatheticmoose
Copy link
Contributor

@sympatheticmoose sympatheticmoose commented Mar 2, 2026

Enable the built-in color mode toggle (sun/moon icon) in the navbar, add Grafana light theme CSS variables and Infima mappings, configure a light Prism syntax highlighting theme, and swizzle the ColorModeToggle component.

Light > Dark

Screenshot 2026-03-02 at 17 38 43

Dark > Light

Screenshot 2026-03-02 at 17 38 38

Light mode

Screenshot 2026-03-02 at 17 40 53

Dark mode

Screenshot 2026-03-02 at 17 41 00

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Enable the built-in color mode toggle (sun/moon icon) in the navbar,
add Grafana light theme CSS variables and Infima mappings, configure
a light Prism syntax highlighting theme, and swizzle the ColorModeToggle
component with humorous tooltip text.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged. It will not be considered when calculating future versions of the npm packages and will not appear in the changelogs.

@sympatheticmoose sympatheticmoose added type/docs Changes only affect the documentation no-changelog Don't include in changelog and version calculations labels Mar 2, 2026
@grafana-plugins-platform-bot grafana-plugins-platform-bot bot moved this from 📬 Triage to 🔬 In review in Grafana Catalog Team Mar 2, 2026
Copy link
Collaborator

@jackw jackw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @sympatheticmoose ! 🚀

Comment on lines +18 to +34
// Use a MutationObserver to strip the inner button's native title whenever
// React re-applies it, so the browser falls through to our wrapper's title.
useEffect(() => {
const button = ref.current?.querySelector('button');
if (!button) {
return;
}
button.removeAttribute('title');

const observer = new MutationObserver(() => {
if (button.hasAttribute('title')) {
button.removeAttribute('title');
}
});
observer.observe(button, { attributes: true, attributeFilter: ['title'] });
return () => observer.disconnect();
}, [colorMode]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want this level of customisation I think it would be best to swizzle the ColorModeToggle with eject and customize it rather than rely on useEffect with MutationObserver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW Claude got very angry when Codex suggested this, I had to separate the two before nuclear war erupted

codex: The MutationObserver for the tooltip is heavy-handed. It works, but it's fragile — if Docusaurus changes the inner DOM structure, it could silently break. A simpler approach might be to fully swizzle (--eject) the component and just change the title prop directly, or use CSS pointer-events: none on the inner button with title on the wrapper. That said, the wrapping approach is safer for upgrades, so this is a reasonable tradeoff.

claude: MutationObserver — agree it's heavy-handed, but the alternatives are worse. pointer-events: none on the button would break the toggle. Ejecting is fragile on upgrades. Current approach is the right tradeoff. No change.

But I'm happy to switch to the eject approach

Copy link
Collaborator

@jackw jackw Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with Claude and neither does Docusaurus:

cd docusaurus/website && npm run swizzle @docusaurus/theme-classic -- --list

shows us it's safe to both wrap or eject:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Don't include in changelog and version calculations type/docs Changes only affect the documentation

Projects

Status: 🔬 In review

Development

Successfully merging this pull request may close these issues.

2 participants