DocsShowcaseGitHub
IntroductionReactMorphingLine, Fill and DuoSVGAccessibilityDesignRoadmapChangelog
Get started
  • Introduction
Guides
  • React
  • Morphing
  • Line, Fill and Duo
  • SVG
  • Accessibility
  • Design
Project
  • Roadmap
  • Changelog

Morphing

Previous: ReactNext: Line, Fill and Duo

MorphIcon animates between related icons, like menu to x.

MorphIcon animates from one icon to another when its name changes. Try it:

Usage#

MorphIcon comes from its own entry point in @nubo-icons/react. Pass the icon to show as name, and change it to animate:

import { MorphIcon } from "@nubo-icons/react/morph";
 
<button aria-label={open ? "Close menu" : "Open menu"} onClick={toggle}>
  <MorphIcon name={open ? "x" : "menu"} />
</button>;

It fits anywhere a control flips between two states:

Icons#

MorphIcon covers menu, x, plus, minus, check, and the arrows and chevrons in all four directions. Each of them can change into any other.

Icons that are the same shape turned, like the arrows, the chevrons, and plus and x, rotate as a whole, so an arrow never bends on its way round. Any other pair morphs line by line: lines move to their new place, new lines grow from their middle, and lines that aren't needed shrink away.

They are the same drawings as the regular Line icons, kept to at most three straight lines so they can morph.

Motion#

The animation is a spring with no bounce that settles in about 400ms. Changing name mid-animation starts from wherever the lines are, so fast toggling never jumps.

With reduced motion turned on, icons swap instantly.

In right-to-left layouts, left and right arrows and chevrons swap, so arrow-right points left. MorphIcon reads the direction itself and needs no CSS.

The approach, lines padded to a fixed count and same-shape icons rotating instead of morphing, comes from Benji's Morphing icons with Claude.

Props#

MorphIcon takes name, size, strokeWidth and title, and passes any other SVG prop through, like the other React icons. It draws Line only.

The MorphIconName type lists the names it accepts.

Accessibility#

Like the other icons, MorphIcon is hidden from screen readers unless you give it a title. In a button, label the button and change the label with the icon, so the label always says what the button will do.

ReactLine, Fill and Duo

On this page

  • Usage
  • Icons
  • Motion
  • Props
  • Accessibility
Edit this pageBack to top