Hamburger
A menu button whose three bars fold into an X, in two motions, all CSS. The root is a real button carrying aria-expanded, and it manages its own state until you hand it an open prop.
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece hamburger
Requires the pieces.css tokens merged into your app styles (see Introduction). The transitions travel inside the piece's own style block, so there is no stylesheet to import.
Usage
import Hamburger from '@/components/ui/Hamburger.pzl';
<Hamburger/>
<Hamburger variant="twist" open={ menuOpen } controls="site-nav" @change={ setMenuOpen }/>Variants
- converge — the default. The outer bars slide in to the middle one, then turn into the X; closing unturns first, then spreads.
- twist — the same two phases, but the turn keeps going for half a spin before it settles on the X.
Sizes
Driving a menu
aria-expanded="false"
No animation
Color
Accessibility and motion
The root is a native button, so Enter and Space toggle it and it takes focus in order. It carries aria-expanded and, when you pass controls, aria-controls pointing at the menu it opens. The label (default “Menu”) stays the same in both states — aria-expanded already says which one it is in. The three bars are aria-hidden.
Under prefers-reduced-motion: reduce there are no transitions at all: the icon swaps between the bars and the X instantly, exactly as it does with animate={ false }.