react-motion-drawer-alt
Version:
Navigation drawer built with the awesome react-motion and react-hammerjs
108 lines (83 loc) • 4.08 kB
Markdown
<h1 align="center">react-motion-drawer</h1>
<p align="center">
<a href="#example">Example</a> |
<a href="#usage">Usage</a> |
<a href="#api">API</a> |
<a href="CHANGELOG.md">Changelog</a>
<br><br>
<img align="center" src="./media/drawer.gif">
</p>
> Navigation drawer built with the awesome [react-motion][rm] by [@chenglou][c] and [react-hammerjs][rh] by [@JedWatson][j]
[](https://badge.fury.io/js/react-motion-drawer)
A live demo is available [here](https://react-motion-drawer.netlify.com/)!
To run the example locally, run:
```bash
$ yarn
$ yarn serve
```
Via npm:
```
npm install react-motion-drawer
```
```js
import Drawer from 'react-motion-drawer';
```
```jsx
<Drawer open={false} onChange={onChange}>
<ul>
<li>Home</li>
<li>About</li>
<li>Settings</li>
</ul>
</Drawer>
```
If you want the drawer on the right side of the screen you need the following css.
```css
body {
overflow: hidden;
}
```
You can hook into the animation by passing a function as the child component.
```jsx
<Drawer open={false} width={300} onChange={onChange}>
{ val =>
<ul style={{ opacity: 300 / val }}>
<li>Home</li>
<li>About</li>
<li>Settings</li>
</ul>
}
</Drawer>
```
| Prop Name | type | default | description |
|----------------------|---------|--------------------------|----------------------------------------------------------|
| zIndex | number | `10000` | z-index of the drawer |
| noTouchOpen | bool | `false` | can a user pan to open |
| noTouchClose | bool | `false` | can a user pan to close |
| onChange | func | `() => {}` | called when the drawer is open |
| drawerStyle | object | `null` | additional drawer styles |
| className | object | `null` | additional drawer className |
| overlayClassName | object | `null` | additional overlay className |
| config | object | `null` | configuration of the react-motion animation |
| open | bool | `false` | states if the drawer is open |
| width | number | `300` | width of the drawer |
| height | number | `100%` | height of the drawer |
| handleWidth | number | `20` | width of the handle |
| peakingWidth | number | `50` | width that the drawer peaks on press |
| panTolerance | number | `50` | tolerance until the drawer starts to move |
| right | bool | `false` | drawer on the right side of the screen |
| overlayColor | string | `'rgba(0, 0, 0, 0.4)'` | color of the overlay |
| fadeOut | bool | `false` | fade out |
| offset | number | `0` | offset of the drawer |
MIT © [Christoph Hermann](http://stoeffel.github.io)
[]: https://github.com/chenglou/react-motion
[]: https://github.com/JedWatson/react-hammerjs
[]: https://github.com/chenglou
[]: https://github.com/JedWatson