import _ from 'lodash'; import React from 'react'; import { ProgressStepsProps, ProgressStepStatus } from './types'; export const ProgressSteps: React.FC = ({ steps, onNext, onPrevious, onStepClick, children }) => { const handleNext = () => { if (onNext) { onNext(); } }; const handlePrevious = () => { if (onPrevious) { onPrevious(); } }; const showNextPage = () => { if (onNext) { return _.some(steps, { status: ProgressStepStatus.Upcoming }); } return false; }; const showPreviousPage = () => { if (onPrevious) { return _.some(steps, { status: ProgressStepStatus.Complete }); } return false; }; const handleStepClick = (stepId: string) => { if (onStepClick) { onStepClick(stepId); } }; return ( <> {children} {(showNextPage() || showPreviousPage()) && (
{showNextPage() && ( )} {showPreviousPage() && ( )}
)} ); };