Skip to content

Switch

A simple vue switch.

Demo ​

Sizes

Variants

Colors

High Contrast

Disabled

Custom Color


Install ​

bash
npm i @vuesimple/vs-switch

Usage ​

html
<template>
  <vs-switch v-model="isEnabled" />
</template>

<script>
  import VsSwitch from '@vuesimple/vs-switch';

  export default {
    components: {
      VsSwitch,
    },
    data() {
      return {
        isEnabled: false,
      };
    },
  };
</script>

CDN ​

html
<script src="https://unpkg.com/@vuesimple/vs-switch@3.1.7/dist/index.min.js"></script>
javascript
// Main/Entry file
app.use(VsSwitch.plugin);
html
<template>
  <vs-switch v-model="isEnabled" />
</template>

Props ​

NameTypeDefaultDescription
modelValueBooleanfalseThe checked state (supports v-model)
sizeStringmediumSize of switch. (small, medium, large)
variantStringclassicVisual variant. (classic, surface, soft)
colorStringprimaryColor theme of the switch when checked
highContrastBooleanfalseHigh contrast mode for better visibility
radiusStringfullBorder radius. (none, small, medium, large, full)
disabledBooleanfalseDisable the switch
ariaLabelString-Aria label for accessibility
checkedBgColorString-Custom background color when checked (hex/rgb/text color)

Events ​

NameDescription
v-modelEmitted when the switch state changes
changeEmitted when the switch state changes (detail)

Slots ​

Currently, the switch component does not have slots. It renders as a simple toggle button.


Color Options ​

The switch supports various color themes when checked:

  • primary (default blue)
  • success (green)
  • danger (red)
  • warning (orange)
  • secondary (dark gray)
  • indigo
  • cyan
  • orange
  • crimson
  • gray

Examples ​

Basic Switch ​

html
<vs-switch v-model="isEnabled" />

Switch with Label ​

html
<label>
  <vs-switch v-model="isEnabled" />
  Enable notifications
</label>

Different Sizes ​

html
<vs-switch v-model="isEnabled" size="small" />
<vs-switch v-model="isEnabled" size="medium" />
<vs-switch v-model="isEnabled" size="large" />

Different Variants ​

html
<vs-switch v-model="isEnabled" variant="classic" />
<vs-switch v-model="isEnabled" variant="surface" />
<vs-switch v-model="isEnabled" variant="soft" />

Different Colors ​

html
<vs-switch v-model="isEnabled" color="primary" />
<vs-switch v-model="isEnabled" color="success" />
<vs-switch v-model="isEnabled" color="danger" />
<vs-switch v-model="isEnabled" color="indigo" />

Disabled State ​

html
<vs-switch v-model="isEnabled" disabled />

High Contrast ​

html
<vs-switch v-model="isEnabled" highContrast color="indigo" />

Custom Color for Checked State ​

html
<vs-switch v-model="isEnabled" checkedBgColor="#ff6b6b" />

Events Handling ​

html
<template>
  <vs-switch v-model="isEnabled" @change="handleChange" />
</template>

<script>
  export default {
    data() {
      return {
        isEnabled: false,
      };
    },
    methods: {
      handleChange(newValue) {
        console.log('Switch is now:', newValue);
      },
    },
  };
</script>


License ​

MIT