Coder Social home page Coder Social logo

xiaoqi1102 / react-burger-menu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from negomi/react-burger-menu

0.0 2.0 0.0 1.47 MB

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

Home Page: http://negomi.github.io/react-burger-menu/

License: MIT License

JavaScript 96.22% CSS 3.31% HTML 0.46%

react-burger-menu's Introduction

react-burger-menu Build Status

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

Demo & Examples

Live demo: negomi.github.io/react-burger-menu

To build the examples locally, run:

npm install
npm start

Then open localhost:8000 in a browser.

Tests

The test suite uses Mocha, Chai and Sinon, with jsdom.

You will need Node v4.0.0 (or io.js) to run the tests, due to jsdom depending on it.

To run the tests once, run:

npm test

To run them with a watcher, TDD style, run:

npm run tdd

For a code coverage report generated by Istanbul, run:

npm run coverage

Installation

The easiest way to use react-burger-menu is to install it from npm and include it in your own React build process (using Browserify, Webpack, etc).

If you're using Webpack, you'll need to add imports-loader to your devDependencies.

You can also use the standalone build by including dist/react-burger-menu.js in your page. If you use this, make sure you have already included React, and it is available as a global variable.

If you're using React 0.14:

npm install react-burger-menu --save

If you're using React 0.13.3:

npm install [email protected] --save

Usage

Items for the sidebar should be passed as child elements of the component using JSX.

var Menu = require('react-burger-menu').nameOfAnimation;

var Example = React.createClass({
  showSettings: function(event) {
    event.preventDefault();
    .
    .
    .
  },
  render: function() {
    return (
      <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>
        <a onClick={ this.showSettings } className="menu-item--small" href="">Settings</a>
      </Menu>
    );
  }
});

Animations

  • slide
  • stack
  • elastic
  • bubble
  • push
  • pushRotate
  • scaleDown
  • scaleRotate
  • fallDown

Properties

Some animations require certain other elements to be on your page:

  • Page wrapper - an element wrapping the rest of the content on your page, placed after the menu component

    <Menu pageWrapId={ "page-wrap" }/>
    <main id="page-wrap">
      .
      .
      .
    </main>
  • Outer container - an element containing everything, including the menu component

    <div id="outer-container">
      <Menu pageWrapId={ "page-wrap" } outerContainerId={ "outer-container" }/>
      <main id="page-wrap">
        .
        .
        .
      </main>
    </div>

If you are using an animation that requires either/both of these elements, you need to give the element an ID, and pass that ID to the menu component as the pageWrapId and outerContainerId props respectively.

Check this table to see which animations require these elements:

Animation pageWrapId outerContainerId
slide
stack
elastic
bubble
push
pushRotate
scaleDown
scaleRotate
fallDown

There is also an optional id prop, which will simply add an ID to the rendered menu's outermost element. This is not required for any functionality.

<Menu id={ "sidebar" }/>

Styling

All the animations are handled internally by the component. However, the visual styles (colors, fonts etc.) are not, and need to be included with CSS.

The component has the following helper classes:

/* Color of burger icon */
.bm-burger-icon {
  background: #373a47;
}

/* Color of close button cross */
.bm-cross {
  background: #bdc3c7;
}

/* Background color of sidebar */
.bm-menu {
  background: #373a47;
}

.bm-morph-shape {
  fill: #373a47; /* Morph shape necessary with bubble or elastic */
}

/* General menu styles */
.bm-menu {
  padding: 2.5em 1.5em 0;
  font-size: 1.15em;
}

/* Wrapper for item list */
.bm-item-list {
  color: #b8b7ad;
  padding: 0.8em;
}

Browser Support

Because this project uses CSS3 features, it's only meant for modern browsers. It also relies on React's implementation of inline styles, which means some browsers currently fail to apply some of the animations correctly.

Chrome, Firefox and IE 10+ have full support, but Safari has strange behavior for some of the menus.

License

MIT

react-burger-menu's People

Contributors

negomi avatar menelaos avatar

Watchers

James Cloos avatar 小齐 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.