import React, { forwardRef } from "react"; import { Label } from "../typography"; import type { OverridableComponent } from "../utils-external"; import { cl, composeEventHandlers } from "../utils/helpers"; import { useStepperContext } from "./context"; export interface StepperStepProps extends React.AnchorHTMLAttributes { /** * Text content by indicator. */ children: string; /** * Makes step-indicator a checkmark. * @default false */ completed?: boolean; /** * Makes step non-interactive if false. Step will be set to a `
`, overriding `as`-prop. * @default true */ interactive?: boolean; } export const Step: OverridableComponent = forwardRef( ( { className, children, as: Component = "a", completed = false, interactive, onClick, ...rest }, ref, ) => { const context = useStepperContext(); const { activeStep } = context; const isInteractive = interactive ?? context?.interactive; const Comp = isInteractive ? Component : "div"; const handleStepClick = () => { isInteractive && context.onStepChange(context.index + 1); }; return ( context.index, "aksel-stepper__step--non-interactive": !isInteractive, "aksel-stepper__step--completed": completed, })} data-active={activeStep === context.index} data-completed={completed} data-interactive={isInteractive} onClick={composeEventHandlers(onClick, handleStepClick)} > {completed ? ( ) : ( )} ); }, ); export default Step;