diff --git a/src/BackToTop.tsx b/src/BackToTop.tsx new file mode 100644 index 000000000..3761f91e2 --- /dev/null +++ b/src/BackToTop.tsx @@ -0,0 +1,47 @@ +import React from "react"; +import { forwardRef, memo } from "react"; +import { cx } from "./tools/cx"; +import { fr } from "./fr"; +import { symToStr } from "tsafe/symToStr"; +import { createComponentI18nApi } from "./i18n"; + +export type BackToTopProps = { + anchor?: string; + right?: boolean; +}; + +export const BackToTop = memo( + forwardRef((props, ref) => { + const { t } = useTranslation(); + const { anchor = "#top", right = false } = props; + return ( +
+ + {t("page top")} + +
+ ); + }) +); + +BackToTop.displayName = symToStr({ BackToTop }); + +export default BackToTop; + +const { useTranslation, addBackToTopTranslations } = createComponentI18nApi({ + "componentName": symToStr({ BackToTop }), + "frMessages": { + "page top": "Haut de page" + } +}); + +addBackToTopTranslations({ + lang: "en", + messages: { + "page top": "Top of the page" + } +}); diff --git a/stories/BackToTop.stories.tsx b/stories/BackToTop.stories.tsx new file mode 100644 index 000000000..967972cc5 --- /dev/null +++ b/stories/BackToTop.stories.tsx @@ -0,0 +1,25 @@ +import { BackToTop } from "../dist/BackToTop"; +import { getStoryFactory } from "./getStory"; +import { sectionName } from "./sectionName"; + +const { meta, getStory } = getStoryFactory({ + sectionName, + "wrappedComponent": { BackToTop }, + "description": `- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/retour-en-haut-de-page/) +- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/BackToTop.tsx)`, + // "argTypes": { + // "anchor": { + // "control": { "type": null }, + // "defaultValue": "#top" + // }, + // "right": { + // "control": { "type": null }, + // "description": "Align to right" + // } + // }, + "disabledProps": ["lang"] +}); + +export default meta; + +export const Default = getStory({});