Convert Figma logo to code with AI

cyntler logohamburger-react

Animated hamburger menu icons for React.js weighs only 1.5 KB.

1,018
40
1,018
10

Top Related Projects

Tasty CSS-animated Hamburgers

:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations

🔥 A highly scalable, offline-first foundation with the best developer experience and a focus on performance and best practices.

Bootstrap components built with React

Accessible modal dialog component for React

Quick Overview

Hamburger-react is a lightweight, customizable React component library for creating animated hamburger menu icons. It provides a simple way to add interactive menu toggles to React applications with minimal setup and a variety of animation styles.

Pros

  • Easy to use and integrate into existing React projects
  • Offers multiple animation styles for hamburger icons
  • Lightweight with no external dependencies
  • Fully customizable with props for color, size, and animation duration

Cons

  • Limited to hamburger menu icons only
  • May require additional styling for optimal integration with some designs
  • Animations might be considered too simple for complex UI requirements

Code Examples

Basic usage:

import Hamburger from 'hamburger-react'

function App() {
  return <Hamburger />
}

Customized hamburger icon:

import Hamburger from 'hamburger-react'

function App() {
  return (
    <Hamburger
      size={32}
      color="#4FD1C5"
      duration={0.3}
      distance="lg"
      rounded
    />
  )
}

Using with state management:

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

function App() {
  const [isOpen, setOpen] = useState(false)

  return (
    <Hamburger toggled={isOpen} toggle={setOpen} />
  )
}

Getting Started

  1. Install the package:

    npm install hamburger-react
    
  2. Import and use in your React component:

    import Hamburger from 'hamburger-react'
    
    function MyComponent() {
      return (
        <div>
          <Hamburger onToggle={toggled => console.log(toggled)} />
        </div>
      )
    }
    
  3. Customize as needed using available props:

    <Hamburger
      size={24}
      direction="right"
      duration={0.5}
      color="#333"
      easing="ease-in"
    />
    

Competitor Comparisons

Tasty CSS-animated Hamburgers

Pros of hamburgers

  • Offers a wide variety of hamburger animations (26 types)
  • Provides CSS and Sass versions for flexibility
  • Includes customization options for colors, sizes, and animations

Cons of hamburgers

  • Requires more setup and configuration
  • Larger file size due to multiple animation options
  • May require additional CSS knowledge for customization

Code Comparison

hamburgers (CSS):

.hamburger {
  padding: 15px;
  display: inline-block;
  cursor: pointer;
  transition-property: opacity, filter;
  transition-duration: 0.15s;
  transition-timing-function: linear;
  font: inherit;
  color: inherit;
  text-transform: none;
  background-color: transparent;
  border: 0;
  margin: 0;
  overflow: visible;
}

hamburger-react (JSX):

import Hamburger from 'hamburger-react'

function App() {
  const [isOpen, setOpen] = useState(false)
  return <Hamburger toggled={isOpen} toggle={setOpen} />
}

hamburgers provides more customization options and animation varieties but requires more setup. hamburger-react offers a simpler, React-specific implementation with fewer options but easier integration. The code comparison shows the CSS-based approach of hamburgers versus the component-based approach of hamburger-react.

:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations

Pros of react-burger-menu

  • More customizable with various menu styles and animations
  • Includes built-in accessibility features
  • Offers more comprehensive documentation and examples

Cons of react-burger-menu

  • Larger bundle size due to additional features
  • Steeper learning curve for basic implementation
  • Less frequently updated compared to hamburger-react

Code Comparison

react-burger-menu:

import { slide as Menu } from 'react-burger-menu'

<Menu>
  <a id="home" className="menu-item" href="/">Home</a>
  <a id="about" className="menu-item" href="/about">About</a>
  <a id="contact" className="menu-item" href="/contact">Contact</a>
</Menu>

hamburger-react:

import Hamburger from 'hamburger-react'

const [isOpen, setOpen] = useState(false)

<Hamburger toggled={isOpen} toggle={setOpen} />

Summary

react-burger-menu offers more features and customization options, making it suitable for complex menu requirements. However, it comes with a larger bundle size and steeper learning curve. hamburger-react, on the other hand, provides a simpler and more lightweight solution for basic hamburger menu functionality, with a focus on easy implementation and smaller bundle size. The choice between the two depends on the specific needs of the project, balancing between feature richness and simplicity.

🔥 A highly scalable, offline-first foundation with the best developer experience and a focus on performance and best practices.

Pros of react-boilerplate

  • Comprehensive and feature-rich, offering a complete setup for large-scale React applications
  • Includes built-in state management, routing, and internationalization
  • Provides a scalable project structure with best practices for React development

Cons of react-boilerplate

  • Steeper learning curve due to its complexity and numerous features
  • May be overkill for smaller projects or simple applications
  • Requires more setup time and configuration compared to lightweight alternatives

Code Comparison

react-boilerplate:

import React from 'react';
import { Helmet } from 'react-helmet';
import styled from 'styled-components';
import { Switch, Route } from 'react-router-dom';

import HomePage from 'containers/HomePage/Loadable';

hamburger-react:

import React from 'react'
import Hamburger from 'hamburger-react'

const App = () => {
  const [isOpen, setOpen] = useState(false)
  return <Hamburger toggled={isOpen} toggle={setOpen} />
}

react-boilerplate is a comprehensive solution for building large-scale React applications, offering a robust set of features and best practices. However, it may be excessive for simpler projects. hamburger-react, on the other hand, is a lightweight and focused library specifically for creating hamburger menu icons, making it easier to implement but with a narrower scope.

Bootstrap components built with React

Pros of react-bootstrap

  • Comprehensive UI component library with a wide range of pre-built components
  • Extensive documentation and community support
  • Seamless integration with Bootstrap's CSS framework

Cons of react-bootstrap

  • Larger bundle size due to its extensive component library
  • Steeper learning curve for developers unfamiliar with Bootstrap
  • Less flexibility for custom styling compared to more lightweight alternatives

Code Comparison

hamburger-react:

import Hamburger from 'hamburger-react'

const Menu = () => {
  const [isOpen, setOpen] = useState(false)
  return <Hamburger toggled={isOpen} toggle={setOpen} />
}

react-bootstrap:

import { Navbar, Nav } from 'react-bootstrap'

const Menu = () => (
  <Navbar expand="lg">
    <Navbar.Toggle aria-controls="basic-navbar-nav" />
    <Navbar.Collapse id="basic-navbar-nav">
      <Nav className="mr-auto">
        <Nav.Link href="#home">Home</Nav.Link>
        <Nav.Link href="#about">About</Nav.Link>
      </Nav>
    </Navbar.Collapse>
  </Navbar>
)

Summary

hamburger-react is a lightweight, focused library for creating hamburger menu icons, while react-bootstrap is a comprehensive UI component library. hamburger-react offers simplicity and ease of use for specific menu functionality, whereas react-bootstrap provides a full suite of components but with added complexity and larger bundle size.

Accessible modal dialog component for React

Pros of react-modal

  • More comprehensive and feature-rich, offering a complete modal solution
  • Highly customizable with various options for styling and behavior
  • Well-established project with a large community and extensive documentation

Cons of react-modal

  • Larger bundle size due to its comprehensive nature
  • Steeper learning curve for basic implementations
  • May require more setup and configuration for simple use cases

Code Comparison

react-modal:

import Modal from 'react-modal';

<Modal
  isOpen={modalIsOpen}
  onRequestClose={closeModal}
  contentLabel="Example Modal"
>
  <h2>Modal Content</h2>
  <button onClick={closeModal}>Close</button>
</Modal>

hamburger-react:

import Hamburger from 'hamburger-react'

<Hamburger toggled={isOpen} toggle={setOpen} />

Summary

react-modal is a more comprehensive solution for creating modals in React applications, offering extensive customization options and a robust feature set. However, it comes with a larger bundle size and potentially more complex setup for basic use cases.

hamburger-react, on the other hand, is a lightweight and focused component specifically for creating hamburger menu icons. It's simpler to implement but lacks the broader functionality of a full modal system.

The choice between these libraries depends on the specific needs of your project. If you require a full-featured modal system, react-modal is the better choice. For a simple hamburger menu icon, hamburger-react offers a more streamlined solution.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

‌

Preview

‌

Animated hamburger menu icons for React

Hamburger menu icons for React, with CSS-driven transitions. Created to be as elegant and performant as possible. This means no JavaScript animations, no transitions on non-cheap properties and a small size.

Installation

npm install hamburger-react

Size

When using one hamburger, ~1.5 KB will be added to your bundle (min + gzip).

Usage

Visit the website for full documentation, API and examples. A basic implementation looks as follows:

import Hamburger from 'hamburger-react'
const [isOpen, setOpen] = useState(false)
<Hamburger toggled={isOpen} toggle={setOpen} />

Or without providing your own state:

<Hamburger onToggle={toggled => ...} />

Yet another hamburger library?

Yes. Since the creation of these burgers in 2015 a lot of similar ones have appeared, with one or more of the following downsides:

  • Animations that don't feel natural
  • Transitions on expensive properties (jerky animations)
  • No React support
  • Size (additional dependencies besides React or no tree shaking)
  • Not customizable, or too customizable (no sensible defaults)
  • Doing too much

Accessibility

It is recommended to have a tap/click area of at least 48x48 pixels. Therefore, padding will be added around the icon to create a surface of exactly this size.

Keyboard interaction is provided with the enter key, and the icon element has the recommended accessibility attributes (such as role). You can use the label property to supply an ARIA label for the icon.

Support

The icons are hooks-based, and will work with React 16.8.0 ('the one with hooks') or higher.

NPM DownloadsLast 30 Days