Animated Hamburger Menu Icons for React

2.5.2 · active · verified Sun Apr 19

hamburger-react provides a collection of animated hamburger menu icons specifically designed for React applications. It focuses on performance and elegance, utilizing CSS-driven transitions on 'cheap' properties to avoid jerky animations, differentiating itself from libraries that use JavaScript for animations or transition expensive CSS properties. The current stable version is 2.5.2, with releases occurring periodically to support new React versions and add minor features or accessibility improvements. Key differentiators include its small bundle size (~1.5 KB min+gzip per hamburger), hooks-based implementation (requiring React 16.8.0+), robust accessibility features (ARIA labels, keyboard interaction, recommended tap area), and a focused API that avoids over-customization while providing sensible defaults. It supports React 16.8 through 19 via peer dependencies.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic setup of the Hamburger component, integrating it with React's `useState` hook for toggling, and showcasing various common props for customization and accessibility.

import Hamburger from 'hamburger-react';
import { useState } from 'react';

const MyMenuToggle = () => {
  // Manage the open/closed state of the menu
  const [isOpen, setOpen] = useState(false);

  // Render the Hamburger component, binding its state to the component's state
  // This allows external control over the hamburger's toggled state.
  return (
    <div>
      <button
        aria-label="Toggle menu"
        onClick={() => setOpen(!isOpen)}
        style={{ border: 'none', background: 'transparent', cursor: 'pointer' }}
      >
        <Hamburger 
          toggled={isOpen} 
          toggle={setOpen} 
          size={24} 
          duration={0.8} 
          label="Show navigation" 
          hideOutline={false} 
          direction="left"
          distance="lg"
          easing="ease-in"
          rounded
        />
      </button>
      {isOpen && (
        <nav style={{ padding: '20px', backgroundColor: '#f0f0f0', border: '1px solid #ccc' }}>
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
      )}
    </div>
  );
};

export default MyMenuToggle;

view raw JSON →