2017-01-26 20:05:32 +03:00
|
|
|
/* eslint-disable jsx-a11y/aria-role */
|
2017-04-17 17:14:17 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-05-21 21:48:55 +03:00
|
|
|
import { themr } from 'react-css-themr';
|
|
|
|
import classnames from 'classnames';
|
2017-01-26 20:05:32 +03:00
|
|
|
import { DIALOG } from '../identifiers';
|
|
|
|
import Portal from '../hoc/Portal';
|
|
|
|
import ActivableRenderer from '../hoc/ActivableRenderer';
|
|
|
|
import InjectButton from '../button/Button';
|
|
|
|
import InjectOverlay from '../overlay/Overlay';
|
2015-09-19 17:45:27 +03:00
|
|
|
|
2016-05-28 23:04:00 +03:00
|
|
|
const factory = (Overlay, Button) => {
|
|
|
|
const Dialog = (props) => {
|
|
|
|
const actions = props.actions.map((action, idx) => {
|
2017-01-26 20:05:32 +03:00
|
|
|
const className = classnames(props.theme.button, { [action.className]: action.className });
|
|
|
|
return <Button key={idx} {...action} className={className} />; // eslint-disable-line
|
2016-05-28 23:04:00 +03:00
|
|
|
});
|
2015-11-05 13:28:42 +03:00
|
|
|
|
2016-05-28 23:04:00 +03:00
|
|
|
const className = classnames([props.theme.dialog, props.theme[props.type]], {
|
2017-01-26 20:05:32 +03:00
|
|
|
[props.theme.active]: props.active,
|
2016-05-28 23:04:00 +03:00
|
|
|
}, props.className);
|
2015-11-05 13:28:42 +03:00
|
|
|
|
2016-05-28 23:04:00 +03:00
|
|
|
return (
|
2017-01-05 04:42:18 +03:00
|
|
|
<Portal className={props.theme.wrapper}>
|
|
|
|
<Overlay
|
|
|
|
active={props.active}
|
2017-01-05 12:57:25 +03:00
|
|
|
className={props.theme.overlay}
|
2017-01-05 04:42:18 +03:00
|
|
|
onClick={props.onOverlayClick}
|
|
|
|
onEscKeyDown={props.onEscKeyDown}
|
|
|
|
onMouseDown={props.onOverlayMouseDown}
|
|
|
|
onMouseMove={props.onOverlayMouseMove}
|
|
|
|
onMouseUp={props.onOverlayMouseUp}
|
2017-01-05 12:57:25 +03:00
|
|
|
theme={props.theme}
|
|
|
|
themeNamespace="overlay"
|
2017-01-05 04:42:18 +03:00
|
|
|
/>
|
2017-01-26 20:05:32 +03:00
|
|
|
<div data-react-toolbox="dialog" className={className}>
|
|
|
|
<section role="body" className={props.theme.body}>
|
2016-05-28 23:04:00 +03:00
|
|
|
{props.title ? <h6 className={props.theme.title}>{props.title}</h6> : null}
|
|
|
|
{props.children}
|
|
|
|
</section>
|
|
|
|
{actions.length
|
2017-05-23 13:07:41 +03:00
|
|
|
? <nav className={props.theme.navigation}>
|
2017-01-26 20:05:32 +03:00
|
|
|
{actions}
|
|
|
|
</nav>
|
2016-05-28 23:04:00 +03:00
|
|
|
: null
|
|
|
|
}
|
|
|
|
</div>
|
2017-01-05 04:42:18 +03:00
|
|
|
</Portal>
|
2016-05-28 23:04:00 +03:00
|
|
|
);
|
|
|
|
};
|
2015-11-05 13:28:42 +03:00
|
|
|
|
2016-05-28 23:04:00 +03:00
|
|
|
Dialog.propTypes = {
|
2017-01-26 20:05:32 +03:00
|
|
|
actions: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
className: PropTypes.string,
|
|
|
|
label: PropTypes.string,
|
|
|
|
children: PropTypes.node,
|
|
|
|
})),
|
2016-05-29 13:47:27 +03:00
|
|
|
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({
|
2016-06-04 00:44:33 +03:00
|
|
|
active: PropTypes.string,
|
|
|
|
body: PropTypes.string,
|
|
|
|
button: PropTypes.string,
|
|
|
|
dialog: PropTypes.string,
|
|
|
|
navigation: PropTypes.string,
|
2017-04-02 15:17:14 +03:00
|
|
|
overflow: PropTypes.string,
|
2017-01-05 12:57:25 +03:00
|
|
|
overlay: PropTypes.string,
|
2017-01-05 04:42:18 +03:00
|
|
|
title: PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
wrapper: PropTypes.string,
|
2016-05-28 23:04:00 +03:00
|
|
|
}),
|
2016-05-29 13:47:27 +03:00
|
|
|
title: PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
type: PropTypes.string,
|
2016-05-28 23:04:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
Dialog.defaultProps = {
|
|
|
|
actions: [],
|
|
|
|
active: false,
|
2017-01-26 20:05:32 +03:00
|
|
|
type: 'normal',
|
2016-05-28 23:04:00 +03:00
|
|
|
};
|
2015-11-05 13:28:42 +03:00
|
|
|
|
2016-05-28 23:04:00 +03:00
|
|
|
return ActivableRenderer()(Dialog);
|
2015-11-05 13:28:42 +03:00
|
|
|
};
|
2015-10-22 02:31:17 +03:00
|
|
|
|
2016-05-28 23:04:00 +03:00
|
|
|
const Dialog = factory(InjectOverlay, InjectButton);
|
|
|
|
export default themr(DIALOG)(Dialog);
|
|
|
|
export { Dialog };
|
|
|
|
export { factory as dialogFactory };
|