import cx from "classnames"; import React, { forwardRef, useCallback, useMemo } from "react"; import Check from "../../components/Icon/Icons/components/Check"; import Divider from "../../components/Divider/Divider"; import { NOOP } from "../../utils/function-utils"; import StepIndicator from "./components/StepIndicator/StepIndicator"; import { MultiStepType, Size, StepStatus, TextPlacement } from "./MultiStepConstants"; import { getTestId } from "../../tests/test-ids-utils"; import { ComponentDefaultTestId } from "../../tests/constants"; import { SubIcon, VibeComponent, VibeComponentProps, withStaticProps } from "../../types"; import { IconType } from "../Icon/IconConstants"; import styles from "./MultiStepIndicator.module.scss"; export type Step = { titleText: string; subtitleText: string; status: StepStatus; }; export interface MultiStepIndicatorProps extends VibeComponentProps { steps?: Step[]; type?: MultiStepType; stepComponentClassName?: string; dividerComponentClassName?: string; fulfilledStepIcon?: SubIcon; fulfilledStepIconType?: IconType.SVG | IconType.ICON_FONT; isFulfilledStepDisplayNumber?: boolean; onClick?: (stepNumber: number) => void; textPlacement?: TextPlacement; size?: Size; } const MultiStepIndicator: VibeComponent & { types?: typeof MultiStepType; stepStatuses?: typeof StepStatus; textPlacements?: typeof TextPlacement; sizes?: typeof Size; } = forwardRef( ( { className, steps = [], type = MultiStepType.PRIMARY, stepComponentClassName, dividerComponentClassName, fulfilledStepIcon = Check, fulfilledStepIconType = IconType.SVG, isFulfilledStepDisplayNumber = false, onClick = NOOP, textPlacement = TextPlacement.HORIZONTAL, id, size, "data-testid": dataTestId }, ref ) => { const finalSize = textPlacement === TextPlacement.VERTICAL ? Size.REGULAR : size; const renderHorizontalStepIndicator = useCallback( (step: Step, index: number) => { return ( {index !== steps.length - 1 && ( )} ); }, [ onClick, isFulfilledStepDisplayNumber, type, stepComponentClassName, fulfilledStepIcon, fulfilledStepIconType, dividerComponentClassName, steps.length, finalSize ] ); const renderVerticalStepIndicator = useCallback( (step: Step, index: number) => { return ( ); }, [ onClick, isFulfilledStepDisplayNumber, type, stepComponentClassName, fulfilledStepIcon, fulfilledStepIconType, dividerComponentClassName, steps.length ] ); const stepRenderer = useMemo( () => (textPlacement === TextPlacement.VERTICAL ? renderVerticalStepIndicator : renderHorizontalStepIndicator), [textPlacement, renderVerticalStepIndicator, renderHorizontalStepIndicator] ); return (
    {steps.map(stepRenderer)}
); } ); export default withStaticProps(MultiStepIndicator, { types: MultiStepType, stepStatuses: StepStatus, textPlacements: TextPlacement, sizes: Size });