Skip to content

Commit

Permalink
Add saving and savingText props to Wizard [#151932325]
Browse files Browse the repository at this point in the history
Signed-off-by: Ming Xiao <mxiao@pivotal.io>
  • Loading branch information
reidmit authored and Ming Xiao committed Oct 12, 2017
1 parent d4f5f09 commit 66e8b92
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
42 changes: 42 additions & 0 deletions spec/pivotal-ui-react/wizard/wizard_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,47 @@ describe('Wizard', () => {
expect(finish).toHaveBeenCalledWith();
});
});

describe('when "saving" is true and savingText is provided', () => {
beforeEach(() => {
subject::setProps({saving: true, savingText: 'Creating'});
});

it('renders a spinner', () => {
expect('.wizard-finish-btn .icon-spinner-sm').toExist();
});

it('changes the button text to savingText', () => {
expect('.wizard-finish-btn').toContainText('Creating');
});

it('disables the back button', () => {
expect('.wizard-back-btn').toHaveAttr('disabled');
});
});

describe('when "saving" is true and savingText is not provided', () => {
beforeEach(() => {
subject::setProps({saving: true});
});

it('changes the button text to the default saving text', () => {
expect('.wizard-finish-btn').toContainText('Saving');
});
});

describe('when "saving" is false', () => {
it('does not render a spinner', () => {
expect('.wizard-finish-btn .icon-spinner-sm').not.toExist();
});

it('does not change the button text', () => {
expect('.wizard-finish-btn').toContainText('Finish');
});

it('does not disable the back button', () => {
expect('.wizard-back-btn').not.toHaveAttr('disabled');
});
});
});
});
21 changes: 15 additions & 6 deletions src/react/wizard/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react';
import types from 'prop-types';
import {PrimaryButton} from '../buttons';
import {Icon} from '../iconography';
import classnames from 'classnames';

function doNothing() {
Expand All @@ -13,14 +14,18 @@ export class Wizard extends React.Component {
cancel: types.func,
cancelText: types.string,
finish: types.func,
finishText: types.string
finishText: types.string,
saving: types.bool,
savingText: types.string
};

static defaultProps = {
pages: [],
cancelText: 'Cancel',
finish: doNothing,
finishText: 'Finish'
finishText: 'Finish',
saving: false,
savingText: 'Saving'
};

constructor(props) {
Expand Down Expand Up @@ -74,7 +79,7 @@ export class Wizard extends React.Component {
}

render() {
const {cancel, cancelText, className, pages, finishText, style} = this.props;
const {cancel, cancelText, className, pages, finishText, style, saving, savingText} = this.props;
const {currentPage} = this.state;

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

const backButton = (
<PrimaryButton alt className="wizard-back-btn"
<PrimaryButton alt className="wizard-back-btn" disabled={saving}
onClick={this.onClickBack}>Back</PrimaryButton>
);

const icon = saving && <Icon src="spinner-sm"/>;
const finishButton = (
<PrimaryButton className="wizard-finish-btn"
onClick={this.onClickFinish}>{finishText}</PrimaryButton>
<PrimaryButton {...{
className: "wizard-finish-btn",
icon,
onClick: this.onClickFinish
}}>{saving ? savingText : finishText}</PrimaryButton>
);

const nextButton = (
Expand Down

0 comments on commit 66e8b92

Please sign in to comment.