import React from 'react' import Button from '../Button/Button' import Icon from '../Icons/Icon' import styles from './_stepper.module.scss' import { c } from '../../translations/LibraryTranslationService' /** Base properties for the Stepper component */ type StepperPropsBase = { /** Array of strings which represent each step title */ steps: string[] /** Indicates current step number. Starts from 1 */ currentStep: number /** Optionally hide the "Step" text */ hideStepText?: boolean /** Optionally hide the Back button */ hideBackButton?: boolean /** Optional prop to add a test id to the Stepper for QA testing */ qaTestId?: string } /** * If `hideBackButton` is `true`, `callout` should not be provided. * If `hideBackButton` is `false` or not provided, `callout` is required. */ export type StepperProps = StepperPropsBase & ( | { hideBackButton: true /** Callout for the back button. Required if the back button is not hidden. */ callout?: never } | { hideBackButton?: false /** Callout for the back button. Required if the back button is not hidden. */ callout: (currentStep: number) => void } ) const Stepper = ({ steps, currentStep, callout, hideStepText, hideBackButton, qaTestId = 'stepper', }: StepperProps): React.JSX.Element => { const cStep = currentStep <= 0 ? 1 : currentStep > steps.length ? steps.length : currentStep const hasBackButton = !hideBackButton && currentStep > 1 const backButtonStyle = hasBackButton ? styles.hasBackButton : '' return (
{hasBackButton && cStep > 1 && ( )}
{steps[cStep - 1]}
{!hideStepText ? c('step') : null}{' '} {c('stepOfSteps', { stepNumber: cStep, stepLength: steps.length, })}{' '}
{steps.map((step, index) => ( index + 1} /> ))}
) } export default Stepper type StepProps = { active: boolean highlighted: boolean } const Step = ({ active, highlighted }: StepProps): React.JSX.Element => { return (
) }