项目作者: HamzaMhadbi

项目描述 :
Simple react side menu
高级语言: JavaScript
项目地址: git://github.com/HamzaMhadbi/simple-side-menu.git
创建时间: 2018-11-29T03:56:25Z
项目社区:https://github.com/HamzaMhadbi/simple-side-menu

开源协议:

下载


Simple Side Menu

a simple Side menu component written only in React.js and CSS3.

Important: This component must be used with React Router V4.

Demo

Take a look at the demo

Installation

We need to install react router dom firstly if is it not installed

  1. npm install react-router-dom --save
  1. npm install simple-side-menu --save

Usage

menu.js

  1. export default [
  2. {
  3. title: "Dashboard",
  4. iconClassName: "fa fa-dashboard",
  5. icon: "",
  6. to: "/simple-side-menu"
  7. },
  8. {
  9. title: "Group",
  10. isCollapsible: true,
  11. icon: "group",
  12. subItems: [
  13. {
  14. title: "New group",
  15. icon: "group_add",
  16. to: "/simple-side-menu/group/new"
  17. },
  18. {
  19. title: "New person",
  20. icon: "person_add",
  21. to: "/simple-side-menu/group/person/new"
  22. }
  23. ]
  24. },
  25. {
  26. title: "Notifications",
  27. icon: "notifications",
  28. subItems: [
  29. {
  30. title: "Active",
  31. icon: "notifications_active",
  32. to: "/simple-side-menu/notifications/active"
  33. },
  34. {
  35. title: "Off",
  36. icon: "notifications_off",
  37. to: "/simple-side-menu/notifications/off"
  38. }
  39. ]
  40. },
  41. {
  42. title: "Settings",
  43. isCollapsible: true,
  44. iconClassName: "ion-gear-b",
  45. subItems: [
  46. {
  47. title: "Profile",
  48. icon: "person",
  49. to: "/simple-side-menu/settings/profile"
  50. },
  51. {
  52. title: "Applications",
  53. icon: <i className="material-icons">apps</i>,
  54. to: "/simple-side-menu/settings/apps"
  55. }
  56. ]
  57. },
  58. {
  59. title: "Sign out",
  60. icon: <i className="ion-log-out" ></i>,
  61. to: "/simple-side-menu/sign-out"
  62. }
  63. ];

Menu.js

  1. import React, { PureComponent } from "react";
  2. import { BrowserRouter as Router, Route } from "react-router-dom";
  3. import { Container, Header, SideMenu } from "simple-side-menu";
  4. import MENU_ITEMS from "./menu";
  5. class Menu extends PureComponent {
  6. state = {
  7. isOpen: true
  8. };
  9. toggleMenu = () => {
  10. this.setState(prevState => ({
  11. isOpen: !prevState.isOpen
  12. }));
  13. };
  14. render() {
  15. return (
  16. <Router>
  17. <Container>
  18. <SideMenu
  19. isOpen={this.state.isOpen}
  20. header={<Header logo="../public/logo.png" title="MENU_TITLE" ></SideMenu>}
  21. items={MENU_ITEMS}
  22. />
  23. <div className="main">
  24. <button onClick={this.toggleMenu}>Toggle Me</button>
  25. <Route exact path="/" component={Dashboard} ></Route>
  26. <Route path="/group/new" component={AddGroup} ></Route>
  27. <Route path="/group/person/new" component={AddPerson} ></Route>
  28. <Route
  29. path="/notifications/active"
  30. component={NotificationsActive}
  31. ></Route>
  32. <Route path="/notifications/off" component={NotificationsOff} ></Route>
  33. <Route path="/settings/profile" component={Profile} ></Route>
  34. <Route path="/settings/apps" component={Application} ></Route>
  35. <Route path="/sign-out" component={LogOut} ></Route>
  36. </div>
  37. </Container>
  38. </Router>
  39. );
  40. }
  41. }
  42. const RoutePath = ({ path }) => <h4>{path}</h4>;
  43. const Dashboard = () => <RoutePath path="/dashboard" ></RoutePath>;
  44. const AddGroup = () => <RoutePath path="/group/new" ></RoutePath>;
  45. const AddPerson = () => <RoutePath path="/group/person/new" ></RoutePath>;
  46. const NotificationsActive = () => <RoutePath path="/notifications/active" ></RoutePath>;
  47. const NotificationsOff = () => <RoutePath path="/notifications/off" ></RoutePath>;
  48. const Profile = () => <RoutePath path="/settings/profile" ></RoutePath>;
  49. const Application = () => <RoutePath path="/settings/apps" ></RoutePath>;
  50. const LogOut = () => <RoutePath path="/sign-out" ></RoutePath>;
  51. export default Menu;

API

<SideMenu ></SideMenu>

Prop Type Default Description
isOpen bool true Specify if the side menu must be opened.
items array Required Property for the configuration of the component SideMenu. check the menu.js
header elem null Property for the side menu header. you can use Header component or any JSX element.
isExpandable bool false This property make possibile usage of the expanded mode. don’t use it with toggle menu fonctionnality.
defaultIconClassName string material-icons Property for default icon className used for menu item and sub menu item, the Allowed values (material-icons, fa).

<Header ></Header>

Prop Type Default Description
to string / Path of home page
logo string null The source path for the logo of application
title string null The title of the side menu
headerClassName string nav-container__header the Header className.
logoClassName string nav-container__logo The Logo className.
titleClassName string nav-container__title The title className.

Styling

  1. .nav-container {
  2. background-color: #db3d44;
  3. }
  4. .sub-menu {
  5. background-color: #ff6666;
  6. }
  7. .sub-menu__item--active,
  8. .sub-menu__item:hover,
  9. .sub-menu__item:visited,
  10. .menu-item--active,
  11. .menu-item > *:first-child:hover {
  12. background-color: #af3136;
  13. }
  14. .nav-container__header,
  15. .side-menu,
  16. .menu-item {
  17. box-shadow: 0 1px 0 #fff !important;
  18. -webkit-box-shadow: 0 1px 0 #fff !important;
  19. -moz-box-shadow: 0 1px 0 #fff !important;
  20. }