Components/IconMorph

IconMorph

A stroke icon that morphs into another icon with spring physics.

VerifiedSince 0.6.0

Usage

Basic

Changing icon springs the shape into the new icon.

Loading demo...

Controlled Progress

Pass from, to, and progress to drive the morph from a gesture, scroll position, or custom transition, without the spring.

<template>
  <TxIconMorph from="menu" to="close" :progress="dragProgress" :size="24" />
</template>

Best Practices

  • Use it for stateful buttons: play / pause, menu / close, search / clear, plus / check.
  • Use spring="snappy" for click feedback and spring="smooth" for larger UI transitions.
  • Stroke icons (Lucide, Tabler, Feather) morph best; crossfade filled glyphs instead.

API Reference

Props

PropTypeDefaultDescription
iconIconInput-Current icon when uncontrolled: a preset name ('menu', 'close', 'check', …), a path d, an IconNode, or <svg> markup.
fromIconInput-Start icon in controlled mode.
toIconInput-Target icon in controlled mode.
progressnumber-Controlled progress (0–1); setting it enters controlled mode and stops the spring.
spring'snappy' | 'smooth' | 'bouncy' | { stiffness?: number, damping?: number }'snappy'Spring for uncontrolled transitions.
sizenumber | string24Icon width and height in px.
strokeWidthnumber | string2Stroke width.
absoluteStrokeWidthbooleanfalseKeeps the stroke width constant as size changes, per the Lucide convention.
viewBoxstring'0 0 24 24'The root <svg> viewBox; the default matches the engine's 24-unit grid.
labelstring-Accessible name: renders role="img" and a <title>; without it the icon is aria-hidden="true".
colorstring'currentColor'Stroke color.
reducedMotion'never' | 'user' | 'always''never'Reduced-motion policy: user follows the OS setting, always jumps straight to the end.

Exposed Methods

NameTypeDescription
morphTo(icon: IconInput, spring?: SpringPreset | MorphOptions) => voidSprings to the icon; without spring, uses the spring prop.
set(icon: IconInput) => voidJumps to the icon without animating.
seek(icon: IconInput, t: number) => voidFreezes the morph toward the icon at progress t (0–1), without the spring.
progressnumberRead-only current morph progress; 1 at rest.
getMorph() => Morph | nullReturns the underlying Morph driver, or null before any icon shows up.

Technologies

  • The engine aligns both paths with 2D Procrustes to detect rotation, interpolates in polar space, and drives it with a damped spring.
  • Exports TxIconMorph, IconMorph, TxMorphIcon, and MorphIcon from @talex-touch/tuffex/icon-morph or @talex-touch/tuffex.
  • Source: packages/tuffex/packages/components/src/icon-morph/.
查看源码
packages/tuffex/packages/components/src/icon-morph/index.ts