|
| 1 | +import React, { memo, forwardRef } from "react"; |
| 2 | +import { symToStr } from "tsafe/symToStr"; |
| 3 | +import { assert } from "tsafe/assert"; |
| 4 | +import type { Equals } from "tsafe"; |
| 5 | +import { fr } from "./lib"; |
| 6 | +import { cx } from "./lib/tools/cx"; |
| 7 | + |
| 8 | +// We make users import dsfr.css, so we don't need to import the scoped CSS |
| 9 | +// but in the future if we have a complete component coverage it |
| 10 | +// we could stop requiring users to import the hole CSS and only import on a |
| 11 | +// per component basis. |
| 12 | +import "./dsfr/component/stepper/stepper.css"; |
| 13 | + |
| 14 | +export type StepperProps = { |
| 15 | + className?: string; |
| 16 | + currentStep: number; |
| 17 | + steps: number; |
| 18 | + title: string; |
| 19 | + nextTitle?: string; |
| 20 | +}; |
| 21 | + |
| 22 | +/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-stepper> */ |
| 23 | +export const Stepper = memo( |
| 24 | + forwardRef<HTMLDivElement, StepperProps>((props, ref) => { |
| 25 | + const { className, currentStep, steps, title, nextTitle, ...rest } = props; |
| 26 | + |
| 27 | + assert<Equals<keyof typeof rest, never>>(); |
| 28 | + |
| 29 | + return ( |
| 30 | + <div className={cx(fr.cx("fr-stepper"), className)} ref={ref}> |
| 31 | + <h2 className="fr-stepper__title"> |
| 32 | + <span className="fr-stepper__state"> |
| 33 | + Étape {currentStep} sur {steps} |
| 34 | + </span> |
| 35 | + {title} |
| 36 | + </h2> |
| 37 | + <div |
| 38 | + className="fr-stepper__steps" |
| 39 | + data-fr-current-step={currentStep} |
| 40 | + data-fr-steps={steps} |
| 41 | + ></div> |
| 42 | + {nextTitle && ( |
| 43 | + <p className="fr-stepper__details"> |
| 44 | + <span className="fr-text--bold">Étape suivante :</span> {nextTitle} |
| 45 | + </p> |
| 46 | + )} |
| 47 | + </div> |
| 48 | + ); |
| 49 | + }) |
| 50 | +); |
| 51 | + |
| 52 | +Stepper.displayName = symToStr({ Stepper }); |
| 53 | + |
| 54 | +export default Stepper; |
0 commit comments