1 | import React, { memo, forwardRef, type CSSProperties, type ReactNode } 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, type RegisteredLinkProps } from "./link";
|
8 | import { useAnalyticsId } from "./tools/useAnalyticsId";
|
9 |
|
10 | export 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 |
|
21 | export 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 |
|
65 | Download.displayName = symToStr({ Download });
|
66 |
|
67 | export default Download;
|
68 |
|
\ | No newline at end of file |