|
| 1 | +import React, { memo, forwardRef, type CSSProperties } from "react"; |
| 2 | +import { symToStr } from "tsafe/symToStr"; |
| 3 | +import { assert } from "tsafe/assert"; |
| 4 | +import type { Equals } from "tsafe"; |
| 5 | +import { fr } from "./fr"; |
| 6 | +import { cx } from "./tools/cx"; |
| 7 | +import { getLink } from "./link"; |
| 8 | +import { RegisteredLinkProps } from "./link"; |
| 9 | + |
| 10 | +export type DownloadProps = { |
| 11 | + className?: string; |
| 12 | + style?: CSSProperties; |
| 13 | + details: string; |
| 14 | + label: string; |
| 15 | + linkProps: RegisteredLinkProps; |
| 16 | + classes?: Partial<Record<"root" | "wrapper" | "link" | "details", string>>; |
| 17 | +}; |
| 18 | + |
| 19 | +/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-download> */ |
| 20 | + |
| 21 | +export const Download = memo( |
| 22 | + forwardRef<HTMLDivElement, DownloadProps>((props, ref) => { |
| 23 | + const { className, style, details, label, linkProps, classes = {}, ...rest } = props; |
| 24 | + |
| 25 | + const { Link } = getLink(); |
| 26 | + |
| 27 | + assert<Equals<keyof typeof rest, never>>(); |
| 28 | + |
| 29 | + return ( |
| 30 | + <div |
| 31 | + className={cx(fr.cx("fr-download"), className, classes.root)} |
| 32 | + style={style} |
| 33 | + ref={ref} |
| 34 | + > |
| 35 | + <p className={cx(classes.wrapper)}> |
| 36 | + <Link |
| 37 | + {...linkProps} |
| 38 | + download |
| 39 | + className={cx(fr.cx("fr-download__link"), classes.link)} |
| 40 | + > |
| 41 | + {label} |
| 42 | + <span className="fr-download__detail">{details}</span> |
| 43 | + </Link> |
| 44 | + </p> |
| 45 | + </div> |
| 46 | + ); |
| 47 | + }) |
| 48 | +); |
| 49 | + |
| 50 | +Download.displayName = symToStr({ Download }); |
| 51 | + |
| 52 | +export default Download; |
0 commit comments