Switch
The Switch component is used as an alternative for the checkbox. The option that the switch controls, as well as the state it's in, should be made clear from the corresponding inline label.
Examples
Switch
Code
vue
<script setup lang="ts">
import { ref } from 'vue'
import { BaseSwitch } from '@point-hub/papp'
const form = ref({
checked: false
})
</script>
<template>
<form @submit.prevent="">
<component :is="BaseSwitch" v-model="form.checked" />
</form>
</template>
Text
Code
vue
<script setup lang="ts">
import { ref } from 'vue'
import { BaseSwitch } from '@point-hub/papp'
const form = ref({
checked: false
})
</script>
<template>
<form @submit.prevent="">
<component :is="BaseSwitch" v-model="form.checked" text="Label" />
<component :is="BaseSwitch" v-model="form.checked" text="Label" text-position="right" />
</form>
</template>
Label
Code
vue
<script setup lang="ts">
import { ref } from 'vue'
import { BaseSwitch } from '@point-hub/papp'
const form = ref({
checked1: false,
checked2: false
})
</script>
<template>
<form @submit.prevent="">
<component
:is="BaseSwitch"
v-model="form.checked1"
label="Label"
layout="vertical"
description="Vertical Layout"
/>
<component
:is="BaseSwitch"
v-model="form.checked2"
label="Label"
layout="horizontal"
description="Horizontal Layout"
/>
</form>
</template>
Size
Code
vue
<script setup lang="ts">
import { ref } from 'vue'
import { BaseSwitch } from '@point-hub/papp'
const form = ref({
checked1: false,
checked2: false,
checked3: false,
checked4: false
})
</script>
<template>
<form @submit.prevent="">
<component :is="BaseSwitch" v-model="form.checked1" label="sm" size="sm" />
<component :is="BaseSwitch" v-model="form.checked2" label="md" size="md" />
<component :is="BaseSwitch" v-model="form.checked3" label="lg" size="lg" />
<component :is="BaseSwitch" v-model="form.checked4" label="xl" size="xl" />
</form>
</template>
Helper
Code
vue
<script setup lang="ts">
import { ref } from 'vue'
import { BaseSwitch } from '@point-hub/papp'
const form = ref({
checked1: false,
checked2: false,
checked3: false,
checked4: false,
checked5: false
})
const errors = ref(['Error Example'])
</script>
<template>
<form @submit.prevent="">
<component
:is="BaseSwitch"
v-model="form.checked1"
label="Label"
layout="horizontal"
required
/>
<component
:is="BaseSwitch"
v-model="form.checked2"
label="Label"
layout="horizontal"
description="Description example"
/>
<component
:is="BaseSwitch"
v-model="form.checked3"
label="Label"
layout="horizontal"
:helpers="['Description example']"
/>
<component
:is="BaseSwitch"
v-model="form.checked4"
label="Label"
layout="horizontal"
v-model:errors="errors"
/>
<component
:is="BaseSwitch"
v-model="form.checked5"
label="Label"
layout="horizontal"
description="Disabled"
disabled
/>
</form>
</template>
Disabled
Code
vue
<script setup lang="ts">
import { ref } from 'vue'
import { BaseSwitch } from '@point-hub/papp'
const form = ref({
checked1: true,
checked2: false
})
</script>
<template>
<form @submit.prevent="">
<component :is="BaseSwitch" v-model="form.checked1" disabled />
<component :is="BaseSwitch" v-model="form.checked2" disabled />
</form>
</template>
Switch API
Types
ts
export type BaseSwitchTextPosition = 'left' | 'right'
export type BaseSwitchSize = 'sm' | 'md' | 'lg' | 'xl'
Props
Name | Type | Default | Description |
---|---|---|---|
v-model | boolean | v-model is required . | |
v-model:errors | string[] | Input error message. | |
label | string | Switch label. | |
text | string | Switch text. | |
text-position | BaseSwitchTextPosition | left | Switch text position. |
size | BaseSwitchSize | md | Switch size. |
disabled | boolean | false | if true switch is disabled . |