Components
- Accordion
- Add to Cart
- Animated List
- Carousel
- Collapsible Sidebarnew
- Dynamic Island
- Expandable Cardnew
- Expanding Searchnew
- Filter Grid
- Kanban Board
- Layout Switcher
- Morphing Popover
- Number Flip
- Page Transition
- Product Gallery
- Segmented Control
- Sortable Table
- Stack Navigator
- Status Button
- Step Wizard
- Tabs
- Text Morphnew
- Theme Mode Switch
- Theme Morph Button
- Theme Toggle Button
- Theme Toggle Switch
- Theme Transition
- Toast Stacknew
Installation
$ pnpm dlx shadcn@latest add @transition-kit/theme-transitionSetup
import {
createRootRoute,
HeadContent,
Outlet,
Scripts,
} from "@tanstack/react-router";
import {
ThemeTransitionProvider,
ThemeTransitionScript,
} from "@/components/transitions/theme-transition";
const RootDocument = () => (
<html lang="en" suppressHydrationWarning>
<head>
<HeadContent />
<ThemeTransitionScript />
</head>
<body>
<ThemeTransitionProvider transition="circle-reveal">
<Outlet />
</ThemeTransitionProvider>
<Scripts />
</body>
</html>
);
export const Route = createRootRoute({ component: RootDocument });Usage
import { useThemeTransition } from "@/components/transitions/theme-transition";
export const ThemeButton = () => {
const { resolvedTheme, setTheme, toggleTheme } = useThemeTransition();
return (
<>
{/* The provider's style, starting at the pointer. */}
<button type="button" onClick={(event) => toggleTheme({ origin: event })}>
{resolvedTheme === "dark" ? "Light mode" : "Dark mode"}
</button>
{/* Another style for this change only. */}
<button
type="button"
onClick={() => setTheme("system", { transition: "diagonal-wipe" })}
>
System
</button>
</>
);
};API Reference
ThemeTransitionProvider
| Prop | Type | Default | Description |
|---|---|---|---|
transition | string | "circle-reveal" | Style slug used when setTheme and toggleTheme are called without one. Circle Reveal ships with the core. |
defaultTheme | "light" | "dark" | "system" | "system" | Theme used before the stored one loads. |
storageKey | string | "theme" | localStorage key. Synced across tabs; system follows prefers-color-scheme. |
duration | number | - | Milliseconds. Overrides every style's timing. |
easing | string | - | Overrides every style's easing. |
children | ReactNode | - | Must cover everything the user sees; its element is snapshotted. |
...props | ComponentProps<"div"> | - | Spread onto the provider's element. |
ThemeTransitionScript
| Prop | Type | Default | Description |
|---|---|---|---|
storageKey | string | "theme" | Must match the provider's. |
defaultTheme | "light" | "dark" | "system" | "system" | Must match the provider's. |
nonce | string | - | Content-Security-Policy nonce. |
useThemeTransition
| Property | Type | Description |
|---|---|---|
mounted | boolean | false on the server and until the stored theme is read. |
theme | "light" | "dark" | "system" | The selected theme. |
resolvedTheme | "light" | "dark" | The active theme, with system resolved. |
setTheme | (theme: Theme, options?: ThemeTransitionOptions) => void | Changes the theme, animated. |
toggleTheme | (options?: ThemeTransitionOptions) => void | Flips between light and dark, animated. |
ThemeTransitionOptions
| Option | Type | Description |
|---|---|---|
transition | string | Style slug for this change only. Defaults to the provider's transition. |
origin | { clientX: number; clientY: number } | Element | The viewport centre. Click event starts at the pointer; an element starts at its centre. |