Skip to content
On this page

Switch

Switch is used for switching between two opposing states.

Basic Usage

The inputs have themes: default, transparent.

Label
Label
<template>
  <div class="flex flex-col">
    <HcSwitch
      v-model="value1"
      label="Label"
    />

    <HcSwitch
      v-model="value2"
      label="Label"
      class="mt-5"
      label-position="right"
    />
  </div>
</template>

<script lang="ts" setup>
import { HcSwitch } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';

const value1 = ref(true);
const value2 = ref(true);
</script>

Disabled & readonly

Change the state of the component to disabled with the disabled property, the property is a boolean so you can add it without any value.

Change the state of the component to readonly with the readonly property.

Label
Label
<template>
  <div class="flex flex-col">
    <HcSwitch
      v-model="value1"
      label="Label"
      disabled
    />

    <HcSwitch
      v-model="value2"
      label="Label"
      class="mt-5"
      readonly
    />
  </div>
</template>

<script lang="ts" setup>
import { HcSwitch } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';

const value1 = ref(true);
const value2 = ref(true);
</script>

Errors

Use props errorMsg to show error message and error state of the component

Label
This field is required
<template>
  <div class="flex flex-col">
    <HcSwitch
      v-model="value1"
      label="Label"
      class="mt-5"
      :error-msg="!value1 ? 'This field is required' : ''"
    />
  </div>
</template>

<script lang="ts" setup>
import { HcSwitch } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';

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

Props

PropertyType Values Description Default
modelValueBooleanBooleanbinding valuefalse
labelStringStringlabel text
disabledBooleanBooleanwhether component is disabledfalse
readonlyBooleanBooleanwhether component is read onlyfalse
errorMsgStringStringerror message
labelPositionStringStringleft,rightleft

Slots

PropertyType Values Description Default
label-Customize label content

Events

PropertyType Values Description Default
update:model-valueFunctionvalue - booleantriggers when value changes
changeFunctionvalue - booleantriggers when value changes

Created by DeepVision Software.