Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion COMPONENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- [x] Summary
- [ ] Table
- [ ] Tag
- [ ] Download
- [x] Download
- [ ] Transcription
- [x] Tile
- [x] Input
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This module is a wrapper/compatibility layer for [@gouvfr/dsfr](https://github.c
- [x] No [white flash when reloading in SSR setup](https://github.com/codegouvfr/@codegouvfr/react-dsfr/issues/2#issuecomment-1257263480).
- [x] Most components are server component ready. The others are labeled with `"use client";`
- [x] [Perfect integration with all major React framework: Next.js (PagesDir and AppDir), Create React App, Vue](https://react-dsfr.etalab.studio/).
- [ ] All [the components](https://www.systeme-de-design.gouv.fr/elements-d-interface) are implemented (20/41, [see details](COMPONENTS.md))
- [ ] All [the components](https://www.systeme-de-design.gouv.fr/elements-d-interface) are implemented (21/41, [see details](COMPONENTS.md))
- [x] Three shakable distribution, cherry pick the components you import. (It's not all in a big .js bundle)
- [x] Optional integration with [MUI](https://mui.com/). If you use MUI components they will
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).
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
"./Highlight": "./dist/Highlight.js",
"./Header": "./dist/Header.js",
"./Footer": "./dist/Footer.js",
"./File": "./dist/File.js",
"./Download": "./dist/Download.js",
"./Display": "./dist/Display.js",
Comment on lines +151 to 153
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's automatically generated, you don't need to worry about that.

"./Checkbox": "./dist/Checkbox.js",
"./Card": "./dist/Card.js",
Expand Down
52 changes: 52 additions & 0 deletions src/Download.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { memo, forwardRef, type CSSProperties } from "react";
import { symToStr } from "tsafe/symToStr";
import { assert } from "tsafe/assert";
import type { Equals } from "tsafe";
import { fr } from "./fr";
import { cx } from "./tools/cx";
import { getLink } from "./link";
import { RegisteredLinkProps } from "./link";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always import types as type

Comment on lines +7 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { getLink } from "./link";
import { RegisteredLinkProps } from "./link";
import { getLink, type RegisteredLinkProps } from "./link";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just forgot to review my own PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem!


export type DownloadProps = {
className?: string;
style?: CSSProperties;
details: string;
label: string;
Comment on lines +13 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoses two can be ReactNode

linkProps: RegisteredLinkProps;
classes?: Partial<Record<"root" | "wrapper" | "link" | "details", string>>;
};

/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-download> */

export const Download = memo(
forwardRef<HTMLDivElement, DownloadProps>((props, ref) => {
const { className, style, details, label, linkProps, classes = {}, ...rest } = props;

const { Link } = getLink();

assert<Equals<keyof typeof rest, never>>();

return (
<div
className={cx(fr.cx("fr-download"), className, classes.root)}
style={style}
ref={ref}
>
<p className={cx(classes.wrapper)}>
<Link
{...linkProps}
download
className={cx(fr.cx("fr-download__link"), classes.link)}
>
{label}
<span className="fr-download__detail">{details}</span>
</Link>
</p>
</div>
);
})
);

Download.displayName = symToStr({ Download });

export default Download;
29 changes: 29 additions & 0 deletions stories/Download.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Download } from "../dist/Download";
import { sectionName } from "./sectionName";
import { getStoryFactory } from "./getStory";

const { meta, getStory } = getStoryFactory({
sectionName,
"wrappedComponent": { Download },
description: `
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/telechargement-de-fichier)
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/Download.tsx)`,
"argTypes": {
"label": {
"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.`
},
"details": {
"description": `Required - informations about the file to download (size, format, etc.). `
}
}
});

export default meta;

export const Default = getStory({
"label": "Télécharger le document lorem ipsum sit dolores amet",
"details": "JPG – 61,88 ko",
linkProps: {
href: "[À MODIFIER]"
}
});