|
@@ -102,26 +102,8 @@ class StatelessDialog extends Component<Props> {
|
102
|
102
|
this._onDialogDismissed = this._onDialogDismissed.bind(this);
|
103
|
103
|
this._onKeyDown = this._onKeyDown.bind(this);
|
104
|
104
|
this._onSubmit = this._onSubmit.bind(this);
|
|
105
|
+ this._renderFooter = this._renderFooter.bind(this);
|
105
|
106
|
this._setDialogElement = this._setDialogElement.bind(this);
|
106
|
|
-
|
107
|
|
- this._Footer = this._createFooterConstructor(props);
|
108
|
|
- }
|
109
|
|
-
|
110
|
|
- /**
|
111
|
|
- * React Component method that executes before the component is updated.
|
112
|
|
- *
|
113
|
|
- * @inheritdoc
|
114
|
|
- * @param {Object} nextProps - The next properties, before the update.
|
115
|
|
- * @returns {void}
|
116
|
|
- */
|
117
|
|
- componentWillUpdate(nextProps) {
|
118
|
|
- // If button states have changed, update the Footer constructor function
|
119
|
|
- // so buttons of the proper state are rendered.
|
120
|
|
- if (nextProps.okDisabled !== this.props.okDisabled
|
121
|
|
- || nextProps.cancelDisabled !== this.props.cancelDisabled
|
122
|
|
- || nextProps.submitDisabled !== this.props.submitDisabled) {
|
123
|
|
- this._Footer = this._createFooterConstructor(nextProps);
|
124
|
|
- }
|
125
|
107
|
}
|
126
|
108
|
|
127
|
109
|
/**
|
|
@@ -142,7 +124,7 @@ class StatelessDialog extends Component<Props> {
|
142
|
124
|
return (
|
143
|
125
|
<Modal
|
144
|
126
|
autoFocus = { true }
|
145
|
|
- footer = { this._Footer }
|
|
127
|
+ footer = { this._renderFooter }
|
146
|
128
|
heading = { titleString || t(titleKey) }
|
147
|
129
|
i18n = { this.props.i18n }
|
148
|
130
|
onClose = { this._onDialogDismissed }
|
|
@@ -174,41 +156,38 @@ class StatelessDialog extends Component<Props> {
|
174
|
156
|
);
|
175
|
157
|
}
|
176
|
158
|
|
177
|
|
- _onCancel: () => Function;
|
|
159
|
+ _renderFooter: () => React$Node;
|
178
|
160
|
|
179
|
161
|
/**
|
180
|
|
- * Returns a functional component to be used for the modal footer.
|
|
162
|
+ * Returns a ReactElement to display buttons for closing the modal.
|
181
|
163
|
*
|
182
|
|
- * @param {Object} options - The configuration for how the buttons in the
|
183
|
|
- * footer should display. Essentially {@code StatelessDialog} props should
|
184
|
|
- * be passed in.
|
|
164
|
+ * @param {Object} propsFromModalFooter - The props passed in from the
|
|
165
|
+ * {@link ModalFooter} component.
|
185
|
166
|
* @private
|
186
|
167
|
* @returns {ReactElement}
|
187
|
168
|
*/
|
188
|
|
- _createFooterConstructor(options) {
|
|
169
|
+ _renderFooter(propsFromModalFooter) {
|
189
|
170
|
// Filter out falsy (null) values because {@code ButtonGroup} will error
|
190
|
171
|
// if passed in anything but buttons with valid type props.
|
191
|
172
|
const buttons = [
|
192
|
|
- this._renderOKButton(options),
|
193
|
|
- this._renderCancelButton(options)
|
|
173
|
+ this._renderOKButton(),
|
|
174
|
+ this._renderCancelButton()
|
194
|
175
|
].filter(Boolean);
|
195
|
176
|
|
196
|
|
- return function Footer(modalFooterProps) {
|
197
|
|
- return (
|
198
|
|
- <ModalFooter showKeyline = { modalFooterProps.showKeyline } >
|
199
|
|
- {
|
200
|
|
-
|
201
|
|
- /**
|
202
|
|
- * Atlaskit has this empty span (JustifySim) so...
|
203
|
|
- */
|
204
|
|
- }
|
205
|
|
- <span />
|
206
|
|
- <ButtonGroup>
|
207
|
|
- { buttons }
|
208
|
|
- </ButtonGroup>
|
209
|
|
- </ModalFooter>
|
210
|
|
- );
|
211
|
|
- };
|
|
177
|
+ return (
|
|
178
|
+ <ModalFooter showKeyline = { propsFromModalFooter.showKeyline } >
|
|
179
|
+ {
|
|
180
|
+
|
|
181
|
+ /**
|
|
182
|
+ * Atlaskit has this empty span (JustifySim) so...
|
|
183
|
+ */
|
|
184
|
+ }
|
|
185
|
+ <span />
|
|
186
|
+ <ButtonGroup>
|
|
187
|
+ { buttons }
|
|
188
|
+ </ButtonGroup>
|
|
189
|
+ </ModalFooter>
|
|
190
|
+ );
|
212
|
191
|
}
|
213
|
192
|
|
214
|
193
|
_onCancel: () => void;
|
|
@@ -257,21 +236,14 @@ class StatelessDialog extends Component<Props> {
|
257
|
236
|
/**
|
258
|
237
|
* Renders Cancel button.
|
259
|
238
|
*
|
260
|
|
- * @param {Object} options - The configuration for the Cancel button.
|
261
|
|
- * @param {boolean} options.cancelDisabled - True if the cancel button
|
262
|
|
- * should not be rendered.
|
263
|
|
- * @param {string} options.cancelTitleKey - The translation key to use as
|
264
|
|
- * text on the button.
|
265
|
|
- * @param {boolean} options.isModal - True if the cancel button should not
|
266
|
|
- * be rendered.
|
267
|
239
|
* @private
|
268
|
240
|
* @returns {ReactElement|null} The Cancel button if enabled and dialog is
|
269
|
241
|
* not modal.
|
270
|
242
|
*/
|
271
|
|
- _renderCancelButton(options = {}) {
|
272
|
|
- if (options.cancelDisabled
|
273
|
|
- || options.isModal
|
274
|
|
- || options.hideCancelButton) {
|
|
243
|
+ _renderCancelButton() {
|
|
244
|
+ if (this.props.cancelDisabled
|
|
245
|
+ || this.props.isModal
|
|
246
|
+ || this.props.hideCancelButton) {
|
275
|
247
|
return null;
|
276
|
248
|
}
|
277
|
249
|
|
|
@@ -286,7 +258,7 @@ class StatelessDialog extends Component<Props> {
|
286
|
258
|
key = 'cancel'
|
287
|
259
|
onClick = { this._onCancel }
|
288
|
260
|
type = 'button'>
|
289
|
|
- { t(options.cancelTitleKey || 'dialog.Cancel') }
|
|
261
|
+ { t(this.props.cancelTitleKey || 'dialog.Cancel') }
|
290
|
262
|
</Button>
|
291
|
263
|
);
|
292
|
264
|
}
|
|
@@ -294,18 +266,11 @@ class StatelessDialog extends Component<Props> {
|
294
|
266
|
/**
|
295
|
267
|
* Renders OK button.
|
296
|
268
|
*
|
297
|
|
- * @param {Object} options - The configuration for the OK button.
|
298
|
|
- * @param {boolean} options.okDisabled - True if the button should display
|
299
|
|
- * as disabled and clicking should have no effect.
|
300
|
|
- * @param {string} options.okTitleKey - The translation key to use as text
|
301
|
|
- * on the button.
|
302
|
|
- * @param {boolean} options.submitDisabled - True if the button should not
|
303
|
|
- * be rendered.
|
304
|
269
|
* @private
|
305
|
270
|
* @returns {ReactElement|null} The OK button if enabled.
|
306
|
271
|
*/
|
307
|
|
- _renderOKButton(options = {}) {
|
308
|
|
- if (options.submitDisabled) {
|
|
272
|
+ _renderOKButton() {
|
|
273
|
+ if (this.props.submitDisabled) {
|
309
|
274
|
return null;
|
310
|
275
|
}
|
311
|
276
|
|
|
@@ -318,11 +283,11 @@ class StatelessDialog extends Component<Props> {
|
318
|
283
|
appearance = 'primary'
|
319
|
284
|
form = 'modal-dialog-form'
|
320
|
285
|
id = { OK_BUTTON_ID }
|
321
|
|
- isDisabled = { options.okDisabled }
|
|
286
|
+ isDisabled = { this.props.okDisabled }
|
322
|
287
|
key = 'submit'
|
323
|
288
|
onClick = { this._onSubmit }
|
324
|
289
|
type = 'button'>
|
325
|
|
- { t(options.okTitleKey || 'dialog.Ok') }
|
|
290
|
+ { t(this.props.okTitleKey || 'dialog.Ok') }
|
326
|
291
|
</Button>
|
327
|
292
|
);
|
328
|
293
|
}
|