Skip to content

Commit 47446c7

Browse files
authored
added Download component (#59)
1 parent 0484866 commit 47446c7

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

COMPONENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
- [x] Summary
3838
- [ ] Table
3939
- [ ] Tag
40-
- [ ] Download
40+
- [x] Download
4141
- [ ] Transcription
4242
- [x] Tile
4343
- [x] Input

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ This module is a wrapper/compatibility layer for [@gouvfr/dsfr](https://github.c
4545
- [x] No [white flash when reloading in SSR setup](https://github.com/codegouvfr/@codegouvfr/react-dsfr/issues/2#issuecomment-1257263480).
4646
- [x] Most components are server component ready. The others are labeled with `"use client";`
4747
- [x] [Perfect integration with all major React framework: Next.js (PagesDir and AppDir), Create React App, Vue](https://react-dsfr.etalab.studio/).
48-
- [ ] All [the components](https://www.systeme-de-design.gouv.fr/elements-d-interface) are implemented (20/41, [see details](COMPONENTS.md))
48+
- [ ] All [the components](https://www.systeme-de-design.gouv.fr/elements-d-interface) are implemented (21/41, [see details](COMPONENTS.md))
4949
- [x] Three shakable distribution, cherry pick the components you import. (It's not all in a big .js bundle)
5050
- [x] Optional integration with [MUI](https://mui.com/). If you use MUI components they will
5151
be automatically adapted to look like [DSFR components](https://www.systeme-de-design.gouv.fr/elements-d-interface). See [documentation](https://react-dsfr.etalab.studio/mui-integration).

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@
148148
"./Highlight": "./dist/Highlight.js",
149149
"./Header": "./dist/Header.js",
150150
"./Footer": "./dist/Footer.js",
151+
"./File": "./dist/File.js",
152+
"./Download": "./dist/Download.js",
151153
"./Display": "./dist/Display.js",
152154
"./Checkbox": "./dist/Checkbox.js",
153155
"./Card": "./dist/Card.js",

src/Download.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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;

stories/Download.stories.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Download } from "../dist/Download";
2+
import { sectionName } from "./sectionName";
3+
import { getStoryFactory } from "./getStory";
4+
5+
const { meta, getStory } = getStoryFactory({
6+
sectionName,
7+
"wrappedComponent": { Download },
8+
description: `
9+
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/telechargement-de-fichier)
10+
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/Download.tsx)`,
11+
"argTypes": {
12+
"label": {
13+
"description": `Required - the label of the anchor element. In case the file to download is in a different language than the current document one, it should contains the mention of the language.`
14+
},
15+
"details": {
16+
"description": `Required - informations about the file to download (size, format, etc.). `
17+
}
18+
}
19+
});
20+
21+
export default meta;
22+
23+
export const Default = getStory({
24+
"label": "Télécharger le document lorem ipsum sit dolores amet",
25+
"details": "JPG – 61,88 ko",
26+
linkProps: {
27+
href: "[À MODIFIER]"
28+
}
29+
});

0 commit comments

Comments
 (0)