Skip to content

Commit a45ae98

Browse files
committed
Update playground link in readme
1 parent 0bddcd1 commit a45ae98

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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
29+
className={cx(fr.cx("fr-container"))}
30+
role="navigation"
31+
aria-label={t("label")}
32+
>
33+
<ul className={cx(fr.cx("fr-skiplinks__list"), classes.list)}>
34+
{links &&
35+
links.map(link => (
36+
<li key={link.anchor}>
37+
<a
38+
className={cx(fr.cx("fr-link"), classes.link)}
39+
href={`#${link.anchor}`}
40+
>
41+
{link.label}
42+
</a>
43+
</li>
44+
))}
45+
</ul>
46+
</nav>
47+
</div>
48+
);
49+
})
50+
);
51+
52+
SkipLinks.displayName = symToStr({ SkipLinks });
53+
54+
const { useTranslation, addSkipLinksTranslations } = createComponentI18nApi({
55+
"componentName": symToStr({ SkipLinks }),
56+
"frMessages": {
57+
/* spell-checker: disable */
58+
"label": "Accès rapide"
59+
/* spell-checker: enable */
60+
}
61+
});
62+
63+
addSkipLinksTranslations({
64+
"lang": "en",
65+
"messages": {
66+
"label": "Quick access"
67+
}
68+
});
69+
addSkipLinksTranslations({
70+
"lang": "es",
71+
"messages": {
72+
"label": "Acceso rapido"
73+
}
74+
});
75+
addSkipLinksTranslations({
76+
"lang": "de",
77+
"messages": {
78+
"label": "Schneller Zugang"
79+
}
80+
});
81+
82+
export default SkipLinks;

stories/SkipLinks.stories.tsx

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

0 commit comments

Comments
 (0)