Formulários

VSwitch

Componentev-model8 exemplos10 propsA2UI · Switch

Toggle binário on/off para configurações e preferências, com thumb animado e suporte a label/descrição.

Importação
<script setup lang="ts">
import { VSwitch } from 'vueui-nova-kit'
</script>

Uso

Exemplo
<script setup lang="ts">

</script>

<template>
  
</template>

Playground

Os controles abaixo são gerados a partir das props declaradas em VSwitch.types.ts; o código acompanha cada mudança.

Exemplos

Variantes, tamanhos e estados, extraídos das stories da biblioteca.

Default

Variação Padrão. Estado padrão do componente; use a aba Controls para experimentar as props ao vivo.

Ver código
vue
<script setup lang="ts">
import { VSwitch } from 'vueui-nova-kit'
</script>

<template>
  <VSwitch v-model="value" />
</template>

On

Variação Em. Props: modelValue=true.

Ver código
vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vueui-nova-kit'

const value = ref(true)
</script>

<template>
  <VSwitch v-model="value" />
</template>

Labeled

Variação Labeled. Props: modelValue=true, label="Enable notifications", description="Get product updates and tip…".

Ver código
vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vueui-nova-kit'

const value = ref(true)
</script>

<template>
  <VSwitch
    v-model="value"
    label="Enable notifications"
    description="Get product updates and tips." />
</template>

Settings Row

Variação Settings Row. Props: modelValue=true, label="Dark mode", description="A more comfortable viewing …", showIcon=true.

Ver código
vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vueui-nova-kit'

const value = ref(true)
</script>

<template>
  <VSwitch
    v-model="value"
    label="Dark mode"
    description="A more comfortable viewing experience."
    show-icon />
</template>

Disabled

Variação Desabilitado. Props: modelValue=true, disabled=true, label="Disabled switch", description="Cannot be changed.".

Ver código
vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vueui-nova-kit'

const value = ref(true)
</script>

<template>
  <VSwitch
    v-model="value"
    disabled
    label="Disabled switch"
    description="Cannot be changed." />
</template>

Sizes

Variação Tamanhos. Interativo: o estado é mantido na própria story (v-model).

Ver código
vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vueui-nova-kit'

const sm = ref(true)
const md = ref(false)
const lg = ref(true)
</script>

<template>
  <div style="display:flex;flex-direction:column;gap:16px;max-width:420px">
    <VSwitch v-model="sm" size="sm" label="Small switch" />
    <VSwitch v-model="md" size="md" label="Medium switch" />
    <VSwitch v-model="lg" size="lg" label="Large switch" />
  </div>
</template>

States

Variação Estados. Interativo: o estado é mantido na própria story (v-model).

Ver código
vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vueui-nova-kit'

const off = ref(false)
const on = ref(true)
</script>

<template>
  <div style="display:flex;gap:24px;align-items:center;flex-wrap:wrap">
    <VSwitch v-model="off" aria-label="Switch off" />
    <VSwitch v-model="on" aria-label="Switch on" />
    <VSwitch :model-value="false" disabled aria-label="Disabled off" />
    <VSwitch :model-value="true" disabled aria-label="Disabled on" />
  </div>
</template>

Interactive

Variação Interativo. Estado mantido via v-model (ref no setup), com ícone de tema.

Ver código
vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vueui-nova-kit'

const dark = ref(false)
</script>

<template>
  <VSwitch v-model="dark" label="Dark mode" description="A more comfortable viewing experience." showIcon />
</template>

Acessibilidade

role="switch", Space/Enter para alternar, label visível, foco com anel de 2px, opacidade no disabled, área mínima 44×24px.

Estados

Off · Hover Off · Focus Off · On · Hover On · Focus On · Pressed · Disabled Off · Disabled On.

Motion

TriggerPropertyDurationEasing
Toggletransform/background160msstandard
Hoverbox-shadow/tint100msease-out
Focus ringbox-shadow120msease-out
Pressedthumb scale70msease-in

Respeitar prefers-reduced-motion.

Todas as transições respeitam prefers-reduced-motion e os tokens --v-duration-*.

Props

PropTipoDefaultDescrição
modelValuebooleanfalse—
labelstring——
descriptionstring——
disabledbooleanfalse—
sizeVSwitchSize"md"—
namestring——
idstring——
showIconbooleanfalse—
ariaLabelstring——
motionVMotionLevelV_MOTION_DEFAULT ("expressive")—

Events

EventoPayloadDescrição
@update:modelValuevalue: boolean—
@changevalue: boolean—

Slots

SlotProps do slot
#label—

Fonte: src/components/form/VSwitch/VSwitch.vue · tipos: src/components/form/VSwitch/VSwitch.types.ts