LibraryComponents

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.

Icon types
Two-bar
Three-bar

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.

Materials
frosted button
ink button
emboss button

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

PropTypeDefaultDescription
isOpenboolean—Open state; sets aria-expanded and data-state
onOpenChange(isOpen: boolean) => void—Called on click with toggled value, before haptics
classNamestring—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
ghostbooleanfalseIcon-only; ignored when material is set
variant"default" | "circle" | "ghost"—Deprecated shape/ghost alias
hapticboolean | preset nametrueWebHaptics; default selection; false disables

Install peer: pnpm add web-haptics

Accessibility

AttributeValue
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-shapeCurrent icon and shape
Screen readerHidden "Menu" text via ziteox-sr-only

Styling

Scoped classes (no Tailwind in the package):

  • ziteox-hamburger
  • ziteox-hamburger--two-bar / --three-bar
  • ziteox-hamburger--circle / --square / --rounded-square
  • ziteox-hamburger--md / --lg
  • ziteox-hamburger-bar-* (three-bar)
  • ziteox-hamburger-line-* (two-bar)

Extensible registries: HAMBURGER_ICONS, HAMBURGER_SHAPES, HAMBURGER_SIZES.

Animation

ConcernImplementation
MorphCSS transform on bars/lines, selected by [data-state="open"] / [aria-expanded="true"]
Three-bar easingPer-bar cubic-bezier
Two-bar easingcubic-bezier(0.4, 0, 0.2, 1)
Reduced motionusePrefersReducedMotion → 150ms
HydrationuseSkipInitialAnimation 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

DecisionRationale
One componentTwo-bar and three-bar are icon styles of the same control; animation is inherent
Material propSurface is composable; emboss restores the original 3D fill
SiteMenuToggle presetKeeps existing two-bar circle call sites working
CSS not motionSimple transform morph; smaller bundle