|
| 1 | +import React, { forwardRef, memo, type CSSProperties } from "react"; |
| 2 | +import { symToStr } from "tsafe/symToStr"; |
| 3 | +import { createComponentI18nApi } from "./i18n"; |
| 4 | +import { fr } from "./fr"; |
| 5 | +import { assert, type Equals } from "tsafe/assert"; |
| 6 | +import { cx } from "./tools/cx"; |
| 7 | +import "./assets/moncomptepro.css"; |
| 8 | + |
| 9 | +export type FranceConnectButtonProps = { |
| 10 | + className?: string; |
| 11 | + url: string; |
| 12 | + classes?: Partial<Record<"root" | "login" | "brand", string>>; |
| 13 | + style?: CSSProperties; |
| 14 | +}; |
| 15 | + |
| 16 | +/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-franceconnectbutton> */ |
| 17 | +export const MonCompteProButton = memo( |
| 18 | + forwardRef<HTMLDivElement, FranceConnectButtonProps>((props, ref) => { |
| 19 | + const { classes = {}, className, url, style, ...rest } = props; |
| 20 | + |
| 21 | + assert<Equals<keyof typeof rest, never>>(); |
| 22 | + |
| 23 | + const { t } = useTranslation(); |
| 24 | + |
| 25 | + return ( |
| 26 | + <div |
| 27 | + className={cx(fr.cx("fr-connect-group"), classes.root, className)} |
| 28 | + style={style} |
| 29 | + ref={ref} |
| 30 | + > |
| 31 | + <a className={cx(fr.cx("fr-btn", "fr-connect"), "moncomptepro-button")} href={url}> |
| 32 | + <span className={cx(fr.cx("fr-connect__login"), classes.login)}> |
| 33 | + S’identifier avec |
| 34 | + </span> |
| 35 | + <span className={cx(fr.cx("fr-connect__brand"), classes.brand)}> |
| 36 | + MonComptePro |
| 37 | + </span> |
| 38 | + </a> |
| 39 | + <p> |
| 40 | + <a |
| 41 | + href="https://moncomptepro.beta.gouv.fr/" |
| 42 | + target="_blank" |
| 43 | + rel="noopener" |
| 44 | + title={`${t("what is service")} - ${t("new window")}`} |
| 45 | + > |
| 46 | + {t("what is service")} |
| 47 | + </a> |
| 48 | + </p> |
| 49 | + </div> |
| 50 | + ); |
| 51 | + }) |
| 52 | +); |
| 53 | + |
| 54 | +MonCompteProButton.displayName = symToStr({ MonCompteProButton }); |
| 55 | + |
| 56 | +export default MonCompteProButton; |
| 57 | + |
| 58 | +const { useTranslation, addMonCompteProButtonTranslations } = createComponentI18nApi({ |
| 59 | + "componentName": symToStr({ MonCompteProButton }), |
| 60 | + "frMessages": { |
| 61 | + /* spell-checker: disable */ |
| 62 | + "what is service": "Qu’est-ce que MonComptePro ?", |
| 63 | + "new window": "nouvelle fenêtre" |
| 64 | + /* spell-checker: enable */ |
| 65 | + } |
| 66 | +}); |
| 67 | + |
| 68 | +addMonCompteProButtonTranslations({ |
| 69 | + "lang": "en", |
| 70 | + "messages": { |
| 71 | + "what is service": "What's MonComptePro", |
| 72 | + "new window": "new window" |
| 73 | + } |
| 74 | +}); |
| 75 | + |
| 76 | +export { addMonCompteProButtonTranslations }; |
0 commit comments