1.1.3 • Published 2 years ago

svelte-theme-toggle v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

svelte-theme-toggle

npm npm

A dead simple way to implement a dark theme toggle in your Svelte/SvelteKit application.

Demo

Getting-Started

npm i svelte-theme-toggle

Usage

Import the package in <script> in a svelte component and then declare it in the body.

<script>
	import ThemeToggle from "svelte-theme-toggle";
</script>

<main>
	<!-- Some Stuff here -->
	<ThemeToggle />
	<!-- Some other stuff here -->
</main>

Set styles

Use the following parameters in your global styles to actually change the colors on theme change

:root {
        --bg: #fff;
        --text-color: #000;
}

:global([data-theme="dark"]) {
        --bg: #121212;
        --text-color: #fff;
}

:global(body) {
        background-color: var(--bg);
        color: var(--text-color);
        transition: ease 0.5s;  /* Change the transition time by altering this property */
}

It is highly recommended to use this component on __layout.svelte or it's derivatives.

1.1.3

2 years ago

1.1.1

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago