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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import AKButton from '@atlaskit/button';
  2. import AKButtonGroup from '@atlaskit/button-group';
  3. import ModalDialog from '@atlaskit/modal-dialog';
  4. import React from 'react';
  5. import { connect } from 'react-redux';
  6. import { translate } from '../../i18n';
  7. import AbstractDialog from './AbstractDialog';
  8. /**
  9. * Web dialog that uses atlaskit modal-dialog to display dialogs.
  10. */
  11. class Dialog extends AbstractDialog {
  12. /**
  13. * Web dialog component's property types.
  14. *
  15. * @static
  16. */
  17. static propTypes = {
  18. /**
  19. * This is the body of the dialog, the component children.
  20. */
  21. children: React.PropTypes.node,
  22. /**
  23. * Whether the dialog is modal. This means clicking on the blanket will
  24. * leave the dialog open. No cancel button.
  25. */
  26. isModal: React.PropTypes.bool,
  27. /**
  28. * Width of the dialog, can be:
  29. * - 'small' (400px), 'medium' (600px), 'large' (800px),
  30. * 'x-large' (968px)
  31. * - integer value for pixel width
  32. * - string value for percentage
  33. */
  34. width: React.PropTypes.string
  35. };
  36. /**
  37. * Implements React's {@link Component#render()}.
  38. *
  39. * @inheritdoc
  40. * @returns {ReactElement}
  41. */
  42. render() {
  43. return (
  44. <ModalDialog
  45. footer = { this._renderFooter() }
  46. header = { this._renderHeader() }
  47. isOpen = { true }
  48. onDialogDismissed = { this._onCancel }
  49. width = { this.props.width || 'medium' }>
  50. <div>
  51. <form
  52. className = 'modal-dialog-form'
  53. id = 'modal-dialog-form'
  54. onSubmit = { this._onSubmit }>
  55. { this.props.children }
  56. </form>
  57. </div>
  58. </ModalDialog>);
  59. }
  60. /**
  61. * Render cancel button.
  62. *
  63. * @returns {*} The cancel button if enabled and dialog is not modal.
  64. * @private
  65. */
  66. _renderCancelButton() {
  67. if (this.props.cancelDisabled || this.props.isModal) {
  68. return null;
  69. }
  70. return (
  71. <AKButton
  72. appearance = 'subtle'
  73. id = 'modal-dialog-cancel-button'
  74. onClick = { this._onCancel }>
  75. { this.props.t(this.props.cancelTitleKey || 'dialog.Cancel') }
  76. </AKButton>
  77. );
  78. }
  79. /**
  80. * Render component in dialog footer.
  81. *
  82. * @returns {ReactElement}
  83. * @private
  84. */
  85. _renderFooter() {
  86. return (
  87. <footer className = 'modal-dialog-footer'>
  88. <AKButtonGroup>
  89. { this._renderCancelButton() }
  90. { this._renderOKButton() }
  91. </AKButtonGroup>
  92. </footer>
  93. );
  94. }
  95. /**
  96. * Render component in dialog header.
  97. *
  98. * @returns {ReactElement}
  99. * @private
  100. */
  101. _renderHeader() {
  102. const { t } = this.props;
  103. return (
  104. <header>
  105. <h2>
  106. { this.props.titleString || t(this.props.titleKey) }
  107. </h2>
  108. </header>
  109. );
  110. }
  111. /**
  112. * Render ok button.
  113. *
  114. * @returns {*} The ok button if enabled.
  115. * @private
  116. */
  117. _renderOKButton() {
  118. if (this.props.submitDisabled) {
  119. return null;
  120. }
  121. return (
  122. <AKButton
  123. appearance = 'primary'
  124. form = 'modal-dialog-form'
  125. id = 'modal-dialog-ok-button'
  126. isDisabled = { this.props.okDisabled }
  127. onClick = { this._onSubmit }>
  128. { this.props.t(this.props.okTitleKey || 'dialog.Ok') }
  129. </AKButton>
  130. );
  131. }
  132. /**
  133. * Dispatches action to hide the dialog.
  134. *
  135. * @returns {void}
  136. */
  137. _onCancel() {
  138. if (this.props.isModal) {
  139. return;
  140. }
  141. super._onCancel();
  142. }
  143. }
  144. export default translate(connect()(Dialog));