Skip to content

Switch API Reference

Props

PropTypeDefaultDescription
modelValueBoolean-v-model binding value
valueBoolean-Alternative to modelValue
disabledBooleanfalseDisables the switch
readonlyBooleanfalseMakes the switch read-only
variantString'default'Visual variant class (e.g. 'default', 'success')
sizeString'xl'Size of the switch. Options: 'xs', 'sm', 'md', 'lg', 'xl'
labelString''Label text for the switch
labelPositionString'right'Position of the label. Options: 'left', 'right'
insetBooleanfalseInset style for the switch
dotLabelsObjectnullLabels for the switch dots when active and inactive. Format: { true: 'On', false: 'Off' }

Events

EventPayloadDescription
update:modelValueBooleanEmitted when switch state changes
changeBooleanEmitted when switch state changes

Slots

SlotDescription
left-labelCustom content for the left label
right-labelCustom content for the right label

Methods

The component doesn't expose any methods via template refs.

Example Usage

Basic Usage

vue
<template>
  <OSwitch
    v-model="isEnabled"
    label="Enable Feature"
    variant="default"
  />
</template>

<script setup>
import { ref } from "vue";
import { OSwitch } from "your-component-library";

const isEnabled = ref(false);
</script>

With Variants

vue
<template>
  <div class="switch-group">
    <OSwitch
      v-model="isEnabled1"
      label="Default Variant"
      variant="default"
    />
    <OSwitch
      v-model="isEnabled2"
      label="Success Variant"
      variant="success"
    />
  </div>
</template>

<script setup>
import { ref } from "vue";
import { OSwitch } from "your-component-library";

const isEnabled1 = ref(false);
const isEnabled2 = ref(false);
</script>

Different Sizes

vue
<template>
  <div class="switch-group">
    <OSwitch v-model="isEnabled" label="Extra Small" size="xs" />
    <OSwitch v-model="isEnabled" label="Small" size="sm" />
    <OSwitch v-model="isEnabled" label="Medium" size="md" />
    <OSwitch v-model="isEnabled" label="Large" size="lg" />
    <OSwitch v-model="isEnabled" label="Extra Large" size="xl" />
  </div>
</template>

<script setup>
import { ref } from "vue";
import { OSwitch } from "your-component-library";

const isEnabled = ref(false);
</script>

With Left Label

vue
<template>
  <OSwitch v-model="isEnabled" label="Notifications" label-position="left" />
</template>

<script setup>
import { ref } from "vue";
import { OSwitch } from "your-component-library";

const isEnabled = ref(false);
</script>