-
Notifications
You must be signed in to change notification settings - Fork 85
Feature / Download component #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ | |
| - [x] Summary | ||
| - [ ] Table | ||
| - [ ] Tag | ||
| - [ ] Download | ||
| - [x] Download | ||
| - [ ] Transcription | ||
| - [x] Tile | ||
| - [x] Input | ||
| 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"; | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always import types as
Comment on lines
+7
to
+8
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, just forgot to review my own PR
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoses two can be |
||||||||
| 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; | ||||||||
| 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]" | ||
| } | ||
| }); |
There was a problem hiding this comment.
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.