Skip to content

Switch

Basic Usage

isOn.value === false
skulls.value === []
vue
<script setup>
import { Switch } from '@8ctavio/vergil/components'
import { useModel } from '@8ctavio/vergil'
const isOn = useModel(false)
const skulls = useModel([])
</script>

<template>
    <!-- Single boolean value -->
    <Switch v-model="isOn" label="Switch"/>

    <!-- Multiple values -->
    <Switch v-model="skulls" value="iron" label="Iron"/>
    <Switch v-model="skulls" value="blind" label="Blind"/>
    <Switch v-model="skulls" value="iwhbyd" label="IWHBYD "/>
</template>

Attributes

Value

In order to bind multiple switches to a component model, all switches must include the value attribute and the model's value must be an array. The model's array value includes the value of selected switches. Were the model's value not an array, value has no effect.

TIP

The checked prop may be used to provide an initial value without a model.

Props

On-state value
value[-on]: (boolean | string) = true

The value-on prop is the value assigned to the Switch's model value when it gets checked, and the value of the underlying input[type="checkbox"] element's value attribute.

Off-state value
value-off: (boolean | string) = false

The value-off prop is the value assigned to the Switch's model value when it gets unchecked. If value-on is a string, value-off defaults to an empty string ('').

Track
track: ("on" | "off")

vue
<Switch track="off"/>
<Switch track="on"/>

Labels
label-on: string
label-off: string
MiniMarkup

vue
<Switch label-on="On" label-off="Off"/>

Highlight labels
highlight: boolean

vue
<Switch highlight track="on" label-on="Yearly" label-off="Monthly"/>

Icons
icon-on: string
icon-off: string

vue
<Switch icon-off="light_mode" icon-on="dark_mode" track="on"/>

Theme
theme: theme = 'brand'

Size
size: ('xs' | 'sm' | 'md' | 'lg' | 'xl') = 'md'

Radius
radius: ('none' | 'sm' | 'md' | 'lg' | 'full') = 'full'

Spacing
spacing: ('compact' | 'expanded') = ''

Disabled
disabled: boolean

Elements

elementtagdescription
input<input[type="checkbox"]>Switch's underlying input element.

Anatomy

<div.form-field.switch/>

<div.form-field-label-wrapper/>

<label.form-field-label/>

<span.form-field-hint/>

<p.form-field-details.form-field-description/>

<div.switch-button/>

<input[type="checkbox"]/>

<label.switch-label-off/>

<span.switch-track/>

<span.switch-knob/>

<Icon.icon.switch-icon-off/>

<Icon.icon.switch-icon-on/>

<label.switch-label-on/>

<p.form-field-details.form-field-help/>

API Reference

Props

proptypedefault
checkedboolean
valueboolean | stringundefined
value-onboolean | stringtrue
value-offboolean | stringfalse
track'on' | 'off'
label-onstring
label-offstring
highlightboolean
icon-onstring
icon-offstring
disabledboolean
labelstring
hintstring
descriptionstring
helpstring
showErrrosboolean
descendantboolean
theme'brand' | 'user' | 'ok' | 'info' | 'warn' | 'danger' | 'neutral''brand'
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'
radius'none' | 'sm' | 'md' | 'lg' | 'full''full'
spacing'' | 'compact' | 'extended'''
validatorFunction
eagerValidationboolean
elementsobject

Configuration options

Switch's configuration options allow to overwrite some Switch props' default values and may be overwritten under the switch root-level configuration option.

switch.<option>typedefaultglobal
themetheme
sizesize
radiusradius'full'
spacingspacing