Skip to content

feat(animated-theme-toggler): add controlled mode for next-themes#973

Merged
Yeom-JinHo merged 3 commits into
magicuidesign:mainfrom
Yeom-JinHo:feat/theme-toggler
May 27, 2026
Merged

feat(animated-theme-toggler): add controlled mode for next-themes#973
Yeom-JinHo merged 3 commits into
magicuidesign:mainfrom
Yeom-JinHo:feat/theme-toggler

Conversation

@Yeom-JinHo

Copy link
Copy Markdown
Member

Closes #968.

Summary

AnimatedThemeToggler mutated html.dark and localStorage directly, so useTheme() from next-themes stayed stale until refresh. Adds opt-in controlled props:

theme?: "light" | "dark"
onThemeChange?: (theme: "light" | "dark") => void
  • Uncontrolled (theme undefined): unchanged — no migration.
  • Controlled: skips localStorage (avoids next-themes key collision), still toggles html.dark synchronously for View Transitions, calls onThemeChange so the parent syncs its context.

Chose theme/onThemeChange over the issue's onToggle callback because it matches the shadcn controlled pattern and eliminates the double localStorage write under the same "theme" key.

Usage

const { resolvedTheme, setTheme } = useTheme()

<AnimatedThemeToggler
  theme={resolvedTheme === "dark" ? "dark" : "light"}
  onThemeChange={setTheme}
/>

Changes

  • animated-theme-toggler.tsx — add controlled props, branch applyTheme.
  • animated-theme-toggler-next-themes-demo.tsx — new demo.
  • registry-examples.ts — register demo.

Test plan

  • pnpm lint passes.
  • Uncontrolled demo still toggles + persists across reloads.
  • New next-themes demo: sibling reading useTheme().resolvedTheme updates without refresh.
  • Clip-path animation plays in Chrome and Firefox.

@vercel

vercel Bot commented May 27, 2026

Copy link
Copy Markdown

@Yeom-JinHo is attempting to deploy a commit to the product-studio Team on Vercel.

A member of the Team first needs to authorize it.

@Yeom-JinHo Yeom-JinHo merged commit 1fecedf into magicuidesign:main May 27, 2026
5 of 6 checks passed
@Yeom-JinHo Yeom-JinHo mentioned this pull request May 27, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: animated-theme-toggler.tsx

1 participant