Skip to content

Commit 66e8b92

Browse files
reidmitMing Xiao
authored andcommitted
Add saving and savingText props to Wizard [#151932325]
Signed-off-by: Ming Xiao <mxiao@pivotal.io>
1 parent d4f5f09 commit 66e8b92

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

spec/pivotal-ui-react/wizard/wizard_spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,47 @@ describe('Wizard', () => {
332332
expect(finish).toHaveBeenCalledWith();
333333
});
334334
});
335+
336+
describe('when "saving" is true and savingText is provided', () => {
337+
beforeEach(() => {
338+
subject::setProps({saving: true, savingText: 'Creating'});
339+
});
340+
341+
it('renders a spinner', () => {
342+
expect('.wizard-finish-btn .icon-spinner-sm').toExist();
343+
});
344+
345+
it('changes the button text to savingText', () => {
346+
expect('.wizard-finish-btn').toContainText('Creating');
347+
});
348+
349+
it('disables the back button', () => {
350+
expect('.wizard-back-btn').toHaveAttr('disabled');
351+
});
352+
});
353+
354+
describe('when "saving" is true and savingText is not provided', () => {
355+
beforeEach(() => {
356+
subject::setProps({saving: true});
357+
});
358+
359+
it('changes the button text to the default saving text', () => {
360+
expect('.wizard-finish-btn').toContainText('Saving');
361+
});
362+
});
363+
364+
describe('when "saving" is false', () => {
365+
it('does not render a spinner', () => {
366+
expect('.wizard-finish-btn .icon-spinner-sm').not.toExist();
367+
});
368+
369+
it('does not change the button text', () => {
370+
expect('.wizard-finish-btn').toContainText('Finish');
371+
});
372+
373+
it('does not disable the back button', () => {
374+
expect('.wizard-back-btn').not.toHaveAttr('disabled');
375+
});
376+
});
335377
});
336378
});

src/react/wizard/wizard.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React from 'react';
33
import types from 'prop-types';
44
import {PrimaryButton} from '../buttons';
5+
import {Icon} from '../iconography';
56
import classnames from 'classnames';
67

78
function doNothing() {
@@ -13,14 +14,18 @@ export class Wizard extends React.Component {
1314
cancel: types.func,
1415
cancelText: types.string,
1516
finish: types.func,
16-
finishText: types.string
17+
finishText: types.string,
18+
saving: types.bool,
19+
savingText: types.string
1720
};
1821

1922
static defaultProps = {
2023
pages: [],
2124
cancelText: 'Cancel',
2225
finish: doNothing,
23-
finishText: 'Finish'
26+
finishText: 'Finish',
27+
saving: false,
28+
savingText: 'Saving'
2429
};
2530

2631
constructor(props) {
@@ -74,7 +79,7 @@ export class Wizard extends React.Component {
7479
}
7580

7681
render() {
77-
const {cancel, cancelText, className, pages, finishText, style} = this.props;
82+
const {cancel, cancelText, className, pages, finishText, style, saving, savingText} = this.props;
7883
const {currentPage} = this.state;
7984

8085
const page = pages[currentPage];
@@ -94,13 +99,17 @@ export class Wizard extends React.Component {
9499
);
95100

96101
const backButton = (
97-
<PrimaryButton alt className="wizard-back-btn"
102+
<PrimaryButton alt className="wizard-back-btn" disabled={saving}
98103
onClick={this.onClickBack}>Back</PrimaryButton>
99104
);
100105

106+
const icon = saving && <Icon src="spinner-sm"/>;
101107
const finishButton = (
102-
<PrimaryButton className="wizard-finish-btn"
103-
onClick={this.onClickFinish}>{finishText}</PrimaryButton>
108+
<PrimaryButton {...{
109+
className: "wizard-finish-btn",
110+
icon,
111+
onClick: this.onClickFinish
112+
}}>{saving ? savingText : finishText}</PrimaryButton>
104113
);
105114

106115
const nextButton = (

0 commit comments

Comments
 (0)