-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
249 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"mode-watcher": patch | ||
--- | ||
|
||
feat: Add support for custom themes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: setTheme | ||
description: Programatically set the custom theme. | ||
tagline: API Reference | ||
--- | ||
|
||
A function that sets the current custom theme, not to be confused with [`setMode`](/docs/api-reference/set-mode), which sets the mode (`'light'`, `'dark'` or `'system'`). | ||
|
||
The theme can be set to any arbitrary string value, and is persisted to localStorage and applied to the root `html` element via the `data-theme` attribute. | ||
|
||
## Usage | ||
|
||
```svelte | ||
<script lang="ts"> | ||
import { setTheme } from "mode-watcher"; | ||
</script> | ||
<button on:click={() => setTheme("dracula")}>Dracula Theme</button> | ||
<button on:click={() => setTheme("retro")}>Retro Theme</button> | ||
``` |
28 changes: 28 additions & 0 deletions
28
sites/docs/content/api-reference/theme-local-storage-key.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: themeLocalStorageKey | ||
description: The key used to store the theme in local storage. | ||
tagline: API Reference | ||
--- | ||
|
||
<script> | ||
import { Callout } from '$lib/components' | ||
</script> | ||
|
||
The key used to store the _theme_ in local storage. | ||
|
||
## Usage | ||
|
||
If you wanted to clear the history of the user's theme preference, you could use the `themeLocalStorageKey` like so: | ||
|
||
```svelte | ||
<script lang="ts"> | ||
import { themeLocalStorageKey } from "mode-watcher"; | ||
function clearThemeFromLocalStorage() { | ||
localStorage.removeItem(themeLocalStorageKey); | ||
} | ||
</script> | ||
<p>Clear the user's mode preference history.</p> | ||
<button on:click={clearModeFromLocalStorage}>Clear</button> | ||
``` |
Oops, something went wrong.