A trigger that can be toggled on and off.
Props
<script lang="ts"> import { Toggle } from "melt"; const toggle = new Toggle();</script> <button {...toggle.trigger}> {toggle.value ? "✅" : "❌"}</button>
<script lang="ts"> import { Toggle } from "melt/components";</script> <Toggle> {#snippet children(toggle)} <button {...toggle.trigger}> {toggle.value ? "✅" : "❌"} </button> {/snippet}</Toggle>
new Toggle()
export type ToggleProps = { /** * The value for the Toggle. * * When passing a getter, it will be used as source of truth, * meaning that the value only changes when the getter returns a new value. * * Otherwise, if passing a static value, it'll serve as the default value. * * * @default false */ value?: MaybeGetter<boolean>; /** * Called when the value is supposed to change. */ onValueChange?: (value: boolean) => void; /** * If `true`, prevents the user from interacting with the input. * * @default false */ disabled?: MaybeGetter<boolean | undefined>;};
boolean
{ readonly "data-melt-toggle-trigger": "" readonly "data-checked": "" | undefined readonly disabled: true | undefined readonly onclick: () => void}
{ readonly "data-melt-toggle-hidden-input": "" readonly type: "hidden" readonly value: "on" | "off"}