Giter VIP home page Giter VIP logo

react-sidenav's Introduction

react-sidenav

Build Status

A React Component that makes it easier to automatically build vertical nav menus or compose them from within your React components.

alt tag

Usage

    npm install --save-dev react-sidenav

1.Via Configuration - you can create a sidenav instance using a navigation configuration as per below:

import { SideNav, Nav } from 'react-sidenav';


var navi = [
    { id: 'dashboard', icon: 'fa fa-dashboard' , text: 'Dashboard'},
    { id: 'products', icon: 'fa fa-cube', text: 'Products' ,
        navlist: [
          { icon: 'fa fa-desktop', id: 'manage' ,text: 'Manage Product' },
          { icon: 'fa fa-cog', id: 'suppliers' ,text: 'Suppliers' }
        ]
    },
    { id: 'inventory', icon: 'fa fa-database' ,text: 'Inventory'},
    { id: 'deliveries', icon: 'fa fa-truck' ,text: 'Deliveries'},
    { id: 'reports', icon: 'fa fa-bar-chart' ,text: 'Reports' }
];

//render it
<SideNav selected={selected} navs={navi} onSelection={updateSelection}/>

2.Via Manual Composition - this is another option. The tree should be as follows:

    var SideNav = require("react-sidenav");
    React.render(
        <SideNav selected='nav1'>
            <Nav id='nav1' text='Nav1'/>
            <Nav id='nav2' text='Nav2'/>
        </SideNav>,
           document.getElementById("sidenav-container")
        );

Props

SideNav props accepts the following values

Property Description Example
onSelection Function called when an item is clicked.
selected String of the selected item.
children Nav element if via composition
navs nav config if via configuration

onSelection

The SideNav component is stateless. That means that each click will call onSelection and you need to pass again the new selected props.

    const SideNavComponent = Rect.createClass({

        getInitialState() {
            return { selected: 'dashboard' };
        },
        onSelection(selection) {
            this.setState({selected: selection.id});
            //or trigger a dispatch here
        },
        render() {
            return <SideNav selected={this.state.selected} onSelection={this.onSelection} />
        }

    });

Todo

  1. Custom Item Renderers
  2. Compact
  3. Notification

Development

Edit dev.js and start webpack-dev-server

npm run dev

Contributing

Pull requests are welcome. For me to accept a pull request, please include a test as well under test folder.

License

MIT

react-sidenav's People

Contributors

wmira avatar hagbarth avatar

Watchers

Alex Kovalevych avatar James Cloos 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.