Skip to content

Provide function to programmatically toggle theme #11

@metonym

Description

@metonym

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions