react-offcanvas 0,0 editorconfig eslint npm

:art: Off-canvas menus for React.

React Off-Canvas

Off-canvas menus for React.

Installation

$ npm install --save react-offcanvas

Usage

Basic Usage

<OffCanvas width={300} transitionDuration={300} isMenuOpened={false} position={"left"}>
  <OffCanvasBody className={"my-body-class"} style={{fontSize: '18px'}}>
    This is the canvas body.
  </OffCanvasBody>
  <OffCanvasMenu className={"my-menu-class"} style={{fontWeight: 'bold'}}>
    This is the canvas menu.
  </OffCanvasMenu>
</OffCanvas>

Within An Application

You’ll need to hook up your application to handle the state for toggling the menu. Check out the basic example below:

'use strict';

import React, { Component } from 'react';
import { OffCanvas, OffCanvasMenu, OffCanvasBody } from 'react-offcanvas';

export default class App extends Component {

  componentWillMount() {
    // sets the initial state
    this.setState({
      isMenuOpened: false
    })
  }

  render() {
    return (
      <OffCanvas width={300} transitionDuration={300} isMenuOpened={this.state.isMenuOpened} position={"right"}>
        <OffCanvasBody className={styles.bodyClass} style={{fontSize: '30px'}}>
          <p>This is the main body container.</p>
          <p><a href="#" onClick={this.handleClick.bind(this)}>Click here</a> to toggle the menu.</p>
        </OffCanvasBody>
        <OffCanvasMenu className={styles.menuClass}>
          <p>Placeholder content.</p>
          <ul>
            <li>Link 1</li>
            <li>Link 2</li>
            <li>Link 3</li>
            <li>Link 4</li>
            <li>Link 5</li>
            <li><a href="#" onClick={this.handleClick.bind(this)}>Toggle Menu</a></li>
          </ul>
        </OffCanvasMenu>
      </OffCanvas>
    );
  }

  handleClick() {
    // toggles the menu opened state
    this.setState({ isMenuOpened: !this.state.isMenuOpened });
  }

}

Components

OffCanvas

This is the main component you will be using to compose your body and menu.

Prop Type Default Description
width number 250 The width of the menu and off-canvas transition.
transitionDuration number 250 The time in ms for the transition.
isMenuOpened bool false Is the menu opened or not.
position string “left” Position the menu to the “left” or “right”.

OffCanvasBody

Prop Type Default Description
width number 250 The width of the menu and off-canvas transition.
transitionDuration number 250 The time in ms for the transition.
isMenuOpened bool false Is the menu opened or not.
position string “left” Position the menu to the “left” or “right”.
className string Custom className for the element.
style object CSS style object for the element.

OffCanvasMenu

Prop Type Default Description
width number 250 The width of the menu and off-canvas transition.
transitionDuration number 250 The time in ms for the transition.
isMenuOpened bool false Is the menu opened or not.
position string “left” Position the menu to the “left” or “right”.
className string Custom className for the element.
style object CSS style object for the element.

Related Repositories

react-offcanvas

react-offcanvas

:art: Off-canvas menus for React. ...


Top Contributors

vutran

Dependencies

package version
react ^0.14.7
dev babel-cli ^6.6.5
babel-core ^6.6.5
babel-eslint ^5.0.0
babel-loader ^6.2.4
babel-plugin-react-transform ^2.0.2
babel-plugin-transform-property-literals ^6.5.0
babel-plugin-transform-remove-console ^6.5.0
babel-plugin-transform-remove-debugger ^6.5.0
babel-preset-es2015 ^6.6.0
babel-preset-react ^6.5.0
babel-preset-stage-0 ^6.5.0
css-loader ^0.23.1
eslint ^2.3.0
eventsource-polyfill ^0.9.6
express ^4.13.4
react-dom ^0.14.7
react-transform-hmr ^1.0.4
rimraf ^2.5.2
style-loader ^0.13.0
webpack ^1.12.14
webpack-dev-middleware ^1.5.1
webpack-hot-middleware ^2.9.0

Releases

-   v0.3.1 zip tar
-   v0.3.0 zip tar
-   v0.2.0 zip tar
-   v0.1.0 zip tar
-   v0.0.1 zip tar