Circular theme reveal
Switching theme spreads the new colours out from the toggle button in a growing circle until they cover the panel.
The React code for this component comes with Pro.
Unlock with ProUse it for
- Light and dark mode toggles in a header or settings panel
- Any switch between two visual modes of the same content
Avoid
- Toggles that change layout, not just colour, since the two copies will not line up
- Pages with heavy content, where rendering a second copy is costly
How it works
On click the button centre and the distance to the farthest panel corner are measured. A second copy of the panel in the new theme mounts on top with clip-path circle(0px) at that point, and on the next frame the radius is set to the full distance so a clip-path transition grows it. On transitionend the base panel switches theme and the overlay unmounts. Here it is scoped to one panel; for a whole site the same idea works with the View Transitions API.
Accessibility
The toggle is a real button whose aria-label names the theme it will switch to, and focus stays on it because the base panel never remounts. The overlay copy is aria-hidden with no focusable elements. Reduced motion swaps the theme instantly.
Get the source with Pro
The demo above is free to play with. Pro unlocks the source of this and every other Pro component, with copy-ready code and a zip download.
Already bought? Sign in- Pay once
Lifetime
Pay once, keep it forever.
$39once
- Every Pro component, with full source
- Lifetime updates: every future Pro component included
- One zip download, ready to drop into a React app
- Commercial use in unlimited client and personal projects