You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Dialog.web.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. import React from 'react';
  3. import { connect } from 'react-redux';
  4. import AbstractDialog from './AbstractDialog';
  5. import type { Props as AbstractDialogProps, State } from './AbstractDialog';
  6. import StatelessDialog from './StatelessDialog';
  7. /**
  8. * The type of the React {@code Component} props of {@link Dialog}.
  9. */
  10. type Props = {
  11. ...AbstractDialogProps,
  12. /**
  13. * Whether the dialog is modal. This means clicking on the blanket will
  14. * leave the dialog open. No cancel button.
  15. */
  16. isModal: boolean,
  17. /**
  18. * Disables rendering of the submit button.
  19. */
  20. submitDisabled: boolean,
  21. /**
  22. * Width of the dialog, can be:
  23. * - 'small' (400px), 'medium' (600px), 'large' (800px),
  24. * 'x-large' (968px)
  25. * - integer value for pixel width
  26. * - string value for percentage
  27. */
  28. width: string
  29. };
  30. /**
  31. * Web dialog that uses atlaskit modal-dialog to display dialogs.
  32. */
  33. class Dialog extends AbstractDialog<Props, State> {
  34. /**
  35. * Initializes a new Dialog instance.
  36. *
  37. * @param {Object} props - The read-only properties with which the new
  38. * instance is to be initialized.
  39. */
  40. constructor(props) {
  41. super(props);
  42. // Bind event handlers so they are only bound once per instance.
  43. this._onCancel = this._onCancel.bind(this);
  44. this._onSubmit = this._onSubmit.bind(this);
  45. }
  46. /**
  47. * Implements React's {@link Component#render()}.
  48. *
  49. * @inheritdoc
  50. * @returns {ReactElement}
  51. */
  52. render() {
  53. const props = {
  54. ...this.props,
  55. onCancel: this._onCancel,
  56. onSubmit: this._onSubmit
  57. };
  58. delete props.dispatch;
  59. return <StatelessDialog { ...props } />;
  60. }
  61. _onCancel: () => void;
  62. /**
  63. * Dispatches action to hide the dialog.
  64. *
  65. * @returns {void}
  66. */
  67. _onCancel() {
  68. this.props.isModal || super._onCancel();
  69. }
  70. _onSubmit: (?string) => void;
  71. }
  72. export default connect()(Dialog);