svelte-dark-mode icon indicating copy to clipboard operation
svelte-dark-mode copied to clipboard

Provide function to programmatically toggle theme

Open metonym opened this issue 2 years ago • 0 comments

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}

metonym avatar Jun 19 '22 19:06 metonym