svelte-dark-mode
svelte-dark-mode copied to clipboard
Provide function to programmatically toggle theme
It would be nice to have a function (provided through the let:
directive or as an accessor) to programmatically update the theme. This way, the consumer wouldn't need to maintain the theme
prop by themselves.
let:
directive
<DarkMode let:theme let:toggleTheme>
<button on:click={toggleTheme}>Toggle</button>
Current theme: {theme}
</DarkMode>
Accessor
<script>
let darkMode;
let theme;
</script>
<DarkMode bind:this={darkMode} bind:theme />
<button on:click={darkMode?.toggleTheme}>Toggle</button>
Current theme: {theme}