1.22.1 • Published 4 months ago

@asphalt-react/sidebar v1.22.1

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
4 months ago

Sidebar

Sidebar is used to display vertical primary navigation. It represents a list of links that can either take the user to another page or to another section on same page.

It is contructed using 3 sections:

  1. Header: Application logo can be added using the logo prop.
  2. Navigation: Contains all the links for navigation. Links can be added using NavItem, <NavItemMenu> and <SubItem/> component.
  3. Footer: Avatar can be used here for user profile and ActionList to add some extra actions. They can be passed using footer prop.

Sidebar is fully responsive and can be added to the application in several variants which are linear, nested(single level), links with/without icon, links grouped together based on related category. You can use the component <SubItem/> inside <NavItemMenu> to achieve nested links. For grouped links in sidebar, use component <NavItem/> or <NavItemMenu/> inside <NavGroup/>. To set an item selected in sidebar, we suggest you to update state URL and pass active prop to the respective link component. Sidebar takes the height of the parent in which its rendered.

Usage

import Sidebar, { Nav, NavItem } from "@asphalt-react/sidebar"

function App () {

  return (
    <Sidebar>
      <Nav>
        <NavItem tagProps={{ href: "/" }} active>Home</NavItem>
        <NavItem tagProps={{ href: "/Dashboard" }}>Dashboard</NavItem>
      </Nav>
    </Sidebar>
  );
}

export default App;

Props

children

React node to render in the Sidebar content

typerequireddefault
nodetrueN/A

logo

Logo to be rendered inside Sidebar header

typerequireddefault
nodefalseN/A

footer

Content to display at the bottom of Sidebar

typerequireddefault
nodefalseN/A

onSelect

onSelect is called when users select an item.

The argument is an object of shape

{
  event: React synthetic event
}

Note: This prop has been deprecated & will be removed in the next major version

typerequireddefault
funcfalseN/A

Nav

This component is used to render container for all the nav links in Sidebar.

Props

children

React nodes to render in the Nav content

typerequireddefault
nodetrueN/A

NavItem

Using NavItem component, links can be added to the Sidebar. Navitem renders an <a> tag as default.

⚠️ The NavItem component is different from the one in @asphalt-react/appbar

Props

children

React node to be shown as caption for the link

typerequireddefault
anyfalseN/A

as

Html element/React component to be rendered

typerequireddefault
elementTypefalse"a"

tagProps

Props for the NavItem element being rendered. Attributes like href, name can be passed

typerequireddefault
objectfalse{ href: "#" }

active

Determines if NavItem is currently selected

typerequireddefault
boolfalseN/A

qualifier

Renders an icon before the NavItem caption

typerequireddefault
elementfalsenull

NavItemMenu

This component is used to display a menu in the nav. It supports single level nesting. Sub items link can added inside menu using <SubItem/> component.

Props

children

React node to render as subitems in the NavMenu content

typerequireddefault
anyfalseN/A

as

Html element/React component to be rendered

typerequireddefault
elementTypefalse"a"

tagProps

Props for the NavItemMenu element being rendered. Attributes like href, name can be passed

typerequireddefault
objectfalse{ href: "#" }

caption

Caption for NavItemMenu

typerequireddefault
anyfalseN/A

active

Determines if item is currently selected

typerequireddefault
boolfalseN/A

qualifier

Renders an icon before the NavItemMenu caption

typerequireddefault
elementfalsenull

SubItem

This component is used to renders subitem link inside NavItemMenu

Props

children

React node to render as text content for the link

typerequireddefault
nodefalseN/A

as

Html element/React component to be rendered

typerequireddefault
elementTypefalse"a"

active

Determines if item is currently selected

typerequireddefault
boolfalseN/A

tagProps

Props for the SubItem element being rendered. Attributes like href, name can be passed

typerequireddefault
objectfalse{ href: "#" }

qualifier

Renders an icon before the SubItem caption

typerequireddefault
elementfalseN/A

NavGroup

Using NavGroup component, you can group together a list of nav items based on related category. Links can be provided using component <NavItem/> or <NavItemMenu/> passed inside this component as children and group heading using prop heading.

Props

children

React nodes to render as nav items in the NavGroup

typerequireddefault
nodetrueN/A

heading

Heading of the NavGroup

typerequireddefault
nodetrueN/A