Coder Social home page Coder Social logo

wysher / react-offcanvas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vutran/react-offcanvas

0.0 0.0 0.0 1.78 MB

:art: Off-canvas menus for React.

Home Page: http://vutran.github.io/react-offcanvas

License: MIT License

JavaScript 100.00%

react-offcanvas's Introduction

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"}
  effect={"overlay"}
>
  <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}
        effect={"parallax"}
        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".
effect string "push" Choose menu effect. "push", "overlay" or "parallax".

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.

react-offcanvas's People

Contributors

vutran 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.