An open API service indexing awesome lists of open source software.

https://github.com/cdransf/theme-toggle

A web component that simplifies controlling light/dark theming for a site.
https://github.com/cdransf/theme-toggle

javascript webcomponent webcomponents

Last synced: 12 months ago
JSON representation

A web component that simplifies controlling light/dark theming for a site.

Awesome Lists containing this project

README

          

# `` web component

A web component that simplifies controlling light/dark theming for a site.

```sh
npm i @cdransf/theme-toggle
```

---

## Example usage

Add the `theme-load.js` to your document `` to prevent an unthemed flash on load. This ensures access to the `document`.

```html







```

**Optional attributes:**

- **mode:** accepts either `control` or `toggle` and defaults to `toggle`. If `toggle` is set, you can add `` and allow the user to cycle back to their system preference.
- **storage:** sets the storage API to be used. Defaults to `sessionStorage`, but can also be set to "`local` for `localStorage`.

- Add the `theme-toggle.js` to your markup, set your template.
- Add `` to your site's header.
- Use `light-dark` to define your preferred colors for each scheme.

[Refer to MDN for documentation on CSS light-dark().](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark)