UNPKG

aws-northstar

Version:
84 lines (80 loc) 4.44 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; /** ******************************************************************************************************************* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. * ******************************************************************************************************************** */ import React, { useState } from 'react'; import WizardInner from './components/WizardInner'; /** A wizard is a multipage form that guides a user through a complex flow or a series of interrelated tasks. It consists of a navigation pane, header, main content area, and action buttons. */ const Wizard = (_a) => { var { steps, getStepNumberLabel = (stepNumber) => `Step ${stepNumber}`, cancelButtonText = 'Cancel', previousButtonText = 'Previous', nextButtonText = 'Next', submitButtonText = 'Submit', optionalText = 'optional', isLoadingNextStep = false, isDisabledNextStep = false, disableStepNavigation = false, onNextButtonClick = () => true, onPreviousButtonClick = () => { }, onStepNavigationClick = () => { }, onSubmitButtonClick = () => { }, onCancelButtonClick = () => { } } = _a, props = __rest(_a, ["steps", "getStepNumberLabel", "cancelButtonText", "previousButtonText", "nextButtonText", "submitButtonText", "optionalText", "isLoadingNextStep", "isDisabledNextStep", "disableStepNavigation", "onNextButtonClick", "onPreviousButtonClick", "onStepNavigationClick", "onSubmitButtonClick", "onCancelButtonClick"]); const [maxStepIndex, setMaxStepIndex] = useState(props.activeStepIndex || 0); const [activeStepIndex, setActiveStepIndex] = useState(props.activeStepIndex || 0); const handleStepNavigationClick = (stepClickDetail) => { setActiveStepIndex(stepClickDetail.requestedStepIndex); onStepNavigationClick(stepClickDetail); }; const handleNextButtonClick = () => { const target = activeStepIndex + 1; if (onNextButtonClick({ requestedStepIndex: target })) { setActiveStepIndex(target); if (target > maxStepIndex) { setMaxStepIndex(target); } } }; const handlePreviousButtonClick = () => { const target = activeStepIndex - 1; if (target >= 0) { setActiveStepIndex(target); onPreviousButtonClick({ requestedStepIndex: target }); } }; const wizardProps = { key: activeStepIndex, step: steps[activeStepIndex], stepsInfo: steps.map((step) => ({ title: step.title, isOptional: step.isOptional, })), stepCount: steps.length, activeStepIndex, maxStepIndex, getStepNumberLabel, cancelButtonText, previousButtonText, nextButtonText, submitButtonText, optionalText, isLoadingNextStep, isDisabledNextStep, disableStepNavigation, onNextButtonClick: handleNextButtonClick, onPreviousButtonClick: handlePreviousButtonClick, onStepNavigationClick: handleStepNavigationClick, onSubmitButtonClick: onSubmitButtonClick, onCancelButtonClick: onCancelButtonClick, 'data-testid': props['data-testid'], }; return React.createElement(WizardInner, Object.assign({}, wizardProps)); }; export default Wizard; export { WizardInner };