jiti-meet/react/features/base/dialog/components/AbstractDialog.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-09-18 07:01:14 +00:00
import PropTypes from 'prop-types';
import { Component } from 'react';
2017-03-07 03:34:51 +00:00
import { hideDialog } from '../actions';
2017-06-07 16:45:04 +00:00
import { DIALOG_PROP_TYPES } from '../constants';
2017-03-07 03:34:51 +00:00
/**
2017-09-18 07:01:14 +00:00
* An abstract implementation of a dialog on Web/React and mobile/react-native.
2017-03-07 03:34:51 +00:00
*/
export default class AbstractDialog extends Component {
/**
2017-09-18 07:01:14 +00:00
* <tt>AbstractDialog</tt> React <tt>Component</tt>'s prop types.
2017-03-07 03:34:51 +00:00
*
* @static
*/
static propTypes = {
2017-06-07 16:45:04 +00:00
...DIALOG_PROP_TYPES,
2017-03-07 03:34:51 +00:00
2017-09-18 07:01:14 +00:00
/**
* The React <tt>Component</tt> children of <tt>AbstractDialog</tt>
* which represents the dialog's body.
*/
children: PropTypes.node,
2017-03-07 03:34:51 +00:00
/**
* Used to show/hide the dialog on cancel.
2017-03-07 03:34:51 +00:00
*/
2017-09-18 07:01:14 +00:00
dispatch: PropTypes.func
};
2017-03-07 03:34:51 +00:00
/**
2017-09-18 07:01:14 +00:00
* Initializes a new <tt>AbstractDialog</tt> instance.
2017-03-07 03:34:51 +00:00
*
2017-09-18 07:01:14 +00:00
* @param {Object} props - The read-only React <tt>Component</tt> props with
* which the new instance is to be initialized.
2017-03-07 03:34:51 +00:00
*/
constructor(props) {
super(props);
this._onCancel = this._onCancel.bind(this);
this._onSubmit = this._onSubmit.bind(this);
}
/**
2017-09-18 07:01:14 +00:00
* Dispatches a redux action to hide this dialog when it's canceled.
2017-03-07 03:34:51 +00:00
*
2017-09-18 07:01:14 +00:00
* @protected
2017-03-07 03:34:51 +00:00
* @returns {void}
*/
_onCancel() {
2017-09-18 07:01:14 +00:00
const { onCancel } = this.props;
2017-03-07 03:34:51 +00:00
2017-09-18 07:01:14 +00:00
if (!onCancel || onCancel()) {
2017-03-07 03:34:51 +00:00
this.props.dispatch(hideDialog());
}
}
/**
2017-09-18 07:01:14 +00:00
* Dispatches a redux action to hide this dialog when it's submitted.
2017-03-07 03:34:51 +00:00
*
* @private
* @param {string} value - The submitted value if any.
* @returns {void}
*/
_onSubmit(value) {
2017-09-18 07:01:14 +00:00
const { onSubmit } = this.props;
2017-03-07 03:34:51 +00:00
2017-09-18 07:01:14 +00:00
if (!onSubmit || onSubmit(value)) {
2017-03-07 03:34:51 +00:00
this.props.dispatch(hideDialog());
}
}
}