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

react-sub-sidenav

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-sub-sidenav

React SideNav

  • 0.4.21
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

react-sidenav build status Coverage Status

NPM

React SideNav

Demo: https://trendmicro-frontend.github.io/react-sidenav

Installation

  1. Install the latest version of react and react-sidenav:
npm install --save react @trendmicro/react-sidenav
  1. At this point you can import @trendmicro/react-sidenav and its styles in your application as follows:
import SideNav, { Toggle, Nav, NavItem, NavIcon, NavText } from '@trendmicro/react-sidenav';

// Be sure to include styles at some point, probably during your bootstraping
import '@trendmicro/react-sidenav/dist/react-sidenav.css';

Usage

<SideNav
    onSelect={(selected) => {
        // Add your code here
    }}
>
    <SideNav.Toggle />
    <SideNav.Nav defaultSelected="home">
        <NavItem eventKey="home">
            <NavIcon>
                <i className="fa fa-fw fa-home" style={{ fontSize: '1.75em' }} />
            </NavIcon>
            <NavText>
                Home
            </NavText>
        </NavItem>
        <NavItem eventKey="charts">
            <NavIcon>
                <i className="fa fa-fw fa-line-chart" style={{ fontSize: '1.75em' }} />
            </NavIcon>
            <NavText>
                Charts
            </NavText>
            <NavItem eventKey="charts/linechart">
                <NavText>
                    Line Chart
                </NavText>
            </NavItem>
            <NavItem eventKey="charts/barchart">
                <NavText>
                    Bar Chart
                </NavText>
            </NavItem>
        </NavItem>
    </SideNav.Nav>
</SideNav>

React Router v4 with React v16

<Router>
    <Route render={({ location, history }) => (
        <React.Fragment>
            <SideNav
                onSelect={(selected) => {
                    const to = '/' + selected;
                    if (location.pathname !== to) {
                        history.push(to);
                    }
                }}
            >
                <SideNav.Toggle />
                <SideNav.Nav defaultSelected="home">
                    <NavItem eventKey="home">
                        <NavIcon>
                            <i className="fa fa-fw fa-home" style={{ fontSize: '1.75em' }} />
                        </NavIcon>
                        <NavText>
                            Home
                        </NavText>
                    </NavItem>
                    <NavItem eventKey="devices">
                        <NavIcon>
                            <i className="fa fa-fw fa-device" style={{ fontSize: '1.75em' }} />
                        </NavIcon>
                        <NavText>
                            Devices
                        </NavText>
                    </NavItem>
                </SideNav.Nav>
            </SideNav>
            <main>
                <Route path="/" exact component={props => <RootComponent />} />
                <Route path="/home" component={props => <Home />} />
                <Route path="/devices" component={props => <Devices />} />
            </main>
        </React.Fragment>
    )}
    />
</Router>

Close the side navigation menu when clicking outside

You can find a click-outside React component (https://github.com/tj/react-click-outside/blob/master/index.js) and do something below:

<ClickOutside
    onClickOutside={() => {
        this.setState({ expanded: false });
    }}
>
    <SideNav
        expanded={this.state.expanded}
        onToggle={(expanded) => {
            this.setState({ expanded });
        }}
    >
        <SideNav.Toggle />
        <SideNav.Nav defaultSelected="home">
            <NavItem eventKey="home">
                <NavIcon>
                    <i className="fa fa-fw fa-home" style={{ fontSize: '1.75em' }} />
                </NavIcon>
                <NavText>
                    Home
                </NavText>
            </NavItem>
        </SideNav.Nav>
    </SideNav>
</ClickOutside>

API

Properties

SideNav
NameTypeDefaultDescription
componentClasselement'nav'A custom element for this component.
disabledbooleanWhether the navigation toggle is disabled.
expandedbooleanWhether the side navigation is expanded or collapsed.
onTogglefunction(boolean)Callback fired when toggling the side navigation between expanded and collapsed state.
onSelectfunction(eventKey, event)Callback fired when a navigation item is selected.
Toggle
NameTypeDefaultDescription
componentClasselement'button'A custom element for this component.
disabledbooleanfalseWhether the navigation toggle is disabled.
expandedbooleanfalseWhether the side navigation is expanded or collapsed.
Nav
NameTypeDefaultDescription
componentClasselement'div'A custom element for this component.
onSelectfunction(eventKey, event)Callback fired when a navigation item is selected.
selectedanyThe selected navigation item.
defaultSelectedanyThe initially selected navigation item.
expandedbooleanfalseWhether the side navigation is expanded or collapsed.
NavItem
NameTypeDefaultDescription
componentClasselement'div'A custom element for this component.
activebooleanfalseHighlight the navigation item as active.
disabledbooleanfalseDisable the navigation item, making it unselectable.
expandedbooleanfalseWhether the navigation item is expanded or collapsed.
eventKeyany(required)Value passed to the onSelect handler, useful for identifying the selected navigation item.
onClickfunction(event)Callback fired when the navigation item is clicked.
onSelectfunction(eventKey, event)Callback fired when a navigation item is selected.
navitemClassName
navitemStyle
subnavClassName
subnavStyle
NavIcon
NameTypeDefaultDescription
childrenany
NavText
NameTypeDefaultDescription
childrenany

License

MIT

Keywords

FAQs

Package last updated on 03 Jan 2019

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