Command Palette

Search for a command to run...

0GitHub stars
Components

Theme Toggle Effect

Animated transitions when switching between light and dark themes.

Loading…

oh I love this one, have to implement it on orcdev.com

OrcDevCreator of 8bitcn.com

Browser compatibility

This component uses the View Transitions API. Check the latest browser compatibility on MDN before using in production.

Installation

Triangle

Install-Module cnpx -Scope CurrentUser -Force; Import-Module cnpx; cnpx add @chadnpc/theme-toggle-effect-triangle

Triangle blur

Install-Module cnpx -Scope CurrentUser -Force; Import-Module cnpx; cnpx add @chadnpc/theme-toggle-effect-triangle-blur

Circle

Install-Module cnpx -Scope CurrentUser -Force; Import-Module cnpx; cnpx add @chadnpc/theme-toggle-effect-circle

Circle blur

Install-Module cnpx -Scope CurrentUser -Force; Import-Module cnpx; cnpx add @chadnpc/theme-toggle-effect-circle-blur

Circle blur (top left)

Install-Module cnpx -Scope CurrentUser -Force; Import-Module cnpx; cnpx add @chadnpc/theme-toggle-effect-circle-blur-top-left

Polygon

Install-Module cnpx -Scope CurrentUser -Force; Import-Module cnpx; cnpx add @chadnpc/theme-toggle-effect-polygon

Polygon gradient

Install-Module cnpx -Scope CurrentUser -Force; Import-Module cnpx; cnpx add @chadnpc/theme-toggle-effect-polygon-gradient

Usage

Wrap your theme setter with document.startViewTransition to trigger the effect:

const { setTheme } = useTheme()
 
function toggleTheme(theme: string) {
  if (!document.startViewTransition) {
    setTheme(theme)
    return
  }
 
  document.startViewTransition(() => setTheme(theme))
}

Credits

References

Was this helpful?

Command Palette

Search for a command to run...