131 | {!this.props.noOverlay ?
this.overlay = c}
133 | className={overlayClass}
134 | onClick={this.closeDrawer}>
135 |
: null}
136 |
this.drawer = c}>
139 | {this.props.children}
140 |
141 |
142 | );
143 | }
144 |
145 | }
146 |
147 | ReactDrawer.propTypes = {
148 | open: PropTypes.bool.isRequired,
149 | onClose: PropTypes.func,
150 | position: PropTypes.oneOf(['top', 'bottom', 'right', 'left']),
151 | noOverlay: PropTypes.bool
152 | };
153 |
154 | export default ReactDrawer;
155 |
--------------------------------------------------------------------------------
/src/ReactDrawer.scss:
--------------------------------------------------------------------------------
1 | /*!
2 | * drawer.scss
3 | * Licensed under the MIT license
4 | *
5 | * Copyright (c) 2016 Tony Li
6 | */
7 |
8 | $size: 300px;
9 |
10 | .drawer {
11 | position: fixed;
12 | background-color: #96CA4E;
13 | -webkit-box-shadow: -5px 0px 5px -5px rgba(0,0,0,0.55);
14 | -moz-box-shadow: -5px 0px 5px -5px rgba(0,0,0,0.55);
15 | box-shadow: -5px 0px 5px -5px rgba(0,0,0,0.55);
16 | /* animate.css */
17 | -webkit-animation-duration: 0.5s; /* Chrome, Safari, Opera */
18 | animation-duration: 0.5s;
19 | }
20 |
21 | .drawer-top {
22 | top: 0;
23 | left: 0;
24 | right: 0;
25 | width: 100%;
26 | height: $size;
27 | }
28 |
29 | .drawer-bottom {
30 | bottom: 0;
31 | left: 0;
32 | right: 0;
33 | width: 100%;
34 | height: $size;
35 | }
36 |
37 | .drawer-left {
38 | top: 0;
39 | left: 0;
40 | width: $size;
41 | height: 100%;
42 | }
43 |
44 | .drawer-right {
45 | top: 0;
46 | right: 0;
47 | width: $size;
48 | height: 100%;
49 | }
50 |
51 |
52 | .hidden {
53 | display: none;
54 | }
55 |
56 | .overlay {
57 | position: fixed;
58 | top:0;
59 | left:0;
60 | width: 100%;
61 | height: 100%;
62 | background:rgba(0,0,0,.75);
63 | /* animate.css */
64 | -webkit-animation-duration: 0.4s; /* Chrome, Safari, Opera */
65 | animation-duration: 0.2s;
66 | }
67 |
--------------------------------------------------------------------------------
/src/ReactDrawer.test.js:
--------------------------------------------------------------------------------
1 | /*eslint no-unused-vars: ["error", {varsIgnorePattern: "React[Drawer]*"}]*/
2 | import React from 'react';
3 | import ReactDrawer from './ReactDrawer';
4 | import { configure, mount } from 'enzyme';
5 | import Adapter from 'enzyme-adapter-react-16';
6 |
7 | configure({ adapter: new Adapter() });
8 |
9 | describe('ReactDrawer', () => {
10 |
11 | it('should display an overlay and a drawer', () => {
12 | const wrapper = mount(
13 |