1.0.3 • Published 8 months ago

nottheme v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

nottheme

Accessible theme switcher for Astro.

Installation

npm i nottheme

Usage

See the demo.

If you need to know when the theme changes, set window.__nottheme_onChange to a function:

window.__nottheme_onChange = (key: string, value: string) => {
  console.log(key, value);
};

Features

  • Static sites (localStorage)
  • Zero JavaScript (:has())
  • Zero JavaScript with SSR (cookies)

How it works

There are three components:

  • a component that generates a CSS file based on your specified configuration
  • a JavaScript script which saves preferences if JavaScript is enabled
  • a component to change the theme on your site

With JavaScript enabled:

  • Classes are applied to the body element on page load
  • Settings are saved to localStorage
  • Changes are made through event listeners

With JavaScript disabled:

  • Classes are applied to the nottheme class using :has()
  • Settings are not saved and will reset on page navigation or refresh
  • Changes are made through CSS selectors (selection component must be on every page!)
1.0.3

8 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago