1.0.2 • Published 1 year ago

svelte-switcher v1.0.2

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Svelte Switcher

A fully accessible, mobile-friendly and customisable toggle component for svelte apps.

View examples and demo here

Installation

Install svelte-switcher with npm

  npm install svelte-switcher

Usage/Examples

Click here to view examples

<script>
    import Toggle from 'svelte-switcher'
</script>

<Toggle
    id="svelte-toggle"
    name="theme-toggle"
    defaultChecked={false}
    on:toggle={handleToggle}
    ...
/>

API

Props

PropsDescriptionDefault value
checkeddetermines if the toggle is activefalse
disableddetermines if the toggle is disabledfalse
onChangefires when toggle status changevoid
onFocusfires when toggle is focusedvoid
onBlurfires when toggle is unfocusedvoid
namename attr for the underlying input elementsvelte-switcher-name
valuevalue attr for the underlying input elementsvelte-switcher-value
idid attr for the underlying input elementsvelte-switcher-id
ariaLabelledByariaLabelledBy attr
ariaLabelariaLabel attr

Slots

Slot NameDescriptionDefault value
checked-componentSlot for checked state icon / component
unchecked-componentSlot for unchecked state icon / component

Events

Event NameDescriptionPayload
toggleFires when toggle status changesisChecked: boolean