UI

Icon morph

Eight icons that morph between two states instead of swapping.

import { IconMorph } from '@uthereal/ui/icon-morph'

Icon morph playground

Loading interactive preview…

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.

nameDirect exportstate: falsestate: trueMotion
menuMenuMorphIconHamburgerCloseOuter bars slide and rotate (morph); middle bar folds (snappy)
playPlayPauseIconPlay trianglePause barsSplit triangle quads interpolate into parallel bars (morph)
plusPlusCheckIconPlusCheckTwo strokes swing endpoints into check legs (morph)
copyCopyCheckIconCopy sheetsCheckBack sheet tucks, front sheet settles, check draws in (smooth)
themeSunMoonIconSunMoonDisc grows while masked shadow carves crescent; rays fold (morph)
chevronChevronMorphIconResting arrowTurned arrowRotates turn degrees from pointing (down or right) (morph)
bellBellMorphIconMuted (slash)ActiveSlash retracts (smooth); one-shot bell swing with lagging clapper
heartHeartMorphIconOutlineLiked (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.

ArgumentType / defaultDescription
nameRequiredIconMorphName—Which of the eight icons to render: menu, play, plus, copy, theme, chevron, bell or heart.
stateboolean—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.
defaultStatebooleanDefault: falseInitial state when uncontrolled. Later argument edits do not reset a mounted instance.
sizenumberDefault: 24Rendered size in pixels, 12 to 64. The default 24 sits in a 32px control.
strokeWidthnumberDefault: 1.75Stroke weight on the 24 unit grid, from 0.75 to 4; Arc uses 1.75.
turnnumberDefault: 180Degrees the chevron turns when state is true (-360 to 360). 180 flips down to up; 90 turns right to down.
pointingdown | rightDefault: "down"Where the chevron points at rest: down (default) or right.
interactivebooleanDefault: falseWrap 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.
labelstring—Accessible name of the interactive button, required when interactive is true. Name the action and its object, e.g. "Open menu".
variantsolid | soft | outline | ghostDefault: "ghost"Fill treatment of the interactive button; ghost (the default) suits toolbars.
toneneutral | accent | dangerDefault: "neutral"Color role of the interactive button: neutral is ink, accent follows the theme accent, danger marks destructive actions.
sizeStepxs | sm | md | lgDefault: "md"Square size of the interactive button: 32, 36, 44 or 50 pixels, matching the control scale.
actionstring—Name of an action registered by your application. Sent to onAction when the interactive button is activated.
disabledbooleanDefault: falseUnavailable and removed from the tab order.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeIconMorphTheme—Color mode, accent, and semantic tokens, including the liked-heart color (likeColor). See Theming for all keys and defaults.
motionnone | subtle | expressiveDefault: "subtle"Morph and press animation preset. System reduced-motion preferences take precedence.
motionOptionsIconMorphMotionOptions—Press scale (omitted, it follows the width) and icon swap duration (ms) and travel (px) of the interactive button.
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

React integration

PropPurpose
onAction(action)Handle the named action on activation when interactive is true.
onClick(event)Native click handler on the interactive button; runs before onAction.
refForwarded to the <button> in interactive mode; unused in bare SVG mode.
presetApplication defaults, overridden by explicit instance arguments.
tokens--ui-* CSS variable overrides applied after the typed theme.
className, styleApplied to the <button> when interactive, or the bare <svg> otherwise.
animatedDirect icon exports only (MenuMorphIcon, etc.): set false for instant swaps.
Native attributesid, aria-*, title, and button attributes forwarded in interactive mode.

Keyboard & accessibility

KeyInteraction
TabFocus the interactive button; a keyboard ring appears.
Enter, SpaceActivate 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": []
}

On this page