Sprout UI home page

Toggle

A toggle is a two-state button component that can be turned on or off.

Setup

To use the toggle component, you’ll have to import Toggle module in your assets/app.js.

import { createSproutConfig, Toggle } from "sprout-ui";

const { initComponents, handleDomChange } = createSproutConfig({
  components: [Toggle()],
});

Anatomy

<button is="sp-toggle" data-state="on | off"></button>

Under the hood the slot content is rendered inside a sp-toggle customized builtin element.

Attributes

Attribute Type Description
on :boolean Turn on the toggle by default, default to false
on_toggle_on JS JS commands executed when the toggle is turned on
on_toggle_off JS JS commands executed when the toggle is turned off
rest :global Global attributes to be passed to the sp-toggle element