/* eslint-disable react/no-multi-comp, no-alert */ import React from "react"; import * as PropTypes from "prop-types"; import { Button, Wizard, TextInput } from "../src/"; class AddressStep extends React.Component { static validate(wizardState) { return wizardState.address && wizardState.address.length !== 0; } render() { const { setWizardState, wizardState, recipient } = this.props; return (
{ this.form = f; }} onSubmit={(e) => e.preventDefault()} >

Delivery for {recipient}

setWizardState({ address: this.form.elements.address.value })} value={wizardState.address || ""} /> ); } } AddressStep.propTypes = { recipient: PropTypes.string.isRequired, }; class ContactStep extends React.Component { static validate(wizardState) { for (const field of ["fullName", "phoneNumber"]) { if (!wizardState[field] || wizardState[field].length === 0) { return false; } } return true; } static onStepComplete(wizardState) { alert( "Step.onStepComplete: A custom action for the current step. We might, for example, want to save the phone " + `number (${wizardState.phoneNumber}) entered on this page in a database right away.`, ); // onStepComplete must return a promise. return Promise.resolve(true); } render() { const { wizardState, setWizardState } = this.props; return (
{ this.form = f; }} onSubmit={(e) => e.preventDefault()} > setWizardState({ fullName: this.form.elements.fullName.value, }) } value={wizardState.fullName || ""} /> setWizardState({ phoneNumber: this.form.elements.phoneNumber.value, }) } value={wizardState.phoneNumber || ""} /> ); } } class ReviewStep extends React.Component { static validate(wizardState) { for (const field of ["fullName", "phoneNumber", "address"]) { if (!wizardState[field] || wizardState[field].length === 0) { return false; } } return wizardState.reviewed; } render() { const { setWizardState, wizardState } = this.props; return (
{ this.form = f; }} onSubmit={(e) => e.preventDefault()} >

Delivery Address Information

Delivery Contact Information

); } } AddressStep.propTypes = { wizardState: PropTypes.object.isRequired, setWizardState: PropTypes.func.isRequired, recipient: PropTypes.string.isRequired, }; ContactStep.propTypes = { wizardState: PropTypes.object.isRequired, setWizardState: PropTypes.func.isRequired, }; ReviewStep.propTypes = { wizardState: PropTypes.object.isRequired, setWizardState: PropTypes.func.isRequired, }; export default class WizardExample extends React.Component { constructor(props) { super(props); this.state = { stepNumberInTitle: true, seekable: false, showHelp: false, sticky: false, prevButtonValue: "Back", hideProgressBar: false, recipient: "Kristen Stark", }; } render() { const steps = [ { title: "Delivery Address", description: "To ensure that your item will arrive on time, let's make sure that we have " + "your contact address saved.", component: AddressStep, validate: AddressStep.validate, props: { recipient: this.state.recipient, }, nextButtonValue: "Save address", }, { title: "Preferred Primary Delivery Contact", description: "Who should we contact when we have arrived to your delivery address?", component: ContactStep, validate: ContactStep.validate, nextButtonValue: "Save contact", onStepComplete: ContactStep.onStepComplete, }, { title: "Skip Intermediate Step 1", description: "Who should we contact when we have arrived to your delivery address?", component: ContactStep, validate: () => false, shouldSkipStep: () => true, nextButtonValue: "Save contact", onStepComplete: undefined, }, { title: "Skip Intermediate Step 2", description: "Who should we contact when we have arrived to your delivery address?", component: ContactStep, validate: () => false, shouldSkipStep: () => true, nextButtonValue: "Save contact", onStepComplete: undefined, }, { title: "Review", description: "Please review and double check the information below before finalizing the " + "delivery process.", component: ReviewStep, validate: ReviewStep.validate, nextButtonValue: "Set delivery", }, { title: "Skip Final Step", description: "Who should we contact when we have arrived to your delivery address?", component: ContactStep, validate: () => false, shouldSkipStep: () => true, nextButtonValue: "Save contact", onStepComplete: undefined, }, ]; return (
Wizard controls
  • this.setState({ recipient: e.target.value })} label="Recipient" name="recipient" />
  • this.setState({ prevButtonValue: e.target.value })} label="Prev button text" name="prevButtonValue" />
alert( `Wizard.OnComplete: Delivering to ${state.fullName} at ${state.address}. ` + `Please call ${state.phoneNumber} upon delivery`, ) } wizardButtons={[ { handler: (wizardState, { resetWizard }) => resetWizard(), buttonValue: "Clear and start over", }, ]} help={ this.state.showHelp && (

Need any help?

Don't fret! We got you!

Check out our 

) } seekable={this.state.seekable} stepNumberInTitle={this.state.stepNumberInTitle} hideProgressBar={this.state.hideProgressBar} style={{ height: 700 }} />
); } }