Icon morph
A named native checkbox with a menu, playback or favorite icon that moves into its checked state.
pnpm dlx shadcn@latest add @haze/icon-morph---
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>When to use
- A small toggle needs a recognizable visual change without a changing layout
- A navigation, preview or favorite control already has a meaningful checked state
When not to use
- 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
Installation
Add the Haze registry to components.json once, then install Icon morph with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/icon-morphnpx shadcn@latest add @haze/icon-morphyarn dlx shadcn@latest add @haze/icon-morphbunx --bun shadcn@latest add @haze/icon-morphFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique caller-supplied prefix for this component and its related elements. |
| name | string | id | Form submission name. |
| label | string | "Toggle navigation" | Accessible label describing the checked state. |
| variant | "menu" | "play" | "favorite" | "menu" | Icon pair to draw. |
| checked | boolean | false | Initial native checked state. |
| disabled | boolean | – | Disables the native control and its enhancement. |
| class | string | – | Additional classes for the component root. |
| ...attributes | native control attributes | – | Other attributes are forwarded to the real form control. |
Keyboard interactions
- Tab, Space
- Reach the icon control and toggle its checked state.
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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.