Code Monkey home page Code Monkey logo

react-sidemenu's Introduction

react-sidemenu

Lightweight side menu component written in React.js. No jQuery, just CSS3.

Features

  • Pure React.js, no external dependencies
  • Configure via JS objects or via React components
  • Packed with default ready-to-use styling
  • Easy to customize styling guide
  • Custom rendering, collapse control, right-to-left etc.
  • Flow type checking support

Usage

Install the component with NPM:

npm install react-sidemenu --save

Import the component in your React.js application:

import SideMenu from 'react-sidemenu';

Flow

If you want to have access to Flow typed components, include SideMenu.js from dist folder when installing via npm.

Styling!!!

To use default styling include side-menu.css to your project. You can find it in dist folder when installing via npm. For an idea on how to customize styling see Demo.

Demo & Examples

Demo showcasing the functionalities & code examples. In the examples we use Font Awesome icons (from a CDN).

You can run examples by yourself. Clone the repo and do:

npm install
npm start

The examples are run using Webpack development server.

Options

<SideMenu> - main component

Option Default Description
items null Property for the JS Object configuration of the component SideMenu component. Check out Demo to find out how it works.
activeItem null Preset starting active item. Also used for opening and closing menu items from code (e.g. from a button). When using this option, make sure to always keep the controlling variable (e.g. variable in state) from the parent component of the menu in sync with the actual activeItem (i.e. override onMenuItemClick and update the variable)
collapse true This property gives you the capability to enable or disable collapsing menu when other elements of the menu are clicked.
theme 'default' This sets a class for the component that you can use to apply custom styling. The class will be Side-menu-[theme_name]. Note: our default theme uses Font Awesome icons. See Demo for an detailed example.
renderMenuItemContent({ icon: icon, value: value, label: label }) null This property enables you to provide a custom render method for items. Function is passed one parameter, representing the menu item being rendered. It receives an object with attributes: icon, label and value. Demo
onMenuItemClick (value, extras) => window.location.href = '#' + value This property enables you to provide custom onClick method for items. The function gets passed the value of the clicked item and item extras (object). Demo
rtl false This property enables you to use the sidemenu in a right-to-left page. Demo
shouldTriggerClickOnParents false This property enables triggering 'onMenuItemClick' on parent items that have children.

<Item> - this component is for the non-JS object config of the menu

Option Description
value The href where you will be redirected after you click the item if no onMenuItemClick is provided. If onMenuItemClick is provided, it is the value being passed to the function call.
label Just a label.
icon This is the icon of the item. It should be a font-awesome class name.
onClick Custom on click method specific for this item (overrides onMenuItemClick).
extras Optional container for additional data.

Roadmap

Any contribution is welcome.

TODO:

  • split code into two units: JS object configuration and Component configuration
  • tests & CI support
  • refactor examples code

react-sidemenu's People

Contributors

fortunar avatar i6mi6 avatar oleksandrbohuslavskyi avatar umarovt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-sidemenu's Issues

Menu Items have not got unique keys

In my console, I keep getting this warning:

Warning: Encountered two children with the same key, Others. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted โ€” the behavior is unsupported and could change in a future version

I believe this feature enables react to efficiently update the DOM. My only concern is if something is being done about it. Or better asked: what can I do to resolve this?

Accessing PropTypes via the main React package is deprecated

Warning: Accessing PropTypes via the main React package is deprecated, and will be removed in React v16.0. Use the latest available v15.* prop-types package from npm instead. For info on usage, compatibility, migration and more, see https://fb.me/prop-types-docs

This warning direct to node_modules\react-sidemenu\lib\SideMenu.js:335

SideMenu.propTypes = {
  items: _react.PropTypes.array,
  onMenuItemClick: _react.PropTypes.func,
  renderMenuItemContent: _react.PropTypes.func,
  theme: _react.PropTypes.string,
  collapse: _react.PropTypes.bool,
  rtl: _react.PropTypes.bool,
  activeItem: _react.PropTypes.string
};

Could we update react.PropTypes to Proptypes?

Menu Items aren't collapsable

I tested a simple snippet to test the library, but figured out the items wont collapse. They are always expanded.

    <SideMenu >

            <Item label="Item 1">
                <Item label="Item 1.1">
                    <Item label="Item 1.1.1"/>
                    <Item label="Item 1.1.2" />
                </Item>
                <Item label="Item 1.2"/>
            </Item>
            <Item label="Item 2">
                <Item label="Item 2.1">
                    <Item label="Item 2.1.1"/>
                    <Item label="Item 2.1.2"/>
                </Item>
                <Item label="Item 2.2"/>
            </Item>

    </SideMenu>

Menu is by default opened

When the menu gets initially rendered with all items and sub-items active by default. It collapses upon first click.

Not unique KEYs warning

@banomaster @fortunar
Hi guys,
I found collisions of unique keys.

You use url, thinking that the it's should be unique, but in my case i have duplicates and I've got an errors because of that and:

errorScreenshot

So, i found place, you just need to concatenate item.value and some random integer value.

screenshot

Thanks.

Component is not working

I'm always getting following error while trying to use the component:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Even if I copy paste the example code, getting same issue

Allow non font awesome icons?

I'm hoping to use some non font awesome icons. Looking into the source code, I found some line like this:

<i className={`fa ${item.icon} item-icon`} />

I am wondering if it is better to remove the fa from the library code so that it will not be limited to fa icons. From the end user's perspective, if we want to use fa icons, we simply add fa .

Mouse hover effect on custom themes

The default theme has a nice mouse hover effect on the menu items, however, the custom theme example doesn't have such effect. How can I modify the custom css(less) so that the custom theme will also have such nice mouse hover effect? Thanks.

"activeItem" does'nt change display of the true selected item

If "activeItem" property is set by an external action after rendering of SideMenu, the display of new "Item" is not updated.

  1. "activeItem" property is used to intialize component.
  2. After, active Item is set by clicking on each Item of SideMenu
  3. But, if an external button change value of "activeItem" property, the SideMenu is not render and the look&feel of new active Item is not updated.

Basic example :

`import React, {Component} from 'react';
import {SideMenu, Item} from 'react-sidemenu';

export default class PortalSideMenu extends Component {
constructor(props) {
super(props);
this.changeItem = this.changeItem.bind(this);
this.state = {
activeItem:'/dashboard/requests'
}
}

changeItem(item) {
    this.setState({activeItem: item});
}

render() {
    return (
        <div>
            <button onClick={() => this.changeItem('/dashboard/tasks')}>Change</button>
            <h4>{this.state.activeItem}</h4>
            <SideMenu activeItem={this.state.activeItem}>
                <Item label="Dashboard" icon="fa-tachometer">
                    <Item label="Tasks" value="/dashboard/tasks" icon="fa-folder-open"/>
                    <Item label="Requests" value="/dashboard/requests" icon="fa-folder-open"/>
                </Item>
            </SideMenu>
        </div>
    );
}

}`

styling issue

Styles are not being applied when I use react css modules and import the component and use it without explicitly including those css files. Can you pls let me know the reason for the same. My build workflow is like this:

"scripts": {
    "build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
    "watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
    "start-js": "node scripts/start.js",
    "start": "npm-run-all -p watch-css start-js",
    "build-js": "node scripts/build.js",
    "build": "npm-run-all build-css build-js",
    "test": "node scripts/test.js --env=jsdom"
  },

Disable Items (Feature/Question)

Is there a way to disable items, so they cannot be activated?
I have menu items that are locked behind permissions and other requirements that I dont necessarily want to hide entirely.

Or alternatively, can the activation and visual change be rejected?

Import Error

I get this error when import like in the image

image

image

but the component and the app render ok when i do import SideMenu from 'react-sidemenu

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.