Skip to content

Switch

A switch component that toggles between two states. It supports both iOS (default) and Material Design styles.

Usage

iOS Style (Default)
Value: true
Red Color
Material Style
Value: false
vue
<template>
  <Column :gap="32">
    <!-- iOS Style (Default) -->
    <Column :gap="10">
      <Text :style="{ fontWeight: FontWeight.bold }">iOS Style (Default)</Text>
      <Row :gap="20" cross-axis-alignment="center">
        <Switch v-model:value="iosVal" />
        <Text>Value: {{ iosVal }}</Text>
      </Row>
      <Row :gap="20" cross-axis-alignment="center">
        <Switch v-model:value="iosVal2" active-color="#FF3B30" />
        <Text>Red Color</Text>
      </Row>
    </Column>

    <!-- Material Style -->
    <Column :gap="10">
      <Text :style="{ fontWeight: FontWeight.bold }">Material Style</Text>
      <Row :gap="20" cross-axis-alignment="center">
        <Switch v-model:value="materialVal" variant="material" />
        <Text>Value: {{ materialVal }}</Text>
      </Row>
    </Column>
  </Column>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { Column, Row, Text, Switch, FontWeight } from "fluekit";

const iosVal = ref(true);
const iosVal2 = ref(true);
const materialVal = ref(false);
</script>

API

Props

NameTypeDefaultDescription
valueboolean-Whether this switch is on or off.
variant'material' | 'ios''ios'The style variant of the switch.
activeColorstring#34C759 (iOS) / #2196F3 (Mat)The color to use when this switch is on.
activeTrackColorstring-The color to use on the track when this switch is on.
inactiveThumbColorstring-The color to use on the thumb when this switch is off.
inactiveTrackColorstring-The color to use on the track when this switch is off.

Events

NameDescription
update:valueEmitted when the value changes.
changeEmitted when the user toggles the switch.