Editor formatting
Represent an on/off command such as bold with a pressed button.
Components / Actions
A native two-state button with pressed semantics.
Last changed in version 0.13.0: Add avatar groups and chips, expand the block gallery, and improve component colors, spacing, and motion.
bunx --bun @getweini/cli@latest add toggleImport the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.
<script setup lang="ts">
import { ref } from 'vue'
import Toggle from './components/ui/toggle/Toggle.vue'
const bold = ref(false)
</script>
<template>
<Toggle v-model="bold" variant="outline" aria-label="Bold">B</Toggle>
</template>The native button exposes aria-pressed and data-state. Give it visible text or an ARIA name; disabled toggles cannot update the model and leave the tab order.
Represent an on/off command such as bold with a pressed button.
Bind a boolean preference and reflect its current value.
The button communicates the state with aria-pressed.
<script setup lang="ts">
import { ref } from 'vue'
import Toggle from './components/ui/toggle/Toggle.vue'
const bold = ref(false)
</script>
<template>
<Toggle v-model="bold" aria-label="Bold" variant="outline"><strong>B</strong></Toggle>
</template>A text label can provide the accessible name directly.
<script setup lang="ts">
import { ref } from 'vue'
import Toggle from './components/ui/toggle/Toggle.vue'
const showGrid = ref(true)
</script>
<template>
<Toggle v-model="showGrid">Grid lines</Toggle>
</template>Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
variantprop | "default" | "outline" | undefined | "default" | Choose the visual treatment for this component. |
sizeprop | "sm" | "md" | "lg" | undefined | "md" | Choose the visual size. Medium is the usual default where available. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
typeprop | "button" | "submit" | "reset" | undefined | "button" | Choose the native HTML control type or action behavior. |
modelValuemodel | boolean | undefined | false | Current value. Use v-model to keep it in sync with your page. |
update:modelValueevent | [value: boolean] | — | Requests a new model value from the parent. |
defaultslot | (props: { pressed: boolean; }) => unknown | Required | Content shown inside Toggle. |
elementexposed | HTMLButtonElement | null | — | Reference to the underlying HTML element. |
focusexposed | () => void | undefined | — | Move keyboard focus to this control. |
// packages/frameworks/vue/components/toggle/types.ts
// ------- IMPORTS -------
import type { toggleSizes, toggleVariants } from './styles'
// ------- TYPES -------
export interface ToggleProps {
variant?: keyof typeof toggleVariants
size?: keyof typeof toggleSizes
disabled?: boolean
type?: 'button' | 'submit' | 'reset'
}
// packages/frameworks/vue/components/toggle/styles.ts
// Edit toggle variants and sizes here; public visual prop types follow these keys.
export const toggleVariants = {
default: 'border border-transparent text-foreground hover:bg-secondary',
outline:
'border border-control-border bg-clip-padding bg-control text-foreground hover:bg-secondary',
} as const
export const toggleSizes = {
sm: 'h-8 px-3 text-xs',
md: 'h-10 px-4 text-sm',
lg: 'h-12 px-6 text-base',
} as const