Icon morph
Eight icons that morph between two states instead of swapping.
import { IconMorph } from '@uthereal/ui/icon-morph'Icon morph playground
Overview
IconMorph renders eight two-state icons that morph in place instead of swapping. Lines rotate and slide, shapes interpolate their SVG path data, and one-shot moments fire on activation (the bell rings and the heart bursts). Every morph uses an interruptible spring, so rapid toggling reverses smoothly from the current position.
Icons are decorative by default (aria-hidden="true") and render a bare <svg> for composition inside any host control. Set interactive to wrap the icon in a labelled native button with press motion and a focus ring. Use IconMorph when an icon toggles between two states; use a plain icon or Button when the glyph does not morph.
name | Direct export | state: false | state: true | Motion |
|---|---|---|---|---|
menu | MenuMorphIcon | Hamburger | Close | Outer bars slide and rotate (morph); middle bar folds (snappy) |
play | PlayPauseIcon | Play triangle | Pause bars | Split triangle quads interpolate into parallel bars (morph) |
plus | PlusCheckIcon | Plus | Check | Two strokes swing endpoints into check legs (morph) |
copy | CopyCheckIcon | Copy sheets | Check | Back sheet tucks, front sheet settles, check draws in (smooth) |
theme | SunMoonIcon | Sun | Moon | Disc grows while masked shadow carves crescent; rays fold (morph) |
chevron | ChevronMorphIcon | Resting arrow | Turned arrow | Rotates turn degrees from pointing (down or right) (morph) |
bell | BellMorphIcon | Muted (slash) | Active | Slash retracts (smooth); one-shot bell swing with lagging clapper |
heart | HeartMorphIcon | Outline | Liked (fill) | Fill fades in with likeColor; one-shot ring and 7-spark burst on pop |
Usage
'use client'
import { useState } from 'react'
import { IconMorph } from '@uthereal/ui/icon-morph'
export function LikeToggle() {
const [liked, setLiked] = useState(false)
return (
<IconMorph
name="heart"
state={liked}
interactive
label={liked ? 'Unlike photo' : 'Like photo'}
action="toggle_photo_like"
onClick={() => setLiked((value) => !value)}
onAction={(action) => console.log(action)}
/>
)
}In interactive mode, onAction receives action after onClick. Leave interactive off to compose the bare decorative SVG inside your own button, checkbox, or switch (or import an individual icon such as PlusCheckIcon directly).
Examples
The eight morphing icons
Click any icon to morph it between its resting and active states. Activating bell plays the one-shot ring, and activating heart fires the spark burst.
Custom orientation and styled buttons
Configure pointing and turn on chevron for side-to-down disclosure arrows, and combine interactive with action variant, tone, and sizeStep options.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
nameRequired | IconMorphName— | Which of the eight icons to render: menu, play, plus, copy, theme, chevron, bell or heart. |
state | boolean— | Controlled second state of the icon: menu to close, play to pause, plus or copy to check, sun to moon, chevron turned, bell on, heart liked. Omit to let an interactive button toggle itself from defaultState. |
defaultState | booleanDefault: false | Initial state when uncontrolled. Later argument edits do not reset a mounted instance. |
size | numberDefault: 24 | Rendered size in pixels, 12 to 64. The default 24 sits in a 32px control. |
strokeWidth | numberDefault: 1.75 | Stroke weight on the 24 unit grid, from 0.75 to 4; Arc uses 1.75. |
turn | numberDefault: 180 | Degrees the chevron turns when state is true (-360 to 360). 180 flips down to up; 90 turns right to down. |
pointing | down | rightDefault: "down" | Where the chevron points at rest: down (default) or right. |
interactive | booleanDefault: false | Wrap the icon in a labelled native button with press motion and a focus ring. Off (the default) renders the bare decorative svg for use inside any control. |
label | string— | Accessible name of the interactive button, required when interactive is true. Name the action and its object, e.g. "Open menu". |
variant | solid | soft | outline | ghostDefault: "ghost" | Fill treatment of the interactive button; ghost (the default) suits toolbars. |
tone | neutral | accent | dangerDefault: "neutral" | Color role of the interactive button: neutral is ink, accent follows the theme accent, danger marks destructive actions. |
sizeStep | xs | sm | md | lgDefault: "md" | Square size of the interactive button: 32, 36, 44 or 50 pixels, matching the control scale. |
action | string— | Name of an action registered by your application. Sent to onAction when the interactive button is activated. |
disabled | booleanDefault: false | Unavailable and removed from the tab order. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | IconMorphTheme— | Color mode, accent, and semantic tokens, including the liked-heart color (likeColor). See Theming for all keys and defaults. |
motion | none | subtle | expressiveDefault: "subtle" | Morph and press animation preset. System reduced-motion preferences take precedence. |
motionOptions | IconMorphMotionOptions— | Press scale (omitted, it follows the width) and icon swap duration (ms) and travel (px) of the interactive button. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
onAction(action) | Handle the named action on activation when interactive is true. |
onClick(event) | Native click handler on the interactive button; runs before onAction. |
ref | Forwarded to the <button> in interactive mode; unused in bare SVG mode. |
preset | Application defaults, overridden by explicit instance arguments. |
tokens | --ui-* CSS variable overrides applied after the typed theme. |
className, style | Applied to the <button> when interactive, or the bare <svg> otherwise. |
animated | Direct icon exports only (MenuMorphIcon, etc.): set false for instant swaps. |
| Native attributes | id, aria-*, title, and button attributes forwarded in interactive mode. |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Focus the interactive button; a keyboard ring appears. |
Enter, Space | Activate the interactive button. |
Bare icons render with aria-hidden="true" and focusable="false". The parent control must provide the accessible name and state (aria-pressed or aria-expanded).
In interactive mode, label is required and sets aria-label. aria-pressed tracks state automatically unless you pass aria-expanded or an explicit aria-pressed attribute. Square button sizes follow the control scale (32px to 50px), keeping touch targets above the 24px minimum even when size is smaller. Under forced-colors: active, a liked heart uses Highlight (or HighlightText inside a solid button) to preserve contrast.
Motion and theming
Most morphs run on the interruptible morph spring; copy and the bell slash use smooth, and the menu middle bar folds on snappy. The bell ring and heart burst are one-shot effects that replay each time state transitions from false to true. Both motion="none" and prefers-reduced-motion: reduce snap every morph instantaneously, skip the ring and burst, and disable the heart color transition.
Icons inherit currentColor from their parent. A liked heart reads --ui-icon-morph-like-color, which defaults to --ui-danger and can be customized through theme.tokens.likeColor or tokens. Both interactive and bare IconMorph emit their resolved --ui-* variables inline and accept defaults from UtherealProvider.
Composition
In an agent composition, IconMorph is a leaf. Leave interactive off when embedding inside another control. With interactive: true, label is required and action must reference a host-registered action; the host handler receives { componentId }. See Building with agents.
{
"type": "IconMorph",
"props": {
"name": "heart",
"interactive": true,
"label": "Like photo",
"action": "toggle_photo_like"
},
"children": []
}