Used with a component · Dock
useDock
The magnification engine behind <Dock>. Items near the pointer grow along a smooth cosine falloff, and their neighbors spread apart to make room. It writes transform, or the real size in grow mode, straight onto each item every animation frame, so the effect costs no re-renders. A mouse magnifies on hover. A finger or pen magnifies once it slides 8 px along the dock, so a tap stays a tap. It stays at rest under prefers-reduced-motion: reduce. <Dock> adds the buttons, tooltips, roving keyboard focus and the tap bounce.
Install
import { useDock } from 'vael-ui'Examples
<script setup lang="ts">
import { useTemplateRef } from 'vue'
import { useDock } from 'vael-ui'
const apps = ['Mail', 'Notes', 'Music', 'Photos']
const rootEl = useTemplateRef<HTMLElement>('root')
const { setItemEl, onPointerDown, onPointerMove, onPointerLeave } = useDock(
rootEl,
() => apps.length,
{ baseSize: 48, maxSize: 72 },
)
</script>
<template>
<div
ref="root"
class="my-dock"
@pointerdown="onPointerDown"
@pointermove="onPointerMove"
@pointerleave="onPointerLeave"
@pointerup="onPointerLeave"
@pointercancel="onPointerLeave"
>
<button v-for="(app, i) in apps" :key="app" :ref="setItemEl(i)" class="my-dock-item">
{{ app }}
</button>
</div>
</template>
<style>
/* touch-action: none lets a finger slide along the dock without scrolling the page. */
.my-dock { display: flex; gap: 8px; touch-action: none; }
.my-dock-item { inline-size: 48px; block-size: 48px; }
</style>