Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/dev-warner/svelte-theme-switcher

Component and state for switching theme
https://github.com/dev-warner/svelte-theme-switcher

Last synced: 3 months ago
JSON representation

Component and state for switching theme

Awesome Lists containing this project

README

        

# Svelte Theme Switcher

![Test](https://github.com/dev-warner/svelte-theme-switcher/workflows/Test/badge.svg)

A happy little svelte theme switcher to brighten or maybe darken your day 🌞.

- [demo](https://dev-warner.github.io/svelte-theme-switcher/)

## Basic example

App.svelte

```html

import ThemeSwitcher from "svelte-theme-switcher";

:global(body) {
background: var(--background);
color: var(--text);
transition: 0.6s;
}

:global(.theme-light) {
--background: rgb(250, 252, 240);
--text: #222;
}
:global(.theme-dark) {
--background: #222;
--text: #fff;
}

```

## Installation

```bash
npm i svelte-theme-switcher
```

```
yarn add svelte-theme-switcher
```

### Component props

| Property | default | type | notes |
| ---------- | -------------------------------- | ------ | ------------------ |
| height: | 30px | string | must be a px value |
| width: | 60px | string |
| transition | 0.6s | string |
| background | `{ light: #ecf0f1, dark: #333 }` | object |

### Example

```js

```

### Accessing state

```javascript

import { theme } from "svelte-theme-switcher";

{$theme}


```

## Web Components

In the head of your document add:

```html

body {
background: var(--background);
color: var(--text);
transition: 0.6s;
}

.theme-light {
--background: rgb(250, 252, 240);
--text: #222;
}
.theme-dark {
--background: #222;
--text: #fff;
}

```

this ensure's there is no inital flicker

You can now add the web component to switch between themes.

```html

```