Skip to content
Motionbits

Light and dark switchFreeNew

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.

Get the code for Theme Tip
Save Theme Tip: sign in first

Free. Create a free account to copy the source. Read the release note

Theme Tip

Component 03 · React + View Transitions

Live preview

Now in beta

Plan the day
around the light.

Sundial turns sunrise, golden hour and sunset into a schedule you can share.

Start freeHow it works
  • Sunrise06:12
  • Golden hour17:48
  • Sunset18:26

Press the square toggle in the demo's header.

Get it into your app

Three steps. Copy the files and you're done; nothing to install.

SoonCLI and MCP install

  1. Step 1: Get it

    The source is free with an account, free forever. You come straight back to this page.

  2. Step 2: Add it

    Paste the files into src/components/motionbits/, keeping the paths.

    • theme-tip/theme-tip.tsx
    • theme-tip/theme-tip.css
    • quarter-turn.ts
    • theme-tip/index.ts

    Needs react and react-dom. No other packages to install.

  3. 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

Theme Tip props
PropTypeDefaultWhat 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.
durationnumber700Length of the tip in ms.
ThemeTipTogglecomponent—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.
refThemeTipHandle—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.