There are following components included:
Toggle
Name | Type | Default | Description |
---|---|---|---|
checked | boolean | false | Defines whether the toggle input is checked or not |
colors | object | Object with Tailwind CSS colors classes | |
colors.bgIos | string | 'bg-black bg-opacity-10 dark:bg-white dark:bg-opacity-20' | |
colors.bgMaterial | string | 'bg-md-light-surface-variant dark:bg-md-dark-surface-variant' | |
colors.borderMaterial | string | 'border-md-light-outline dark:border-md-dark-outline' | |
colors.checkedBgIos | string | 'bg-primary' | |
colors.checkedBgMaterial | string | 'bg-md-light-primary dark:bg-md-dark-primary' | |
colors.checkedBorderMaterial | string | 'border-md-light-primary dark:border-md-dark-primary' | |
colors.checkedThumbBgIos | string | 'bg-white' | |
colors.checkedThumbBgMaterial | string | 'bg-md-light-on-primary dark:bg-md-dark-on-primary' | |
colors.thumbBgIos | string | 'bg-white' | |
colors.thumbBgMaterial | string | 'bg-md-light-outline dark:bg-md-dark-outline' | |
component | string | 'label' | Component's HTML Element |
defaultChecked | boolean | false | Defines whether the toggle input is checked or not, for the case if it is uncontrolled component |
disabled | boolean | false | Defines whether the toggle input is disabled or not |
name | string | Toggle input name | |
readOnly | boolean | false | Defines whether the toggle input is readonly or not |
touchRipple | boolean | true | Enables touch ripple effect in Material theme |
value | any | Toggle input value | |
onChange | function(e) | Toggle input |
import React, { useState } from 'react';import {Page,Navbar,NavbarBackLink,List,ListItem,Toggle,} from 'konsta/react';export default function TogglePage() {const [checked1, setChecked1] = useState(true);const [checked2, setChecked2] = useState(true);const [checked3, setChecked3] = useState(true);const [checked4, setChecked4] = useState(true);return (<Page><Navbartitle="Toggle"/><List strong inset><ListItemlabeltitle="Item 1"after={<Togglecomponent="div"className="-my-1"checked={checked1}onChange={() => setChecked1(!checked1)}/>}/><ListItemlabeltitle="Item 2"after={<Togglecomponent="div"className="-my-1 k-color-brand-red"checked={checked2}onChange={() => setChecked2(!checked2)}/>}/><ListItemlabeltitle="Item 3"after={<Togglecomponent="div"className="-my-1 k-color-brand-green"checked={checked3}onChange={() => setChecked3(!checked3)}/>}/><ListItemlabeltitle="Item 4"after={<Togglecomponent="div"className="-my-1 k-color-brand-yellow"checked={checked4}onChange={() => setChecked4(!checked4)}/>}/></List></Page>);}