Skip to content

Commit b58ff70

Browse files
committed
2 parents 0bddcd1 + 4cba708 commit b58ff70

File tree

5 files changed

+120
-4
lines changed

5 files changed

+120
-4
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Thank you so much to anyone that would!
55

66
To get you started you can check out [the `<Alert />` component](https://react-dsfr-components.etalab.studio/?path=/docs/components-alert--default).
77

8-
- Here is it's definition from the SIG: [systeme-de-design.gouv.fr/elements-d-interface/composants/alerte](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/alerte)
8+
- Here is it's definition from the SIG: [systeme-de-design.gouv.fr/elements-d-interface/composants/alerte](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/alerte) (Pro tip: the real source of tuth for DSFR component is [here](https://main--ds-gouv.netlify.app/example/component/))
99
- Here is its implementation [src/Alert.tsx](https://github.com/codegouvfr/react-dsfr/blob/main/src/Alert.tsx)
1010
- Here is the file that generates its documentation: [stories/Alert.stories.tsx](https://github.com/codegouvfr/react-dsfr/blob/main/stories/Alert.stories.tsx)
1111

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
<a href="https://stackblitz.com/edit/nextjs-j2wba3?file=pages/index.tsx">Playground</a>
2525
</p>
2626

27-
> 🗣️ Le **9 décembre (ce vendredi)** de **11h à 12h30**, venez assister à la présentation de la librairie et poser vos questions!
28-
> 👉[Lien du salon ateliers BlueHats](https://webinaire.numerique.gouv.fr//meeting/signin/362/creator/369/hash/84c9902a44b481830388d5d69c808eb669da0a5b)👈
27+
> 🗣️ Replay de l'atelier de présentation de la librairie [ici](https://bbb-dinum-scalelite.visio.education.fr/playback/presentation/2.3/22298bc9d93b53540248207bc3f9e31260f3b4f1-1670578779094).
2928
3029
This module is a wrapper/compatibility layer for [@gouvfr/dsfr](https://github.com/GouvernementFR/dsfr), the vanilla JS/CSS implementation of the DSFR.
3130

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codegouvfr/react-dsfr",
3-
"version": "0.0.94",
3+
"version": "0.0.95",
44
"description": "French State Design System React integration library",
55
"repository": {
66
"type": "git",
@@ -124,6 +124,7 @@
124124
"./mui": "./dist/mui.js",
125125
"./lib": "./dist/lib/index.js",
126126
"./Tabs": "./dist/Tabs.js",
127+
"./SkipLinks": "./dist/SkipLinks.js",
127128
"./Notice": "./dist/Notice.js",
128129
"./Highlight": "./dist/Highlight.js",
129130
"./Header": "./dist/Header/index.js",

src/SkipLinks.tsx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React, { forwardRef, memo } from "react";
2+
import { assert, Equals } from "tsafe";
3+
import { symToStr } from "tsafe/symToStr";
4+
import { fr } from "./lib";
5+
import { createComponentI18nApi } from "./lib/i18n";
6+
import { cx } from "./lib/tools/cx";
7+
8+
export type SkipLink = {
9+
label: string;
10+
anchor: `${string}`;
11+
};
12+
13+
export type SkipLinksProps = {
14+
className?: string;
15+
links: SkipLink[];
16+
classes?: Partial<Record<"root" | "list" | "link", string>>;
17+
};
18+
19+
/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-skiplinks> */
20+
export const SkipLinks = memo(
21+
forwardRef<HTMLDivElement, SkipLinksProps>((props, ref) => {
22+
const { className, classes = {}, links, ...rest } = props;
23+
const { t } = useTranslation();
24+
assert<Equals<keyof typeof rest, never>>();
25+
26+
return (
27+
<div className={cx(fr.cx("fr-skiplinks"), classes.root, className)} ref={ref} {...rest}>
28+
<nav className={fr.cx("fr-container")} role="navigation" aria-label={t("label")}>
29+
<ul className={cx(fr.cx("fr-skiplinks__list"), classes.list)}>
30+
{links &&
31+
links.map(link => (
32+
<li key={link.anchor}>
33+
<a
34+
className={cx(fr.cx("fr-link"), classes.link)}
35+
href={link.anchor}
36+
>
37+
{link.label}
38+
</a>
39+
</li>
40+
))}
41+
</ul>
42+
</nav>
43+
</div>
44+
);
45+
})
46+
);
47+
48+
SkipLinks.displayName = symToStr({ SkipLinks });
49+
50+
const { useTranslation, addSkipLinksTranslations } = createComponentI18nApi({
51+
"componentName": symToStr({ SkipLinks }),
52+
"frMessages": {
53+
/* spell-checker: disable */
54+
"label": "Accès rapide"
55+
/* spell-checker: enable */
56+
}
57+
});
58+
59+
addSkipLinksTranslations({
60+
"lang": "en",
61+
"messages": {
62+
"label": "Quick access"
63+
}
64+
});
65+
addSkipLinksTranslations({
66+
"lang": "es",
67+
"messages": {
68+
"label": "Acceso rapido"
69+
}
70+
});
71+
addSkipLinksTranslations({
72+
"lang": "de",
73+
"messages": {
74+
"label": "Schneller Zugang"
75+
}
76+
});
77+
78+
export default SkipLinks;

stories/SkipLinks.stories.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { SkipLinks } from "../dist/SkipLinks";
2+
import type { SkipLinksProps } from "../src/SkipLinks";
3+
import { sectionName } from "./sectionName";
4+
import { getStoryFactory } from "./getStory";
5+
6+
const { meta, getStory } = getStoryFactory<SkipLinksProps>({
7+
sectionName,
8+
wrappedComponent: { SkipLinks },
9+
description: `
10+
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/liens-d-evitement)
11+
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/SkipLinks.tsx)`
12+
});
13+
14+
export default meta;
15+
16+
export const Default = getStory({
17+
links: [
18+
{
19+
label: "Contenu",
20+
anchor: "#contenu"
21+
},
22+
{
23+
label: "Menu",
24+
anchor: "#header-navigation"
25+
},
26+
{
27+
label: "Recherche",
28+
anchor: "#header-search"
29+
},
30+
{
31+
label: "Pied de page",
32+
anchor: "#footer"
33+
}
34+
],
35+
classes: {
36+
root: "fr-mt-9v" // Just to fix storybook preview toolbar overlapping
37+
}
38+
});

0 commit comments

Comments
 (0)