|
1 | | -import React from 'react'; |
| 1 | +import React, { PropTypes } from 'react'; |
2 | 2 | import { themr } from 'react-css-themr'; |
3 | 3 | import classnames from 'classnames'; |
4 | | -import ActivableRenderer from '../hoc/ActivableRenderer'; |
5 | | -import Overlay from '../overlay'; |
| 4 | +import { DRAWER } from '../identifiers.js'; |
| 5 | +import ActivableRenderer from '../hoc/ActivableRenderer.js'; |
| 6 | +import InjectOverlay from '../overlay/Overlay.js'; |
6 | 7 |
|
7 | | -const Drawer = ({ active, children, className, onOverlayClick, theme, type }) => { |
8 | | - const _className = classnames([theme.drawer, theme[type]], { |
9 | | - [theme.active]: active |
10 | | - }, className); |
| 8 | +const factory = (Overlay) => { |
| 9 | + const Drawer = ({ active, children, className, onOverlayClick, theme, type }) => { |
| 10 | + const _className = classnames([theme.drawer, theme[type]], { |
| 11 | + [theme.active]: active |
| 12 | + }, className); |
11 | 13 |
|
12 | | - return ( |
13 | | - <Overlay active={active} onClick={onOverlayClick}> |
14 | | - <div data-react-toolbox='drawer' className={_className}> |
15 | | - <aside className={theme.content}> |
16 | | - {children} |
17 | | - </aside> |
18 | | - </div> |
19 | | - </Overlay> |
20 | | - ); |
21 | | -}; |
| 14 | + return ( |
| 15 | + <Overlay active={active} onClick={onOverlayClick}> |
| 16 | + <div data-react-toolbox='drawer' className={_className}> |
| 17 | + <aside className={theme.content}> |
| 18 | + {children} |
| 19 | + </aside> |
| 20 | + </div> |
| 21 | + </Overlay> |
| 22 | + ); |
| 23 | + }; |
22 | 24 |
|
23 | | -Drawer.propTypes = { |
24 | | - active: React.PropTypes.bool, |
25 | | - children: React.PropTypes.node, |
26 | | - className: React.PropTypes.string, |
27 | | - onOverlayClick: React.PropTypes.func, |
28 | | - theme: React.PropTypes.shape({ |
29 | | - active: React.PropTypes.string.isRequired, |
30 | | - content: React.PropTypes.string.isRequired, |
31 | | - drawer: React.PropTypes.string.isRequired, |
32 | | - left: React.PropTypes.string.isRequired, |
33 | | - right: React.PropTypes.string.isRequired |
34 | | - }), |
35 | | - type: React.PropTypes.oneOf(['left', 'right']) |
36 | | -}; |
| 25 | + Drawer.propTypes = { |
| 26 | + active: PropTypes.bool, |
| 27 | + children: PropTypes.node, |
| 28 | + className: PropTypes.string, |
| 29 | + onOverlayClick: PropTypes.func, |
| 30 | + theme: PropTypes.shape({ |
| 31 | + active: PropTypes.string.isRequired, |
| 32 | + content: PropTypes.string.isRequired, |
| 33 | + drawer: PropTypes.string.isRequired, |
| 34 | + left: PropTypes.string.isRequired, |
| 35 | + right: PropTypes.string.isRequired |
| 36 | + }), |
| 37 | + type: PropTypes.oneOf(['left', 'right']) |
| 38 | + }; |
| 39 | + |
| 40 | + Drawer.defaultProps = { |
| 41 | + active: false, |
| 42 | + className: '', |
| 43 | + type: 'left' |
| 44 | + }; |
37 | 45 |
|
38 | | -Drawer.defaultProps = { |
39 | | - active: false, |
40 | | - className: '', |
41 | | - type: 'left' |
| 46 | + return ActivableRenderer()(Drawer); |
42 | 47 | }; |
43 | 48 |
|
44 | | -export default themr('ToolboxDrawer')(ActivableRenderer()(Drawer)); |
| 49 | +const Drawer = factory(InjectOverlay); |
| 50 | +export default themr(DRAWER)(Drawer); |
| 51 | +export { factory as drawerFactory }; |
| 52 | +export { Drawer }; |
0 commit comments