Usage
Use the v-model directive to control the pressed state of the Toggle.
<script setup lang="ts">
const value = ref(true)
</script>
<template>
<PToggle v-model="value" icon="i-lucide-bold" aria-label="Toggle bold" />
</template><script setup lang="ts">
import { ref } from 'vue'
const value = ref(true)
</script>
<template>
<PToggle v-model="value" icon="i-lucide-bold" aria-label="Toggle bold" />
</template>Use the default-value prop to set the initial value when you do not need to control its state.
<template>
<PToggle default-value icon="i-lucide-bold" aria-label="Toggle bold" />
</template>label, icon, size, etc., except the link ones. It sets the active prop of the Button from its pressed state.Color
Use the color and active-color props to set the color of the Toggle when not pressed and when pressed. Defaults to neutral and primary.
<template>
<PToggle color="neutral" active-color="neutral" default-value label="Bold" />
</template>Variant
Use the variant and active-variant props to set the variant of the Toggle when not pressed and when pressed. Defaults to ghost and soft.
<template>
<PToggle variant="outline" active-variant="subtle" default-value label="Bold" />
</template>Disabled
Use the disabled prop to disable the Toggle.
<template>
<PToggle disabled label="Bold" />
</template>Examples
Style the pressed state
The Toggle renders data-state="on" when pressed, so you can style it with the data-[state=on] variant.
<template>
<PToggle label="Bold" class="data-[state=on]:ring data-[state=on]:ring-primary" />
</template>API
Props
| Prop | Default | Type |
|---|---|---|
as | 'button' | anyThe element or component this component should render as when not a link. |
id | string | |
color | 'neutral' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
variant | 'ghost' | "solid" | "outline" | "soft" | "subtle" | "ghost" | "link" |
activeColor | 'primary' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral"The color of the toggle when pressed. |
activeVariant | 'soft' | "solid" | "outline" | "soft" | "subtle" | "ghost" | "link"The variant of the toggle when pressed. |
autofocus | false | true | "true" | "false" | |
disabled | boolean | |
name | string | |
label | string | |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
square | boolean Render the button with equal padding on all sides. | |
block | boolean Render the button full width. | |
icon | anyDisplay an icon based on the | |
avatar | AvatarPropsDisplay an avatar on the left side. | |
leading | boolean When | |
leadingIcon | anyDisplay an icon on the left side. | |
trailing | boolean When | |
trailingIcon | anyDisplay an icon on the right side. | |
loading | boolean When | |
loadingIcon | appConfig.ui.icons.loading | anyThe icon when the |
defaultValue | boolean The pressed state of the toggle when it is initially rendered. Use when you do not need to control its open state. | |
modelValue | boolean | null The controlled pressed state of the toggle. Can be bind as | |
required | boolean When | |
ui | { base?: SlotClass; label?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailingIcon?: SlotClass; } |
Slots
| Slot | Type |
|---|---|
leading | { ui: object; } |
default | { ui: object; } |
trailing | { ui: object; } |
Emits
| Event | Type |
|---|---|
change | [event: Event] |
update:modelValue | [value: boolean] |