import AKButton from '@atlaskit/button'; import AKButtonGroup from '@atlaskit/button-group'; import ModalDialog from '@atlaskit/modal-dialog'; import React, { Component } from 'react'; import { translate } from '../../i18n'; import { dialogPropTypes } from '../constants'; /** * Web dialog that uses atlaskit modal-dialog to display dialogs. */ class StatelessDialog extends Component { /** * Web dialog component's property types. * * @static */ static propTypes = { ...dialogPropTypes, /** * This is the body of the dialog, the component children. */ children: React.PropTypes.node, /** * Disables dismissing the dialog when the blanket is clicked. Enabled * by default. */ disableBlanketClickDismiss: React.PropTypes.bool, /** * Whether the dialog is modal. This means clicking on the blanket will * leave the dialog open. No cancel button. */ isModal: React.PropTypes.bool, /** * Disables rendering of the submit button. */ submitDisabled: React.PropTypes.bool, /** * Width of the dialog, can be: * - 'small' (400px), 'medium' (600px), 'large' (800px), * 'x-large' (968px) * - integer value for pixel width * - string value for percentage */ width: React.PropTypes.string }; /** * Initializes a new Dialog instance. * * @param {Object} props - The read-only properties with which the new * instance is to be initialized. */ constructor(props) { super(props); this._onCancel = this._onCancel.bind(this); this._onDialogDismissed = this._onDialogDismissed.bind(this); this._onSubmit = this._onSubmit.bind(this); } /** * Implements React's {@link Component#render()}. * * @inheritdoc * @returns {ReactElement} */ render() { return (
); } /** * Handles click on the blanket area. * * @returns {void} */ _onDialogDismissed() { if (!this.props.disableBlanketClickDismiss) { this._onCancel(); } } /** * Render cancel button. * * @returns {*} The cancel button if enabled and dialog is not modal. * @private */ _renderCancelButton() { if (this.props.cancelDisabled || this.props.isModal) { return null; } return ( { this.props.t(this.props.cancelTitleKey || 'dialog.Cancel') } ); } /** * Render component in dialog footer. * * @returns {ReactElement} * @private */ _renderFooter() { return ( ); } /** * Render component in dialog header. * * @returns {ReactElement} * @private */ _renderHeader() { const { t } = this.props; return (

{ this.props.titleString || t(this.props.titleKey) }

); } /** * Render ok button. * * @returns {*} The ok button if enabled. * @private */ _renderOKButton() { if (this.props.submitDisabled) { return null; } return ( { this.props.t(this.props.okTitleKey || 'dialog.Ok') } ); } /** * Dispatches action to hide the dialog. * * @returns {void} */ _onCancel() { if (this.props.isModal) { return; } this.props.onCancel(); } /** * Dispatches the action when submitting the dialog. * * @private * @param {string} value - The submitted value if any. * @returns {void} */ _onSubmit(value) { this.props.onSubmit(value); } } export default translate(StatelessDialog);