react-toolbox/components/dialog/Dialog.js

80 lines
2.4 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
2016-05-21 21:48:55 +03:00
import { themr } from 'react-css-themr';
import classnames from 'classnames';
import { DIALOG } from '../identifiers.js';
import ActivableRenderer from '../hoc/ActivableRenderer.js';
import InjectButton from '../button/Button.js';
import InjectOverlay from '../overlay/Overlay.js';
2015-09-19 17:45:27 +03:00
const factory = (Overlay, Button) => {
const Dialog = (props) => {
const actions = props.actions.map((action, idx) => {
const className = classnames(props.theme.button, {[action.className]: action.className});
return <Button key={idx} {...action} className={className} />;
});
2015-11-05 13:28:42 +03:00
const className = classnames([props.theme.dialog, props.theme[props.type]], {
[props.theme.active]: props.active
}, props.className);
2015-11-05 13:28:42 +03:00
return (
<Overlay
active={props.active}
onClick={props.onOverlayClick}
2016-07-10 14:42:35 +03:00
onEscKeyDown={props.onEscKeyDown}
onMouseDown={props.onOverlayMouseDown}
onMouseMove={props.onOverlayMouseMove}
2016-07-10 14:42:35 +03:00
onMouseUp={props.onOverlayMouseUp}
>
<div data-react-toolbox='dialog' className={className}>
<section role='body' className={props.theme.body}>
{props.title ? <h6 className={props.theme.title}>{props.title}</h6> : null}
{props.children}
</section>
{actions.length
? <nav role='navigation' className={props.theme.navigation}>
{actions}
</nav>
: null
}
</div>
</Overlay>
);
};
2015-11-05 13:28:42 +03:00
Dialog.propTypes = {
actions: PropTypes.array,
active: PropTypes.bool,
children: PropTypes.node,
className: PropTypes.string,
onEscKeyDown: PropTypes.func,
onOverlayClick: PropTypes.func,
onOverlayMouseDown: PropTypes.func,
onOverlayMouseMove: PropTypes.func,
onOverlayMouseUp: PropTypes.func,
theme: PropTypes.shape({
active: PropTypes.string,
body: PropTypes.string,
button: PropTypes.string,
dialog: PropTypes.string,
navigation: PropTypes.string,
title: PropTypes.string
}),
title: PropTypes.string,
type: PropTypes.string
};
Dialog.defaultProps = {
actions: [],
active: false,
type: 'normal'
};
2015-11-05 13:28:42 +03:00
return ActivableRenderer()(Dialog);
2015-11-05 13:28:42 +03:00
};
2015-10-22 02:31:17 +03:00
const Dialog = factory(InjectOverlay, InjectButton);
export default themr(DIALOG)(Dialog);
export { Dialog };
export { factory as dialogFactory };