# Icon morph

> A named native checkbox with a menu, playback or favorite icon that moves into its checked state.

- Kind: ui · Category: Actions · Interactivity: native
- Install: `npx shadcn@latest add @haze/icon-morph`
- File: `src/components/haze/ui/icon-morph.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/icon-morph

## Use when
- A small toggle needs a recognizable visual change without a changing layout
- A navigation, preview or favorite control already has a meaningful checked state

## Avoid when
- Use action-swap when the action needs visible text beside its icon
- Use button for an icon action that does not retain a selected state

## Alternatives
- [action-swap](https://hazeui.com/ui/action-swap.md)
- [toggle](https://hazeui.com/ui/toggle.md)
- [button](https://hazeui.com/ui/button.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Unique caller-supplied prefix for this component and its related elements. |
| name | `string` | id | no | Form submission name. |
| label | `string` | "Toggle navigation" | no | Accessible label describing the checked state. |
| variant | `"menu" \| "play" \| "favorite"` | "menu" | no | Icon pair to draw. |
| checked | `boolean` | false | no | Initial native checked state. |
| disabled | `boolean` |  | no | Disables the native control and its enhancement. |
| class | `string` |  | no | Additional classes for the component root. |
| ...attributes | `native control attributes` |  | no | Other attributes are forwarded to the real form control. |

## Accessibility
- Only the checkbox is exposed as a control; the drawn icon is decorative.
- A persistent text label names the toggle, and its checked state is available without JavaScript.
- Key Tab, Space: Reach the icon control and toggle its checked state.

## Agent prompts

### Install and use

Install the Haze UI component "Icon morph" with `npx shadcn@latest add @haze/icon-morph`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import IconMorph from "@/components/haze/ui/icon-morph.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/icon-morph.md

### Customize with real content

Adapt the Haze icon-morph ui for our product. Replace the demo values of these props with our real content: id, name, label, variant, checked, disabled, class, ...attributes. Keep the layout, the heading level rules and these accessibility details: Only the checkbox is exposed as a control; the drawn icon is decorative. A persistent text label names the toggle, and its checked state is available without JavaScript. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using icon-morph, check it fits: use it when a small toggle needs a recognizable visual change without a changing layout; a navigation, preview or favorite control already has a meaningful checked state. Avoid it when use action-swap when the action needs visible text beside its icon; use button for an icon action that does not retain a selected state. Alternatives: @haze/action-swap, @haze/toggle, @haze/button.

## Example requests that should lead here
- Add a labeled menu-to-close icon toggle using a real checkbox.

## Source

```astro
---
import { Heart, Pause, Play } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id: string;
  name?: string;
  label?: string;
  variant?: "menu" | "play" | "favorite";
  checked?: boolean;
  disabled?: boolean;
  class?: string;
  [key: string]: unknown;
}

const { id, name = id, label = "Toggle navigation", variant = "menu", checked = false, disabled, class: className, ...rest } = Astro.props;
---

<span class={cn("relative inline-grid size-10 shrink-0", className)}>
  <input {...rest} id={id} name={name} type="checkbox" checked={checked} disabled={disabled} class="peer sr-only" />
  <label for={id} class="group grid size-10 cursor-pointer place-items-center rounded-lg border border-frame bg-field text-foreground transition-[background-color,box-shadow,scale] duration-150 ease-snappy hover:bg-accent hover:shadow-key active:scale-[0.96] active:duration-75 peer-focus-visible:outline-2 peer-focus-visible:outline-offset-1 peer-focus-visible:outline-ring peer-disabled:cursor-not-allowed peer-disabled:bg-muted peer-disabled:text-muted-foreground peer-checked:[&_[data-top]]:translate-y-1.5 peer-checked:[&_[data-top]]:rotate-45 peer-checked:[&_[data-middle]]:scale-x-0 peer-checked:[&_[data-bottom]]:-translate-y-1.5 peer-checked:[&_[data-bottom]]:-rotate-45 peer-checked:[&_[data-play]]:scale-50 peer-checked:[&_[data-play]]:opacity-0 peer-checked:[&_[data-pause]]:scale-100 peer-checked:[&_[data-pause]]:opacity-100 peer-checked:[&_[data-heart]]:fill-current peer-checked:[&_[data-heart]]:scale-110">
    <span class="sr-only">{label}</span>
    {variant === "menu" && <span aria-hidden="true" class="grid gap-1"><span data-top class="h-0.5 w-4 rounded-full bg-current transition-[translate,rotate] duration-200 ease-snappy"></span><span data-middle class="h-0.5 w-4 rounded-full bg-current transition-[scale] duration-200 ease-snappy"></span><span data-bottom class="h-0.5 w-4 rounded-full bg-current transition-[translate,rotate] duration-200 ease-snappy"></span></span>}
    {variant === "play" && <span aria-hidden="true" class="relative size-5"><Play data-play class="absolute inset-0 size-5 fill-current transition-[scale,opacity] duration-200 ease-snappy" /><Pause data-pause class="absolute inset-0 size-5 scale-50 fill-current opacity-0 transition-[scale,opacity] duration-200 ease-snappy" /></span>}
    {variant === "favorite" && <Heart data-heart aria-hidden="true" class="size-5 transition-[scale,fill] duration-200 ease-spring" />}
  </label>
</span>
```
