Giter Club home page Giter Club logo

react-sider's Introduction

react-sider

npm v npm dm

Inspired by Ant Design Pro.

Lightweight Ant Design Pro like <Sider /> component integrated with Ant Design Menu.

Features

  • Zero work on CSS.
  • Minimum configuration and 100% data driven.
  • Easy integration with any React app architectures. Only depends on react, react-router-dom, lodash & antd.
  • Native nested menu and pathname support.
  • Automatical menu openKeys & selectKeys match based on current page pathname.

Installation

yarn add react-sider react react-router-dom lodash antd

Preview

Usage

Sider

Property Description Type Default
className className of container string ''
style style of container object { }
appName name of application string ''
appLogo img src of application logo string ''
appBaseUrl href of sider header string '/'
width sider container width number 256
menuData data of sider menu arrayOf(MenuItem) [ ]
pathname current page pathname string '/'

MenuItem

Property Description Type Default
name menu item name in text string -
path menu item path (see below example for details) string -
icon menu item antd icon string -
children sub menu items arrayOf(MenuItem) -

Example

import ReactSider from 'react-sider';
import 'react-sider/lib/index.css';
import logo from 'assets/logo.svg';

const menuData = [{
  // MenuItem name
  name: 'Dashboard',
  // MenuItem icon (antd icon)
  icon: 'dashboard',
  // MenuItem relative path
  path: 'dashboard',
  // SubMenu
  children: [{
    name: 'Analysis',
    path: 'analysis',
    children: [{
      name: 'Real-time',
      path: 'realtime',
    }, {
      name: 'Offline',
      path: 'offline',
    }],
  },
  {
    name: 'Monitor',
    path: 'monitor',
  },
  {
    name: 'Workplace',
    path: 'workplace',
  }],
}, {
  name: 'Marketing',
  icon: 'table',
  path: 'marketing',
}, {
  name: 'Settings',
  icon: 'setting',
  path: 'settings',
  children: [{
    name: 'Users Management',
    path: 'users',
  }],
}];

const Sider = () => (
  <ReactSider
    appName="React App Pro"
    appLogo={logo}
    menuData={menuData}
    // better to sync pathname with the router in your application
    pathname={this.props.location.pathname}
  />
)

export default Sider;

Notes

  • react-sider will automatically format nested menu path with / based on menuData structure.
  • Remember to config less-loader within your application building process since react-sider directly imports antd components styles.

react-sider's People

Contributors

alanwei avatar alanweilazada avatar

Watchers

 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.