Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Global Navigation

  • Navbar
  • BeianFooter
  • Brand
  • AppLauncher
  • Sidebar
  • NavMenu
  • NavigationMenu
  • Menu
  • Menubar
  • Dock
  • BubbleMenu
  • CardNav
  • FlowingMenu
  • GooeyNav
  • PillNav
  • StaggeredMenu

In-page Navigation

  • RouteTabs
  • Tabs
  • Breadcrumb
  • Pagination
  • Anchor
  • Affix
  • BackTop
  • Stepper
  • Steps
  • PageHeader

Actions and Tools

  • Command
  • ContextMenu
  • Toolbar
  • Accordion
  • Collapsible
  • Link
  • AnimatedThemeToggler

AnimatedThemeToggler

animated-theme-toggler

Switches color themes through an animated icon transition.

Usage

Basic usage

Click the button to switch light and dark themes with a circular reveal animation (reusing Hulian ThemeProvider).

tsx
<AnimatedThemeToggler />

Custom animation duration

duration Adjust the circular reveal animation duration (ms), default 500.

tsx
<AnimatedThemeToggler duration={900} />

Matching description copy

The switcher is a standard button that can be placed alongside other elements in the toolbar.

Click: Circle reveal switches light and dark
tsx
<div className="flex items-center gap-3">
  <AnimatedThemeToggler />
  <span className="text-sm text-muted-foreground">Click: Circle Reveal Switch Light and Dark</span>
</div>

Navbar tools (ghost, compact)

variant="ghost" drops the border and background, and size="sm" matches the height of Button iconSm, so their edges line up side by side.

tsx
<div className="flex items-center gap-1">
  <Button variant="ghost" muted size="iconSm" aria-label="Settings">…</Button>
  <AnimatedThemeToggler variant="ghost" size="sm" />
</div>

When to use

Use AnimatedThemeToggler for a header or settings control that switches light and dark themes with a circular reveal radiating from the button. For an unanimated switch or custom control, compose directly with useTheme().

Import

ts
import { AnimatedThemeToggler } from "@hulianui/ui"

Props

NameTypeDefaultDescription
theme"light" | "dark"-Controlled theme. When set, the button's state and target are driven by this value, ignoring ThemeProvider / the standalone fallback; clicks only call onThemeChange.
onThemeChange(next: "light" | "dark") => void-Called with the next theme when a switch is requested. Fires in both modes; in controlled mode it is the only place the value lands.
durationnumber500Circular reveal duration in milliseconds.
variant"outline" | "ghost""outline"outline has a border and surface background; ghost has neither, rests in the secondary gray, and returns to the body color on hover, for sitting next to ghost icon buttons in a navbar.
size"md" | "sm""md"md is 40px; sm is 32px, the same height as Button size="iconSm".
classNamestring-Button class name.
aria-labelstring-Accessible label.

Without aria-label, the button uses built-in Chinese state-dependent copy: "\u5207\u6362\u5230\u4eae\u8272" (“Switch to light”) in dark mode and "\u5207\u6362\u5230\u6697\u8272" (“Switch to dark”) otherwise.

Example

tsx
<AnimatedThemeToggler aria-label="Toggle light and dark theme" />

// Navbar tools: next to <Button variant="ghost" muted size="iconSm">
<AnimatedThemeToggler variant="ghost" size="sm" />

// Controlled: the theme source of truth lives with the consumer (API / own storage);
// ThemeProvider only mirrors it via forcedTheme
<AnimatedThemeToggler theme={theme} onThemeChange={(next) => savePreference(next)} />

Usage guidelines

  • The circular reveal uses the View Transitions API. Unsupported browsers switch instantly while preserving the theme change.
  • The button position determines the reveal origin, so this is a client component. Use it below a "use client" boundary in an RSC tree.
  • Without ThemeProvider, the component no longer throws. It falls back to local state, reads and writes <html data-theme>, uses the hulian-theme localStorage key, and warns in development. This fallback does not synchronize with other useTheme consumers; production applications should still install ThemeProvider.
  • Controlled mode (#284). With ThemeProvider forcedTheme, toggle writes the preference without changing the visual theme, so an uncontrolled toggler plays the reveal but nothing switches. When the theme source of truth is outside the library (shell + iframes each mounting a forcedTheme provider fed from one place), pass theme + onThemeChange: the circular reveal is unchanged, only where the value lands is up to the consumer. Controlled mode never touches useTheme().toggle and never enters the standalone fallback.
  • Use useTheme when application code must fail without a provider. Library components and tolerant integrations can use useThemeOptional, which returns null without context.

Related

Default toggle labels follow ConfigProvider (zhCN / enUS); an explicit aria-label always wins.
Command · ContextMenu · Toolbar · Accordion · Collapsible · Link

PreviousLinkNavigationNextBubbleMenu

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Example
    • Usage guidelines
    • Related