vael-ui v0.5.7

Actions

Layout

Button

A button for an action, with variants, sizes, icons and a loading state. Use it for any action, and add hold when a destructive one needs a press and hold to confirm.

Install

import { Button } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { Button } from 'vael-ui'
</script>

<template>
  <Button>Button</Button>
</template>

Props

NameTypeDefaultDescription
loadingboolean | "auto"falsetrue and false set the loading state directly. With 'auto', the button stays loading until every overlapping promise your @click handler returns settles.
disabledbooleanfalseDisables the button and blocks interaction.
variant'primary' | 'secondary' | 'outline' | 'ghost' | 'link' | 'text' | 'danger''primary'Visual style of the button.
size'sm' | 'md' | 'lg''md'Button size.
loader'overlay' | 'inline''overlay''overlay' centers the loader over the fading content; 'inline' slides a spinner in at the start.
loaderTypeLoaderSource'ring'The loading animation: a built-in name, or your own component. Unset, it follows the nearest ConfigProvider's loaderType.
iconbooleanfalseRenders a square icon-only button; pair it with an aria-label.
pillbooleanfalseGives the button a fully rounded pill shape.
blockbooleanfalseStretches the button to its container's full inline size.
type'button' | 'submit' | 'reset''button'Native type attribute; applied only when as is 'button'.
asstring'button'Root tag, such as as="a" for a link styled as a button.
badgePlacement'top-start' | 'top-end' | 'bottom-start' | 'bottom-end''top-end'Where the #badge slot sits. Setting it reserves the wrapper up front, so a v-if'd #badge keeps a stable DOM position.
valuestring | numberIn a ButtonGroup with a v-model, what this button turns on and off. Still the native value attribute, for a submit button in a form. Style the on state with [aria-pressed='true'], or Tailwind's aria-pressed:.
holdnumber | booleanfalseActs only after a press and hold, for a destructive action: a fill sweeps across while you hold, and @click fires when it completes. Letting go early cancels. true holds for 1200ms; a number sets the milliseconds. Space and Enter hold too.
uiPartial<Record<'root' | 'leading' | 'trailing' | 'content' | 'label' | 'badge', UiPartValue>>Class and style overrides for each part.
motionButtonMotionAnimates its states, like a label that sinks while pressed: { states: { active: { label: { scale: '0.94' } } } }.
pressedbooleanOpt-in standalone toggle: v-model:pressed turns it on and off and sets aria-pressed. Style the on state with [aria-pressed='true'], or Tailwind's aria-pressed:.

Events

NameTypeDescription
update:pressed(value: boolean | undefined)Fires when pressed changes (v-model:pressed).

Slots

NameTypeDescription
default{ loading: boolean; el: HTMLElement | null; run: <T>(fn: () => T | Promise<T>) => Promise<T>; holdProgress: number; }Button label; receives the loading state, the root element, run and, with hold, how far the hold has got.
loader{ loading: boolean; el: HTMLElement | null; }Custom loader visuals; the library still handles placement and the crossfade.
leadinganyIcon before the label, in an optically aligned 1em box.
trailinganyIcon after the label, in an optically aligned 1em box.
badgeanyBadge content, placed in a wrapper the library positions.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element (the button itself, even when a badge wrapper is rendered).
loadingbooleanWhether the button is loading, from the loading prop or 'auto' tracking.
run<T>(fn: () => T | Promise<T>) => Promise<T>Runs fn with the loading state shown until it settles.
holdingbooleanWhether a hold press is in progress.
holdProgressnumberWith hold: 0 at rest, rising to 1 as the hold completes.

Motion New

active is pressed (pointer, Space or Enter); hover responds to a mouse only.

<Button
  :motion="{ states: { active: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootleadingtrailingcontentlabelbadgeSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statesactivehoverfocusloadingdisabledSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Button pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
EnterSpaceRuns the action.
  • A native <button> by default. With as set to a plain tag, such as div or an a without href, it gets role="button", a Tab stop, and Enter and Space. A link with an href stays a link.
  • loading sets aria-busy and aria-disabled but not disabled, so the button keeps focus. Clicks are ignored while it loads.
  • An icon button has no visible text: give it an aria-label. v-model:pressed sets aria-pressed, and the loader and the #leading and #trailing slots are aria-hidden.
  • With hold, holding Enter or Space fills the button and runs the action when the fill completes. Letting go early cancels. A hidden “Press and hold to confirm” hint is linked through aria-describedby.