🔥 Meet Our New Project: t0ggles - Your Ultimate Project Management Tool! 🔥

Toggle Svelte Component

Toggle Components

There are following components included:

  • Toggle

Toggle Props

NameTypeDefaultDescription
checkedbooleanfalse

Defines whether the toggle input is checked or not

colorsobject

Object with Tailwind CSS colors classes

colors.bgIosstring'bg-black bg-opacity-10 dark:bg-white dark:bg-opacity-20'
colors.bgMaterialstring'bg-md-light-surface-variant dark:bg-md-dark-surface-variant'
colors.borderMaterialstring'border-md-light-outline dark:border-md-dark-outline'
colors.checkedBgIosstring'bg-primary'
colors.checkedBgMaterialstring'bg-md-light-primary dark:bg-md-dark-primary'
colors.checkedBorderMaterialstring'border-md-light-primary dark:border-md-dark-primary'
colors.checkedThumbBgIosstring'bg-white'
colors.checkedThumbBgMaterialstring'bg-md-light-on-primary dark:bg-md-dark-on-primary'
colors.thumbBgIosstring'bg-white'
colors.thumbBgMaterialstring'bg-md-light-outline dark:bg-md-dark-outline'
disabledbooleanfalse

Defines whether the toggle input is disabled or not

namestring

Toggle input name

readonlybooleanfalse

Defines whether the toggle input is readonly or not

touchRipplebooleantrue

Enables touch ripple effect in Material theme

valueany

Toggle input value

onChangefunction(e)

Toggle input change event handler

Examples

Toggle.svelte
<script>
import {
Page,
Navbar,
NavbarBackLink,
List,
ListItem,
Toggle,
} from 'konsta/svelte';
let checked1 = true;
let checked2 = true;
let checked3 = true;
let checked4 = true;
</script>
<Page>
<Navbar title="Toggle" />
<List strong inset>
<ListItem label title="Item 1">
<Toggle
slot="after"
component="div"
class="-my-1"
checked={checked1}
onChange={() => (checked1 = !checked1)}
/>
</ListItem>
<ListItem label title="Item 2">
<Toggle
slot="after"
component="div"
class="-my-1 k-color-brand-red"
checked={checked2}
onChange={() => (checked2 = !checked2)}
/>
</ListItem>
<ListItem label title="Item 3">
<Toggle
slot="after"
component="div"
class="-my-1 k-color-brand-green"
checked={checked3}
onChange={() => (checked3 = !checked3)}
/>
</ListItem>
<ListItem label title="Item 4">
<Toggle
slot="after"
component="div"
class="-my-1 k-color-brand-yellow"
checked={checked4}
onChange={() => (checked4 = !checked4)}
/>
</ListItem>
</List>
</Page>
Code licensed under MIT.
2022 © Konsta UI by nolimits4web.