A two-state button that can be either on or off.
Installation
Install the packages
Add the shadcn-vue component
Animate it
The CLI finds your shadcn-vue components through components.json, swaps their primitive imports for Animate UI's and removes the CSS animation classes Motion replaces.
Usage
<script setup lang="ts">
import { Toggle } from '@animate-ui/vue/primitives/reka-ui';
</script>
<template>
<Toggle aria-label="Toggle bold">B</Toggle>
</template>Animation
The motion of Animate UI's React toggle:
- Toggle scales to 0.97 while pressed, on Motion's default spring for scale (stiffness 550, damping 30). No hover scale.
- The press scale runs on the compositor (a
transform), so atransitionclass on the toggle doesn't tween its frames. - The on/off colours are the component's CSS (
data-[state=on]:bg-accentin shadcn-vue). - Toggling with Space changes the state at once.
- Under reduced motion, there is no press scale.
API Reference
Toggle takes exactly the props of reka-ui's Toggle, plus:
| Prop | Type | Default |
|---|---|---|
transition? | Transition | { type: 'spring', stiffness: 550, damping: 30, restSpeed: 10 } |
With as-child, it renders your element with reka-ui's behaviour, without the animation. AnimateUIProvider's tempo scales these transitions with everything else.