/* 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 (
); } } 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 ( ); } } 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 ( ); } } 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 (Don't fret! We got you!
Check out our