|
| 1 | +"use client"; |
| 2 | +import React, { forwardRef, memo, useState, type CSSProperties } from "react"; |
| 3 | +import { symToStr } from "tsafe/symToStr"; |
| 4 | +import { createComponentI18nApi } from "./i18n"; |
| 5 | +import { fr } from "./fr"; |
| 6 | +import { assert, type Equals } from "tsafe/assert"; |
| 7 | +import agentconnectBtnPrincipalSvgUrl from "./assets/agentconnect-btn-principal.svg"; |
| 8 | +import agentconnectBtnPrincipalHoverSvgUrl from "./assets/agentconnect-btn-principal-hover.svg"; |
| 9 | +import agentconnectBtnAlternatifSvgUrl from "./assets/agentconnect-btn-alternatif.svg"; |
| 10 | +import agentconnectBtnAlternatifHoverSvgUrl from "./assets/agentconnect-btn-alternatif-hover.svg"; |
| 11 | +import { useIsDark } from "./useIsDark"; |
| 12 | +import { useColors } from "./useColors"; |
| 13 | +import { getAssetUrl } from "./tools/getAssetUrl"; |
| 14 | + |
| 15 | +export type AgentConnectButtonProps = { |
| 16 | + className?: string; |
| 17 | + redirectUrl: string; |
| 18 | + style?: CSSProperties; |
| 19 | +}; |
| 20 | + |
| 21 | +/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-franceconnectbutton> */ |
| 22 | +export const AgentConnectButton = memo( |
| 23 | + forwardRef<HTMLDivElement, AgentConnectButtonProps>((props, ref) => { |
| 24 | + const { className, redirectUrl, style, ...rest } = props; |
| 25 | + |
| 26 | + assert<Equals<keyof typeof rest, never>>(); |
| 27 | + |
| 28 | + const { t } = useTranslation(); |
| 29 | + |
| 30 | + const [isMouseHover, setIsMouseHover] = useState(false); |
| 31 | + |
| 32 | + const { isDark } = useIsDark(); |
| 33 | + const theme = useColors(); |
| 34 | + |
| 35 | + return ( |
| 36 | + <div className={className} style={style} ref={ref}> |
| 37 | + <a |
| 38 | + href={redirectUrl} |
| 39 | + style={{ |
| 40 | + "display": "block", |
| 41 | + "backgroundImage": "unset" |
| 42 | + }} |
| 43 | + onMouseEnter={() => setIsMouseHover(true)} |
| 44 | + onMouseLeave={() => setIsMouseHover(false)} |
| 45 | + > |
| 46 | + <img |
| 47 | + src={getAssetUrl( |
| 48 | + isDark |
| 49 | + ? isMouseHover |
| 50 | + ? agentconnectBtnAlternatifHoverSvgUrl |
| 51 | + : agentconnectBtnAlternatifSvgUrl |
| 52 | + : isMouseHover |
| 53 | + ? agentconnectBtnPrincipalHoverSvgUrl |
| 54 | + : agentconnectBtnPrincipalSvgUrl |
| 55 | + )} |
| 56 | + /> |
| 57 | + </a> |
| 58 | + <a |
| 59 | + style={{ |
| 60 | + "display": "inline-block", |
| 61 | + "marginTop": fr.spacing("1v"), |
| 62 | + "color": theme.decisions.text.actionHigh.blueFrance.default |
| 63 | + }} |
| 64 | + className={fr.cx("fr-text--sm")} |
| 65 | + href="https://agentconnect.gouv.fr/" |
| 66 | + target="_blank" |
| 67 | + > |
| 68 | + {t("what is AgentConnect ?")} |
| 69 | + </a> |
| 70 | + </div> |
| 71 | + ); |
| 72 | + }) |
| 73 | +); |
| 74 | + |
| 75 | +AgentConnectButton.displayName = symToStr({ AgentConnectButton }); |
| 76 | + |
| 77 | +export default AgentConnectButton; |
| 78 | + |
| 79 | +const { useTranslation, addAgentConnectButtonTranslations } = createComponentI18nApi({ |
| 80 | + "componentName": symToStr({ AgentConnectButton }), |
| 81 | + "frMessages": { |
| 82 | + /* spell-checker: disable */ |
| 83 | + "what is AgentConnect ?": "Qu’est-ce que AgentConnect ?" |
| 84 | + /* spell-checker: enable */ |
| 85 | + } |
| 86 | +}); |
| 87 | + |
| 88 | +addAgentConnectButtonTranslations({ |
| 89 | + "lang": "en", |
| 90 | + "messages": { |
| 91 | + "what is AgentConnect ?": "What's AgentConnect ?" |
| 92 | + } |
| 93 | +}); |
| 94 | + |
| 95 | +export { addAgentConnectButtonTranslations }; |
0 commit comments