UNPKG

2.01 kBTypeScriptView Raw
1import React, { memo, forwardRef, type CSSProperties, type ReactNode } from "react";
2import { symToStr } from "tsafe/symToStr";
3import { assert } from "tsafe/assert";
4import type { Equals } from "tsafe";
5import { fr } from "./fr";
6import { cx } from "./tools/cx";
7import { getLink, type RegisteredLinkProps } from "./link";
8import { useAnalyticsId } from "./tools/useAnalyticsId";
9
10export type DownloadProps = {
11 id?: string;
12 className?: string;
13 style?: CSSProperties;
14 details: ReactNode;
15 label: ReactNode;
16 linkProps: RegisteredLinkProps;
17 classes?: Partial<Record<"root" | "wrapper" | "link" | "details", string>>;
18};
19
20/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/components-download> */
21export const Download = memo(
22 forwardRef<HTMLDivElement, DownloadProps>((props, ref) => {
23 const {
24 className,
25 style,
26 details,
27 label,
28 linkProps,
29 classes = {},
30 id: props_id,
31 ...rest
32 } = props;
33
34 assert<Equals<keyof typeof rest, never>>();
35
36 const id = useAnalyticsId({
37 "defaultIdPrefix": "fr-download",
38 "explicitlyProvidedId": props_id
39 });
40
41 const { Link } = getLink();
42
43 return (
44 <div
45 id={id}
46 className={cx(fr.cx("fr-download"), className, classes.root)}
47 style={style}
48 ref={ref}
49 >
50 <p className={cx(classes.wrapper)}>
51 <Link
52 {...linkProps}
53 download
54 className={cx(fr.cx("fr-download__link"), classes.link)}
55 >
56 {label}
57 <span className="fr-download__detail">{details}</span>
58 </Link>
59 </p>
60 </div>
61 );
62 })
63);
64
65Download.displayName = symToStr({ Download });
66
67export default Download;
68
\No newline at end of file