vael-ui v0.5.7

Gestures

Layout

Dock

A macOS-style row of icons that magnify as the pointer or a finger moves over them. Use it for app-style navigation or a launcher.

Install

import { Dock } from 'vael-ui'

Playground

Usage
<script setup lang="ts">
import { Dock } from 'vael-ui'
import { PhHouse, PhChatCircle, PhStar } from '@phosphor-icons/vue'

const items = [
  { label: 'Home', icon: PhHouse, style: { color: '#2563eb' } },
  { label: 'Messages', icon: PhChatCircle, style: { color: '#16a34a' } },
  { label: 'Favorites', icon: PhStar, style: { color: '#d97706' } },
]
</script>

<template>
  <Dock :range="168" :items="items" />
</template>

Props

NameTypeDefaultDescription
itemsRequiredDockItemData[]Items to show, one button each.
orientation'horizontal' | 'vertical''horizontal'Lays items out in a row or a column; arrow keys follow the same axis.
baseSizenumber48Resting icon size, in pixels.
maxSizenumber76Icon size, in pixels, directly under the pointer.
rangenumberFalloff distance in pixels. Unset, it's 3.5 times baseSize.
disabledbooleanfalseDims the dock and blocks pointer interaction and magnification.
magnifybooleantruefalse turns off magnification but keeps items interactive, unlike disabled.
growbooleanfalseMagnifies by resizing items, so the dock grows with them. Off, items scale and spread with transforms and the dock keeps its size.
tooltipsbooleantrueRenders each item's v-tooltip on hover.
tooltipSide'top' | 'right' | 'bottom' | 'left'Which side each item's tooltip opens on. Unset, it's 'top' when horizontal and 'right' when vertical.
uiPartial<Record<'root' | 'item', UiPartValue>>Class and style overrides for each part.
motionDockMotionHow it moves: its appearance, item by item ({ initial: { item: { opacity: 0, y: 8 } }, stagger: 0.04 }), and the spring magnification follows the pointer on ({ spring: 'bouncy' }). false turns its own animation off.

Events

NameTypeDescription
select(item: DockItemData, index: number)Fires when you click an item, or press Enter or Space on a focused item.

Slots

No slots.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
itemEls() => HTMLButtonElement[]The item buttons, in order, to animate yourself (with :magnify="false" to turn the built-in magnification off).
remeasure() => voidRe-measures item positions for magnification, after a layout change the dock can't detect.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Dock: its appearance, item by item, and each item's states: hover, active (pressed), focus, and selected, which plays each time the item is picked (a launch hop). Its spring is the one magnification follows the pointer on, overshoot included.

<Dock
  :motion="{ states: { hover: { item: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootitemSets 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.
stateshoveractivefocusdisabledselectedSets 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 Toolbar pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowLeftArrowRightMoves focus to the previous or next item, wrapping at the ends, when horizontal.
ArrowUpArrowDownMoves focus to the previous or next item, wrapping at the ends, when vertical.
HomeEndMoves focus to the first or last enabled item.
EnterSpaceSelects the focused item.
  • The root has role="toolbar", plus aria-orientation="vertical" when vertical. Give it an aria-label.
  • The items are one Tab stop with a roving tabindex, which falls to the first enabled item when the active one is disabled. The arrow keys skip disabled items.
  • Each item is a <button> named by its label, plus its badge when set, such as “Inbox, 3”. The icon and the badge are aria-hidden.
  • Right to left, ArrowLeft and ArrowRight swap.