0.0.11 • Published 4 years ago

svelte-theme-switcher v0.0.11

Weekly downloads
44
License
-
Repository
-
Last release
4 years ago

Svelte Theme Switcher

Test

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

Basic example

App.svelte

<script>
  import ThemeSwitcher from "svelte-theme-switcher";
</script>

<style>
  :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;
  }
</style>

<ThemeSwitcher />

Installation

npm i svelte-theme-switcher
yarn add svelte-theme-switcher

Component props

Propertydefaulttypenotes
height:30pxstringmust be a px value
width:60pxstring
transition0.6sstring
background{ light: #ecf0f1, dark: #333 }object

Example

<ThemeSwitcher
  options={{
    height: "30px",
    width: "60px",
    transition: "0.6s",
    background: {
      light: "#ecf0f1",
      dark: "#333",
    },
  }}
/>

Accessing state

<script>
import { theme } from "svelte-theme-switcher";
</script>

<h1>{$theme}</h1>

Web Components

In the head of your document add:

<script src="https://unpkg.com/svelte-theme-switcher@0.0.11/dist/wc/index.js" />
<style>
  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;
  }
</style>

this ensure's there is no inital flicker

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

<theme-switcher></theme-switcher>
0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago