import React, { Fragment } from 'react'; import classNames from 'classnames'; import { Icon } from '../Icon/Icon'; import { Paragraph } from '../Typography/Paragraph/Paragraph'; import { Text } from '../Typography/Text/Text'; export interface StepperProps { steps: [string, string, ...string[]]; /** * Starts with 1 */ activeStep: number; /** * Prefix for label. * Visible on viewport up to 992px of screen width. * Example: `Step 1` */ prefixOnSmallScreens?: string; } export const Stepper: React.FC = ({ steps, activeStep = 1, prefixOnSmallScreens, ...rest }) => { return (
{steps.map((item, index) => { const currentStep = index + 1; /* Ensures activeStep is within a specified range. */ const currentActiveStep = Math.max(1, Math.min(steps.length, activeStep)); const isStepCurrent = currentActiveStep === currentStep; const isStepCompleted = currentActiveStep > currentStep; return ( {index > 0 &&
}
{item}
); })}
{prefixOnSmallScreens && (
{prefixOnSmallScreens}
)}
{steps[activeStep - 1]}
); };