0.7.2 • Published 6 years ago

react-hamburger v0.7.2

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

React-Hamburger

CircleCI Stable Release

A simple and fully customizable hamburger menu for React.

Installation

npm install react-hamburger --save
# or
yarn add react-hamburger

Usage

{ ReactHamburger }

// ES6 syntax
import { ReactHamburger } from 'react-hamburger';

// ES5 syntax
const { ReactHamburger } = require('react-hamburger');

After importing the component, simply render in the typical React manner.

// stateless component
const HamburgerMenu = () => {
  return (
    <ReactHamburger />
  );
};

// class-based component
class HamburgerMenu extends React.Component {
  render() {
    return (
      <ReactHamburger />
    );
  }
}

{ topBarHeight }

// ES6 syntax
import { topBarHeight } from 'react-hamburger';

// ES5 syntax
const { topBarHeight } = require('react-hamburger');

react-hamburger gives access to the default theme's topBarHeight. This property allows for styling modifications to be made based on the height. If you pass your own height to ReactHamburger either through the theme or prop you will still be able to access topBarHeight but it won't be of much value anymore.


Props

Most props can either be directly passed through the ReactHamburger component or, where it exists, through the corresponding theme key.

The barCount, and TopContent props cannot be passed through the theme object.

If you pass a prop and use the theme, the prop will take precedence.

children

Passing in this.props.children will render content in the LinkContainer (i.e. the slide-in-out sidebar).

Theme

NameTypeUnitsDescriptionDefaulttheme key
themeThemeN/Atheme object that can be passed to react-hamburger rather than passing individual props. The object and the keys can be seen in Custom TypesThemeN/A

HamburgerIcon

The icon that the user clicks to show or hide the LinkContainer.

NameTypeUnitsDescriptionDefaulttheme key
barColorstringN/AColor of the HamburgerIcon bars#FF9900bars.color
barCountnumberN/ANumber of bars in the HamburgerIcon3N/A
barHeightnumberpxHeight of the individual HamburgerIcon bars5bars.height
barRadiusnumberpxCurvature of the HamburgerIcon bars5bars.radius
hamburgerHeightnumberpxHeight of the HamburgerIcon40hamburger.dimensions
hamburgerWidthnumberpxWidth of the HamburgerIcon40hamburger.dimensions
inlinebooleanN/AWhether the HamburgerIcon and any TopContent should take up space on the main pagefalsehamburger.inline
lockedbooleanN/AWhether to lock the HamburgerIcon and TopBar to the top of the screenfalsetopBar.locked
slidebooleanN/AWhether the HamburgerIcon should slide out with the LinkContainerfalsehamburger.slide
rightbooleanN/AWhether the HamburgerIcon should be on the right side of the screenfalsehamburger.location

LinkContainer

The component that holds the links (or whatever content the developer wants) that will show or hide when the user clicks on the HamburgerIcon

NameTypeUnitsDescriptionDefaulttheme key
linkContainerColorstringN/AColor of the LinkContainer#123456linkContainer.color
linkContainerMaxWidthnumberpxMaximum width the LinkContainer will cover the screen300linkContainer.maxWidth
linkContainerPaddingnumberpxExternal padding around the outside of the LinkContainer10linkContainer.padding
linkContainerSpeednumbersecondsSpeed (in seconds) that the LinkContainer slides in and out0.5linkContainer.speed
linkContainerTransitionTransitionN/ATransition type for the LinkContainereaselinkContainer.transition
linkContainerWidthnumber%Width that the LinkContainer will take, up to it's maxWidth75linkContainer.width
verticalSlidebooleanN/AWhether the slider should slide from the topfalselinkContainer.vertical

TopBar

NameTypeUnitsDescriptionDefaulttheme key
showTopBarbooleanN/AWhether or not to render a TopBar. Gives access to other topBar* props.falsetopBar.display
topBarColorstringN/AColor of the top bar that holds the HamburgerIcon and any other contents placed inside the TopBar#111111topBar.color
topBarHeightnumberpxHeight of the bar that holds the HamburgerIcon and any other contents placed inside the TopBar60topBar.height
topBarGutternumberpxSpace between the contents of the HamburgerIcon and the edge of the screen0topBar.gutter
TopContentReact.NodeN/AAny content to render alongside the HamburgerIconnullN/A

Types

In some instances, the prop type and the Theme type are different. Refer to the above tables and Theme type listed below to ensure you are passing the correct prop-type.

Custom Types

type Theme = {
  bars: {
    color: string,
    height: number,
    radius: number,
  },
  hamburger: {
    dimensions: number,
    inline: boolean,
    location: string,
    slide: boolean,
  },
  linkContainer: {
    color: string,
    maxWidth: number,
    padding: number,
    speed: number,
    transition: string,
    vertical: boolean,
    width: number,
  },
  topBar: {
    color: string,
    display: boolean,
    height: number,
    gutter: number,
    locked: boolean,
  },
};
type Transition = 'ease' | 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';

Theme

The theme object and its default values is listed below (can also be seen in the props tables). If you don't pass a prop to the component or overwrite the key in the theme the default will be used.

const theme = {
  bars: {
    color: '#FF9900',
    height: 5,
    radius: 5,
  },
  hamburger: {
    dimensions: 40,
    inline: false,
    location: 'left',
    slide: false,
  },
  linkContainer: {
    color: '#123456',
    maxWidth: 300,
    padding: 0,
    speed: 0.5,
    transition: 'ease',
    vertical: false,,
    width: 75,
  },
  topBar: {
    color: '#111111',
    display: false,
    height: 60,
    gutter: 10,
    locked: false,
  },
};
0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1-0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

10 years ago