Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-pro-sidebar

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-pro-sidebar

high level and customizable side navigation

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
44K
decreased by-19.72%
Maintainers
1
Weekly downloads
 
Created
Source

React Pro Sidebar

npm License Peer Download Stars

React Pro Sidebar provides a set of components for creating high level and customizable side navigation

Old versions

  • v0.x

Live Preview

Screenshot

react-pro-sidebar

Installation

yarn

yarn add react-pro-sidebar

npm

npm install react-pro-sidebar

Usage

import { Sidebar, Menu, MenuItem, SubMenu } from 'react-pro-sidebar';

<Sidebar>
  <Menu>
    <SubMenu label="Charts">
      <MenuItem> Pie charts </MenuItem>
      <MenuItem> Line charts </MenuItem>
    </SubMenu>
    <MenuItem> Documentation </MenuItem>
    <MenuItem> Calendar </MenuItem>
  </Menu>
</Sidebar>;

Using React Router

You can make use of the component prop to integrate React Router link

Example Usage

import { Sidebar, Menu, MenuItem } from 'react-pro-sidebar';
import { Link } from 'react-router-dom';

<Sidebar>
  <Menu
    menuItemStyles={{
      button: {
        // the active class will be added automatically by react router
        // so we can use it to style the active menu item
        [`&.active`]: {
          backgroundColor: '#13395e',
          color: '#b6c8d9',
        },
      },
    }}
  >
    <MenuItem component={<Link to="/documentation" />}> Documentation</MenuItem>
    <MenuItem component={<Link to="/calendar" />}> Calendar</MenuItem>
    <MenuItem component={<Link to="/e-commerce" />}> E-commerce</MenuItem>
  </Menu>
</Sidebar>;

Customization

We provide for each component rootStyles prop that can be used to customize the styles

its recommended using utility classes (sidebarClasses, menuClasses) for selecting target child nodes

Example usage

<Sidebar
  rootStyles={{
    [`.${sidebarClasses.container}`]: {
      backgroundColor: 'red',
    },
  }}
>
  // ...
</Sidebar>

For Menu component, in addition to rootStyles you can also use menuItemStyles prop for customizing all MenuItem & SubMenu components and their children

Type definition

interface MenuItemStyles {
  root?: ElementStyles;
  button?: ElementStyles;
  label?: ElementStyles;
  prefix?: ElementStyles;
  suffix?: ElementStyles;
  icon?: ElementStyles;
  subMenuContent?: ElementStyles;
  SubMenuExpandIcon?: ElementStyles;
}

type ElementStyles = CSSObject | ((params: MenuItemStylesParams) => CSSObject | undefined);

Example usage

<Sidebar>
  <Menu
    menuItemStyles={{
      button: ({ level, active, disabled }) => {
        // only apply styles on first level elements of the tree
        if (level === 0)
          return {
            color: disabled ? '#f5d9ff' : '#d359ff',
            backgroundColor: active ? '#eecef9' : undefined,
          };
      },
    }}
  >
    //...
  </Menu>
</Sidebar>

API

ComponentPropTypeDescriptionDefault
SidebardefaultCollapsedbooleanInitial collapsed statusfalse
collapsedbooleanSidebar collapsed statefalse
toggledbooleanSidebar toggled statefalse
widthnumber | stringWidth of the sidebar270px
collapsedWidthnumber | stringWidth of the sidebar on collapsed state80px
backgroundColorstringSet background color for sidebarrgb(249, 249, 249, 0.7)
imagestringUrl of the image to use in the sidebar background, need to apply transparency to background color -
breakPointxs | sm | md | lg | xl | xxl | allSet when the sidebar should trigger responsiveness behavior -
customBreakPointstringSet custom breakpoint value, this will override breakPoint prop -
transitionDurationnumberDuration for the transition in milliseconds to be used in collapse and toggle behavior300
rtlbooleanRTL directionfalse
rootStylesCSSObjectApply styles to sidebar element-
onBackdropClick() => voidCallback function to be called when backdrop is clicked-
MenucloseOnClickbooleanIf true and sidebar is in collapsed state, submenu popper will automatically close on MenuItem clickfalse
menuItemStylesMenuItemStylesApply styles to MenuItem and SubMenu components and their children -
renderExpandIcon(params: { level: number; collapsed: boolean; disabled: boolean; active: boolean; open: boolean; }) => React.ReactNodeRender method for customizing submenu expand icon-
transitionDurationnumberTransition duration in milliseconds to use when sliding submenu content300
rootStylesCSSObjectApply styles from Menu root element-
MenuItemiconReactNodeIcon for the menu item -
activebooleanIf true, the component is activefalse
disabledbooleanIf true, the component is disabled -
prefixReactNodeAdd a prefix to the menuItem -
suffixReactNodeAdd a suffix to the menuItem -
componentstring | ReactElementA component used for menu button node, can be string (ex: 'div') or a component -
rootStylesCSSObjectApply styles to MenuItem element-
SubMenulabelstring | ReactNodeLabel for the submenu -
iconReactNodeIcon for submenu-
defaultOpenbooleanSet if the submenu is open by defaultfalse
openbooleanSet open value if you want to control the state-
activebooleanIf true, the component is activefalse
disabledbooleanIf true, the component is disabled -
prefixReactNodeAdd a prefix to the submenu -
suffixReactNodeAdd a suffix to the submenu -
onOpenChange(open: boolean) => voidCallback function called when submenu state changes-
componentstring | React.ReactElementA component used for menu button node, can be string (ex: 'div') or a component -
rootStylesCSSObjectApply styles to SubMenu element-

License

MIT © Mohamed Azouaoui

Keywords

FAQs

Package last updated on 03 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc