├── .babelrc
├── .gitignore
├── LICENSE.md
├── README.md
├── example
├── App.js
├── app.css
├── index.html
└── webpack.config.js
├── package.json
├── src
└── HamburgerMenu.js
├── webpack.config.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": ["@babel/plugin-proposal-object-rest-spread"],
3 | "presets": [
4 | ["@babel/preset-env", { "loose": true, "useBuiltIns": "entry" }],
5 | "@babel/react"
6 | ],
7 | }
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .DS_Store
4 | *.log
5 | example/bundle.js
6 | example/bundle.js.map
7 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Cameron Bourke
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | React Hamburger Menu
2 | =========================
3 |
4 | Built for React, this is a handy UI component for a menu icon in a mobile site or application.
5 |
6 | ## Installation
7 |
8 | react-hamburger-menu requires **React 0.14 or later.**
9 |
10 | ```
11 | npm install --save react-hamburger-menu
12 | ```
13 |
14 | ## Demo & Example
15 |
16 | Live demo: [cameronbourke.github.io/react-hamburger-menu](http://cameronbourke.github.io/react-hamburger-menu)
17 |
18 | To build the example locally, clone this repo then run:
19 |
20 | ```
21 | npm install
22 | npm start
23 | Then open localhost:8080 in a browser.
24 | ```
25 |
26 | ## Usage
27 |
28 | React Hamburger Menu only has two required props. They are `isOpen` and `menuClicked`. The other 7 props are optional.
29 |
30 | #### menuClicked
31 |
32 | Note: This prop is passed a `function`. This function will be invoked when the component is `clicked`. The function should responsible for updating the state that is passed to `isOpen`. The function passed to `menuClicked` could look something like the following:
33 |
34 | ```js
35 | handleClick() {
36 | this.setState({
37 | open: !this.state.open
38 | });
39 | }
40 | ```
41 |
42 | An example use of React Hamburger Menu looks like:
43 |
44 | ```js
45 |
56 | ```
57 |
58 | Note, not all props are required. All the props besides `isOpen` and `menuClicked` have defaults.
59 |
60 | ## Options
61 |
62 | Property | Type | Default | Description
63 | ------------- | ------------- | --------- | ----------
64 | isOpen | bool | undefined | determines whether the menu is a hamburger or cross icon
65 | menuClicked | func | undefined | will be invoked when the component is clicked
66 | width | number | 36 | the width of the icon
67 | height | number | 30 | the height of the icon
68 | strokeWidth | number | 2 | the stroke width of the lines
69 | rotate | number | 0 | the rotation of the icon, eg {45} would be `45deg`
70 | color | string | #000 | the color of both icons
71 | borderRadius | number | 0 | the border radius of the lines
72 | animationDuration | number | 0.4 | the length of time it takes for the icon transitions to complete.
73 | className | string | undefined | the class name for the container element
74 |
75 | ## Todo
76 |
77 | - Add Unit Tests
78 |
79 | ## License
80 |
81 | MIT Licensed Copyright (c) Cameron Bourke 2016
82 |
--------------------------------------------------------------------------------
/example/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import HamburgerMenu from '../src/HamburgerMenu';
4 |
5 | class App extends React.Component {
6 | constructor() {
7 | super();
8 | this.state = {
9 | open: [false, true, false, true]
10 | };
11 | }
12 | handleClick(id) {
13 | let { open } = this.state;
14 | this.setState({
15 | open: [...open.slice(0, id), !open[id], ...open.slice(id + 1)]
16 | });
17 | }
18 | render() {
19 | return (
20 |