astro-theme-toggle
astro-theme-toggle
Add a ripple-style theme toggle animation to your Astro project with ease.
https://github.com/user-attachments/assets/19069840-629d-445b-82e7-aea142242225
Installation
npm install astro-theme-toggle
Usage
-
Add the
ThemeScriptcomponent to your<head>. This will set thedata-themeattribute and toggle thedarkclass on your<html>element based on the user's theme preference.--- import { ThemeScript } from 'astro-theme-toggle/components'; --- <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <ThemeScript /> <!-- other head elements --> </head> -
Add the
Togglecomponent to your<body>to toggle the theme:--- import { Toggle } from 'astro-theme-toggle/components' --- <Toggle style="width: 32px; height: 32px;" /> -
You can customize the icon by passing a
Fragmentwith theicon-lightandicon-darkslots.--- import { Toggle } from 'astro-theme-toggle/components' import MyLightIcon from './my-light-icon.astro' import MyDarkIcon from './my-dark-icon.astro' --- <Toggle style="width: 32px; height: 32px;"> <Fragment slot="icon-light"> <MyLightIcon /> </Fragment> <Fragment slot="icon-dark"> <MyDarkIcon /> </Fragment> </Toggle>
Live Examples
License
MIT
Related Packages
astro-intlayer
Easily internationalize i18n your Astro applications with type-safe multilingual...
230,318
856
starwind
Install and manage Starwind UI components in Astro, React, Vue (beta), and Svelt...
22,190
752
@feugene/astro-granularity
Astro integration for @feugene/granularity — flash-free theme mode, styles, auto...
1,735
0
Version History
| Version | Released | License |
|---|---|---|
| 0.8.2 | MIT | |
| 0.8.1 | MIT | |
| 0.8.0 | MIT | |
| 0.7.0 | MIT | |
| 0.6.1 | MIT | |
| 0.6.0 | MIT | |
| 0.5.1 | MIT | |
| 0.5.0 | MIT | |
| 0.4.0 | MIT | |
| 0.3.5 | MIT | |
| 0.3.4 | MIT | |
| 0.3.3 | MIT | |
| 0.3.2 | MIT | |
| 0.3.1 | MIT | |
| 0.3.0 | MIT | |
| 0.2.1 | MIT | |
| 0.2.0 | MIT | |
| 0.1.0 | MIT |