A compact theme toggle with motion animations and accessibility.
Made by raouf.codesOverview
Core Concept
The ThemeSwitch component provides a one-click theme toggle between light and dark modes. Built with next-themes, it handles SSR hydration gracefully while delivering smooth icon transitions via Framer Motion.
Key Features
- Animated icon transitions — Smooth morph between sun and moon icons
- SSR-safe — Prevents hydration mismatch with mount detection
- next-themes integration — Seamless theme state management
- Variant support — Inherits button styling, shape, and elevation props
Installation
Usage
Basic
Composition
Use within navbars or settings panels:
API Reference
ThemeSwitch
Azemmur API Reference - Button Primitive| Prop | Type | Default |
|---|---|---|
styling? | enum | "ghost" |
intent? | enum | "primary" |
size? | enum | "md" |
shape? | enum | "pill" |
elevation? | enum | "raised" |
...props? | HTMLMotionProps<"button"> | - |
Accessibility
- ARIA label — Announces current theme state to screen readers
- Focus visible — Native focus ring for keyboard navigation
- Reduced motion — Icon transitions respect
prefers-reduced-motion
| Key | Action |
|---|---|
Enter / Space | Toggles theme |
Tab | Moves focus |
Credits
- Built with next-themes
- Icon animations powered by Motion
Built by raouf.codes. The source code is available on GitHub.
Last updated: 3/21/2026