Theme Tip
Dark mode, but it tips over. The incoming theme leaves the toggle as a square block and rolls across the page on its corner dot, so the page never crossfades between two fills.
Free. Create a free account to copy the source. Read the release note
Theme Tip
Live preview
Now in beta
Plan the day
around the light.
Sundial turns sunrise, golden hour and sunset into a schedule you can share.
- Sunrise06:12
- Golden hour17:48
- Sunset18:26
Press the square toggle in the demo's header.
Sign in free to see the code
Every file of Theme Tip, ready to copy. Free account, free forever. You come straight back here.
Get it into your app
Three steps. Copy the files and you're done; nothing to install.
SoonCLI and MCP install
Step 1: Get it
The source is free with an account, free forever. You come straight back to this page.
Step 2: Add it
Paste the files into
src/components/motionbits/, keeping the paths.theme-tip/theme-tip.tsxtheme-tip/theme-tip.cssquarter-turn.tstheme-tip/index.ts
Needs react and react-dom. No other packages to install.
Step 3: Use it
Import it and drop it in. Usage and props are just below.
import { ThemeTip, ThemeTipToggle } from "@/components/motionbits/theme-tip";
Usage
import { ThemeTip, ThemeTipToggle } from "@/components/motionbits/theme-tip";
export function Landing() {
return (
<ThemeTip defaultTheme="light" duration={700}>
<header>
<Logo />
<ThemeTipToggle />
</header>
<main>{/* the page re-themes with [data-theme] */}</main>
</ThemeTip>
);
}
// Wrap the whole app to re-theme the document, and keep your own class in sync:
<ThemeTip
theme={theme}
onThemeChange={(next) => {
setTheme(next);
document.documentElement.classList.toggle("dark", next === "dark");
}}
/>
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
theme / defaultTheme | "light" | "dark" | "light" | Controlled or uncontrolled theme of the scope. |
onThemeChange | (theme) => void | — | Runs inside the view transition callback, so anything you change here is part of the new snapshot. |
duration | number | 700 | Length of the tip in ms. |
ThemeTipToggle | component | — | A square toggle with the pivot dot on its corner. It sets the pivot the block tips about. |
useThemeTip() | { theme, toggle, setTheme } | — | For custom toggles. Register the pivot element with the returned ref. |
ref | ThemeTipHandle | — | tip() and setTheme(theme), for driving the switch from code. |
Accessibility
- The toggle is a button with role switch, a name ("Dark theme") and an aria-checked state.
- The page content is real and live under the block, and the theme change is applied once, at the start of the view transition.
- While the block is moving the page is not interactive for 0.7s, which is a view transition's normal behaviour.
Motion
- A square of the incoming ground, sized to the toggle, tips from 0° to −90° about the toggle's corner dot while it grows to cover the scope (0.7s, ease-out).
- The block keeps the new theme's fill for the whole move, so there is no crossfade. The accent dot rides the pivot and pops on landing.
- Toggling back runs the same move with the other theme.
- Built with the View Transitions API, WAAPI and a clip-path polygon. No GSAP.
- With reduced motion the theme crossfades over 0.2s. Without View Transitions support the theme changes instantly.