2016-05-29 13:54:29 +03:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-05-22 14:42:52 +03:00
|
|
|
import { themr } from 'react-css-themr';
|
|
|
|
import classnames from 'classnames';
|
2017-01-05 04:42:18 +03:00
|
|
|
import Portal from '../hoc/Portal.js';
|
2016-05-29 13:54:29 +03:00
|
|
|
import { DRAWER } from '../identifiers.js';
|
|
|
|
import ActivableRenderer from '../hoc/ActivableRenderer.js';
|
|
|
|
import InjectOverlay from '../overlay/Overlay.js';
|
2015-09-09 23:44:24 +03:00
|
|
|
|
2016-05-29 13:54:29 +03:00
|
|
|
const factory = (Overlay) => {
|
2017-01-05 04:42:18 +03:00
|
|
|
const Drawer = ({
|
|
|
|
active,
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
insideTree,
|
|
|
|
onOverlayClick,
|
|
|
|
theme,
|
|
|
|
type,
|
|
|
|
withOverlay
|
|
|
|
}) => {
|
2016-05-29 13:54:29 +03:00
|
|
|
const _className = classnames([theme.drawer, theme[type]], {
|
|
|
|
[theme.active]: active
|
|
|
|
}, className);
|
2015-11-05 13:45:23 +03:00
|
|
|
|
2017-01-05 04:42:18 +03:00
|
|
|
const content = (
|
|
|
|
<aside
|
|
|
|
data-react-toolbox='drawer'
|
|
|
|
className={_className}
|
|
|
|
children={children}
|
|
|
|
/>
|
2016-05-29 13:54:29 +03:00
|
|
|
);
|
2017-01-05 04:42:18 +03:00
|
|
|
|
|
|
|
return React.createElement(insideTree ? 'div' : Portal, {
|
|
|
|
className: theme.wrapper,
|
|
|
|
children: [
|
|
|
|
withOverlay && (
|
|
|
|
<Overlay
|
|
|
|
active={active}
|
|
|
|
onClick={onOverlayClick}
|
|
|
|
theme={theme}
|
|
|
|
themeNamespace="overlay"
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
content
|
|
|
|
]
|
|
|
|
});
|
2016-05-29 13:54:29 +03:00
|
|
|
};
|
2015-11-05 13:45:23 +03:00
|
|
|
|
2016-05-29 13:54:29 +03:00
|
|
|
Drawer.propTypes = {
|
|
|
|
active: PropTypes.bool,
|
|
|
|
children: PropTypes.node,
|
|
|
|
className: PropTypes.string,
|
2017-01-05 04:42:18 +03:00
|
|
|
insideTree: PropTypes.bool,
|
2016-05-29 13:54:29 +03:00
|
|
|
onOverlayClick: PropTypes.func,
|
|
|
|
theme: PropTypes.shape({
|
2016-06-04 00:44:33 +03:00
|
|
|
active: PropTypes.string,
|
|
|
|
drawer: PropTypes.string,
|
|
|
|
left: PropTypes.string,
|
|
|
|
right: PropTypes.string
|
2016-05-29 13:54:29 +03:00
|
|
|
}),
|
2017-01-05 04:42:18 +03:00
|
|
|
type: PropTypes.oneOf([
|
|
|
|
'left', 'right'
|
|
|
|
]),
|
|
|
|
withOverlay: PropTypes.bool
|
2016-05-29 13:54:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
Drawer.defaultProps = {
|
|
|
|
active: false,
|
|
|
|
className: '',
|
2017-01-05 04:42:18 +03:00
|
|
|
insideTree: false,
|
|
|
|
type: 'left',
|
|
|
|
withOverlay: true
|
2016-05-29 13:54:29 +03:00
|
|
|
};
|
2015-11-05 13:45:23 +03:00
|
|
|
|
2016-05-29 13:54:29 +03:00
|
|
|
return ActivableRenderer()(Drawer);
|
2015-11-05 13:45:23 +03:00
|
|
|
};
|
2015-10-22 02:31:17 +03:00
|
|
|
|
2016-05-29 13:54:29 +03:00
|
|
|
const Drawer = factory(InjectOverlay);
|
|
|
|
export default themr(DRAWER)(Drawer);
|
|
|
|
export { factory as drawerFactory };
|
|
|
|
export { Drawer };
|