HamburgerButton
Animated hamburger with icon, shape, size, and material.
HamburgerButton
Domain: navigation
Package path: packages/ui/src/navigation/toggles/hamburger-button.tsx
Import: @ziteox/ui or @ziteox/ui/navigation
Hamburger menu trigger. Pick the icon (bar layout), shape, size, and a material surface. Open/closed morph is built in — CSS-driven from aria-expanded and data-state.
SiteMenuToggle remains a thin two-bar circle preset over this component. AnimatedHamburgerButton is a deprecated alias of HamburgerButton.
Icon types
Three-bar and two-bar are the primary choices. Click to toggle open/closed. No material fill — the icon itself is the content. Preview follows the site theme.
Materials
Each registered surface (frosted, ink, emboss) as a plain button — same layout as icon types. The controls panel switches the icon type shown on these buttons.
Usage
import { useState } from "react";
import { HamburgerButton } from "@ziteox/ui";
export function MobileNavTrigger() {
const [isOpen, setIsOpen] = useState(false);
return (
<HamburgerButton
icon="three-bar"
shape="circle"
size="lg"
material="emboss"
isOpen={isOpen}
onOpenChange={setIsOpen}
className="lg:hidden"
/>
);
}Preset
import { SiteMenuToggle } from "@ziteox/ui";
// Two-bar circle with frosted material
<SiteMenuToggle isOpen={isOpen} onOpenChange={setIsOpen} />Legacy three-bar props still work: variant="default" | "circle" | "ghost" maps to shape / ghost. Without material or ghost, the default surface is emboss.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | — | Open state; sets aria-expanded and data-state |
onOpenChange | (isOpen: boolean) => void | — | Called on click with toggled value, before haptics |
className | string | — | Appended to root button classes |
icon | "two-bar" | "three-bar" | "three-bar" | Bar layout (HAMBURGER_ICONS) |
shape | "circle" | "square" | "rounded-square" | "rounded-square" | Hit-area shape (HAMBURGER_SHAPES) |
size | "md" | "lg" | "md" | md is 44px; lg is 48px |
material | "frosted" | "ink" | "emboss" | "emboss" | Surface from Materials. Omitted when ghost |
ghost | boolean | false | Icon-only; ignored when material is set |
variant | "default" | "circle" | "ghost" | — | Deprecated shape/ghost alias |
haptic | boolean | preset name | true | WebHaptics; default selection; false disables |
Install peer: pnpm add web-haptics
Accessibility
| Attribute | Value |
|---|---|
aria-expanded | "true" / "false" from isOpen |
data-state | "open" / "closed" — drives the morph with aria-expanded |
aria-label | "Open menu" / "Close menu" |
data-icon / data-shape | Current icon and shape |
| Screen reader | Hidden "Menu" text via ziteox-sr-only |
Styling
Scoped classes (no Tailwind in the package):
ziteox-hamburgerziteox-hamburger--two-bar/--three-barziteox-hamburger--circle/--square/--rounded-squareziteox-hamburger--md/--lgziteox-hamburger-bar-*(three-bar)ziteox-hamburger-line-*(two-bar)
Extensible registries: HAMBURGER_ICONS, HAMBURGER_SHAPES, HAMBURGER_SIZES.
Animation
| Concern | Implementation |
|---|---|
| Morph | CSS transform on bars/lines, selected by [data-state="open"] / [aria-expanded="true"] |
| Three-bar easing | Per-bar cubic-bezier |
| Two-bar easing | cubic-bezier(0.4, 0, 0.2, 1) |
| Reduced motion | usePrefersReducedMotion → 150ms |
| Hydration | useSkipInitialAnimation disables transitions on first render |
Does not use motion.
State ownership
The button only. The app owns menu panel, overlay, scroll lock, and open state.
Architecture notes
| Decision | Rationale |
|---|---|
| One component | Two-bar and three-bar are icon styles of the same control; animation is inherent |
| Material prop | Surface is composable; emboss restores the original 3D fill |
| SiteMenuToggle preset | Keeps existing two-bar circle call sites working |
CSS not motion | Simple transform morph; smaller bundle |
Related
- Materials
- SiteMenuToggle — two-bar circle preset
- animation-guidelines
- domain-boundaries