Theme Toggle Slide Top
A wrapper that toggles the theme with a top-to-bottom slide transition using the View Transitions API. Clicking any child runs the transition, and it falls back to an instant toggle when the API is unavailable.


shadcn add · no workarounds · theme neutral (none shipped)Installation
Requires @animbits in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import { ThemeToggleSlideTop } from '@/components/animations/transitions/theme-toggle-slide-top'export function Toggle() { return ( <ThemeToggleSlideTop onToggle={() => document.documentElement.classList.toggle('dark')}> <button type='button'>Toggle theme</button> </ThemeToggleSlideTop> )}- Adding a dark/light mode switch that should feel like a deliberate page-level transition rather than an instant flip.
- Wrapping an existing icon button or switch in a theme toggle that needs a directional slide effect.
- Showcasing View Transitions in a landing page, portfolio, or design-system demo.
- Avoid it when the toggle must work on browsers without View Transitions support and you need the animation to be consistent, or when the theme change is triggered by a route change.
Examples
Basic dark mode toggle
Toggles the dark class on the document root when the wrapped button is clicked.
import * as React from 'react'import { ThemeToggleSlideTop } from '@/components/animations/transitions/theme-toggle-slide-top'export function BasicThemeToggle() { const [dark, setDark] = React.useState(false) const toggle = () => { const next = !dark setDark(next) document.documentElement.classList.toggle('dark', next) } return ( <ThemeToggleSlideTop onToggle={toggle}> <button type='button' aria-label='Toggle theme'> {dark ? 'Light' : 'Dark'} </button> </ThemeToggleSlideTop> )}Slower transition with blur
Uses a longer duration and a 4px blur on both the outgoing and incoming frames.
import * as React from 'react'import { ThemeToggleSlideTop } from '@/components/animations/transitions/theme-toggle-slide-top'export function SlowBlurToggle() { const [dark, setDark] = React.useState(false) return ( <ThemeToggleSlideTop speed={0.8} blur={4} onToggle={() => { setDark((d) => !d) document.documentElement.classList.toggle('dark') }} > <button type='button' aria-label='Toggle theme'> {dark ? 'Light' : 'Dark'} </button> </ThemeToggleSlideTop> )}Icon button in a header
Wraps a styled icon button and passes a custom className to the wrapper element.
import * as React from 'react'import { ThemeToggleSlideTop } from '@/components/animations/transitions/theme-toggle-slide-top'export function HeaderThemeToggle() { const [dark, setDark] = React.useState(false) return ( <ThemeToggleSlideTop className='inline-flex' onToggle={() => { setDark((d) => !d) document.documentElement.classList.toggle('dark') }} > <button type='button' aria-label='Toggle theme' className='rounded-md border px-3 py-2 text-sm' > {dark ? '☀' : '☾'} </button> </ThemeToggleSlideTop> )}API reference
Accessibility
- The wrapper is a plain div with an onClick handler and no role, tabindex, or keyboard handling. Put a native button or link inside it so keyboard users can activate the toggle with Enter or Space.
- Give the interactive child an accessible name such as aria-label='Toggle theme' because the wrapper adds no label.
- The CSS includes a prefers-reduced-motion rule that sets the view-transition animations to none, so users who request reduced motion get an instant switch.
- While a transition runs, the wrapper sets pointer-events to none to block repeated clicks; the isTransitioning guard also ignores extra calls.
- Without View Transitions support, onToggle runs immediately with no animation, so the theme still changes correctly.
- Required CSS: the registry item's global styles (the :root variables, the .theme-slide-top view-transition rules, and the slide keyframes) must be included in the app, or the slide will not appear.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Theme Toggle Slide Top" component (animbits/transitions-theme-toggle-slide-top) from its shadcn registry.1. Install it with: npx shadcn@latest add @animbits/transitions-theme-toggle-slide-top2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: children, onToggle, theme, className, speed, blur.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ThemeToggleSlideTop } from '@/components/animations/transitions/theme-toggle-slide-top'export function Toggle() { return ( <ThemeToggleSlideTop onToggle={() => document.documentElement.classList.toggle('dark')}> <button type='button'>Toggle theme</button> </ThemeToggleSlideTop> )}```Files & dependencies
- registry/new-york/animations/transitions/theme-toggle-slide-top.tsx