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.js 2.1KB

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