{"version":3,"file":"MultiStepForm-a4167566.js","sources":["../../../app/javascript/src/components/ui/Step.jsx","../../../app/javascript/src/utils/children.js","../../../app/javascript/src/components/ui/StepRenderer.jsx","../../../app/javascript/src/components/ui/StepNavigator.jsx","../../../app/javascript/src/components/ui/form/MultiStepForm.jsx"],"sourcesContent":["//\nimport React, { Component, createContext } from 'react'\n\n/**\n * Used to provide custom step body render method\n * @type {{Provider, Consumer}}\n */\n/* $FlowFixMe */\nexport const StepContext = createContext({\n render: (body) => body,\n})\n\nclass Step extends Component {\n static contextType = StepContext\n\n static defaultProps = {\n initialValues: undefined,\n onNavigate: undefined,\n }\n\n componentDidMount() {\n const { onNavigate } = this.props\n\n if (onNavigate) {\n onNavigate()\n }\n }\n\n render() {\n const { children } = this.props\n return this.context.render(children, this)\n }\n}\n\nexport default Step\n","import React from 'react'\n\nexport function mapChildren(children, func, context) {\n let index = 0\n\n let result = React.Children.map(children, (child) => {\n if (!React.isValidElement(child)) {\n return child\n }\n\n return func.call(context, child, index++)\n })\n\n return result\n}\n","//\nimport { Component } from 'react'\nimport * as React from 'react'\nimport { mapChildren } from 'utils/children'\n\n/**\n * StepController Properties\n */\n\n/**\n * StepController State\n */\n\n/**\n *\n */\nexport default class StepRenderer extends Component {\n /**\n * @param step\n * @param idx\n * @returns {*}\n */\n renderStepBody(step, idx) {\n const { activeStep } = this.props\n return idx === activeStep ? step : null\n }\n\n render() {\n const { children } = this.props\n return mapChildren(children, this.renderStepBody, this)\n }\n}\n","//\nimport { Component, createContext, useContext } from 'react'\nimport * as React from 'react'\nimport StepRenderer from './StepRenderer'\nimport history from 'components/frontend/history'\n\n/**\n * StepNavigator Properties\n */\n\n/**\n * StepNavigator State\n */\n\nexport const StepNavigatorContext = createContext({\n currentStep: 0,\n nextStep: () => {},\n prevStep: () => {},\n navigateTo: (step) => {},\n})\n\nexport function useStepNavigator() {\n return useContext(StepNavigatorContext)\n}\n\n/**\n */\nexport default class StepNavigator extends Component {\n constructor(props) {\n super(props)\n\n this.state = {\n currentStep: props.initialStep ? props.initialStep : 0,\n totalSteps: this.stepsCount(),\n nextStep: this.nextStep.bind(this),\n prevStep: this.prevStep.bind(this),\n navigateTo: this.navigateTo.bind(this),\n }\n\n this.nextStep = this.nextStep.bind(this)\n this.prevStep = this.prevStep.bind(this)\n this.navigateTo = this.navigateTo.bind(this)\n this.updateCurrentLocation = this.updateCurrentLocation.bind(this)\n }\n\n componentDidUpdate(prevProps) {\n if (this.props.initialStep !== prevProps.initialStep) {\n this.setState({\n currentStep: this.props.initialStep,\n })\n }\n }\n\n static getDerivedStateFromProps(props, state) {\n /* $FlowFixMe */\n state.totalSteps = props.children.length\n return state\n }\n\n nextStep() {\n let { currentStep, totalSteps } = this.state\n\n if (currentStep < totalSteps - 1) {\n currentStep++\n }\n\n this.handleStepChange(currentStep)\n }\n\n prevStep() {\n let { currentStep } = this.state\n\n if (currentStep > 0) {\n currentStep--\n }\n\n this.handleStepChange(currentStep)\n }\n\n navigateTo(step) {\n let { totalSteps } = this.state\n\n if (step >= 0 && step < totalSteps) {\n this.handleStepChange(step)\n }\n }\n\n updateCurrentLocation() {\n const { currentStep } = this.state\n const { trackingKey, children } = this.props\n\n if (trackingKey) {\n let key = currentStep\n\n if (Array.isArray(children) && children[currentStep]) {\n const { props: { name } = {} } = children[currentStep]\n\n if (name) {\n key = name\n }\n }\n\n let path = location.pathname + `?ul=${trackingKey}-${key}`\n if (location.hash) {\n path += location.hash\n }\n\n history.push(path)\n }\n }\n\n handleStepChange(currentStep) {\n const { onNavigate } = this.props\n\n if (onNavigate) {\n onNavigate(currentStep).then((newStep) => {\n this.setState(\n {\n currentStep: newStep ? newStep : currentStep,\n },\n this.updateCurrentLocation\n )\n })\n } else {\n this.setState(\n {\n currentStep,\n },\n this.updateCurrentLocation\n )\n }\n }\n\n /**\n * @returns {number}\n */\n stepsCount() {\n /* $FlowFixMe */\n return this.props.children.length\n }\n\n render() {\n const { currentStep } = this.state\n\n return (\n