npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-side-bar

v1.0.4

Published

React Side Bar Component

Downloads

233

Readme

React Sidebar Component

Donate npm npm npm

Demo

Check the demo.

Installation

You can install react-side-bar by executing this command:

npm install --save react-side-bar

When the installation process ends, you are ready to import react-side-bar to your project.

How to Use

To use react-side-bar you have to import the component in your project:

import Sidebar from 'react-side-bar';

You can add more properties to react-side-bar, see the list of available properties in Properties section.

Adding a Button to Open the Sidebar

If you want to add a button for opening and closing react-side-bar (hamburguer menu for example), you need to reference the state of the sidebar, e.g.:

constructor(props) {
  this.state = {
    opened: false // (or true)
  }
}

This way, there are two mandatory methods you need to define

  • onOpen (function)
  • onClose (function)

The purpose of this properties is to keep the opened property updated. To achieve this, you need to trigger setState to change the value of the opened property. For exmaple:

Close:

() => {
  this.setState({ opened: false });
}

Open:

() => {
  this.setState({ opened: true });
}

Moreover you can use this functions to add some extra functionality for your application, such as triggers, when opening or closing react-side-bar.

Once you have the object with properties, you can init the component Sidebar.

<Sidebar
	bar={<div>Amazing Sidebar</div>}
	opened={this.state.opened}
	onClose={() => {
		this.setState({ opened: false })
	}}
	onOpen={() => {
		this.setState({ opened: true })
	}}
	size={300}
/>

Output:

To add content for the application you just have to add children inside Sidebar.

<Sidebar>
	<div className='topBar'>SIDEBAR</div>
	<div className='main'>Main</div>
</SideBar>

With style and some improvements, it could be like this:

With react-side-bar you can pass the topBar component (passed as a children in the example above) as a property to change the effect when opening.

<Sidebar
	bar={<div>Amazing Sidebar</div>}
	topBar={<div className='topBar'>SIDEBAR</div>}
	size={300}
>
	<div className='main'>
		Main
	</div>
</SideBar>

Properties

duration (number)

Default: 150

This is the time it takes to open or close the sidebar.

fx (string)

Default: cubic-bezier(0, 1, 0.85, 1)

This is the effect of the sidebar when opening, o can test the default effect in http://cubic-bezier.com or perhaps add another different effect. Effects

mode (string: Sidebar.BEHIND | Sidebar.OVER | Sidebar.PUSH)

Default: Sidebar.OVER

This property allows to change the opening mode of the sidebar, you can choose from three different:

  • Sidebar.BEHIND
  • Sidebar.OVER
  • Sidebar.PUSH

opened (boolean: true | false)

Default: false

This property shows or hides the sidebar. Depending on the sidebar state, its wrapper element features class="side-bar-content opened" or class="side-bar-content closed" class names.

side (string: Sidebar.LEFT | Sidebar.RIGHT)

Default: Sidebar.LEFT

This property allows to change the side of the opening of the sidebar.

size (number)

Default: 256

This property allows to change the width of the sidebar.

tolerance (number)

Default: 70

This property sets the tolerance to calculate the sensibility of the automatic opening of the sidebar.

touch (boolean: true | false)

Default: true

This property allows to enable or disable touch events. If its value is false you have to add another alternative method to open sidebar as a hamburguer menu.

touchSize (number)

Default: 80

With this property you can set the size of the touchable zone to start dragging the sidebar. The value of 0 means that you can drag the sidebar everywhere.

veilStyle (object)

Default: {}

You can define the final style of the veil over the content of application when the sidebar is open. While the sidebar is opening, this style have a opacity depending of the veil opening progress.

You can also use CSS to style the veil by applying styles to .side-bar-veil.

Contribution

If you want to do your own changes, share with community and contribute with the project:

git clone https://github.com/mschez/react-side-bar.git
cd react-side-bar
npm install
npm run dev

Now you can check the demo in http://localhost:3000

Don't forget to check touch actions using the developer tools devices emulation.

Important

If you like this project, don't forget buy me a beer. ¡Thank you!

Donate