diff --git a/src/AgentConnectButton.tsx b/src/AgentConnectButton.tsx index 98decc20a..4489341b6 100644 --- a/src/AgentConnectButton.tsx +++ b/src/AgentConnectButton.tsx @@ -1,57 +1,45 @@ -"use client"; -import React, { forwardRef, memo, useState, type CSSProperties } from "react"; +import React, { forwardRef, memo, type CSSProperties } from "react"; import { symToStr } from "tsafe/symToStr"; import { createComponentI18nApi } from "./i18n"; import { fr } from "./fr"; import { assert, type Equals } from "tsafe/assert"; -import agentconnectBtnPrincipalSvgUrl from "./assets/agentconnect-btn-principal.svg"; -import agentconnectBtnPrincipalHoverSvgUrl from "./assets/agentconnect-btn-principal-hover.svg"; -import agentconnectBtnAlternatifSvgUrl from "./assets/agentconnect-btn-alternatif.svg"; -import agentconnectBtnAlternatifHoverSvgUrl from "./assets/agentconnect-btn-alternatif-hover.svg"; import "./assets/agentconnect.css"; -import { useIsDark } from "./useIsDark"; -import { getAssetUrl } from "./tools/getAssetUrl"; import { cx } from "./tools/cx"; -export type AgentConnectButtonProps = { - className?: string; - url: string; - style?: CSSProperties; -}; +export type AgentConnectButtonProps = AgentConnectButtonProps.Common & + (AgentConnectButtonProps.WithUrl | AgentConnectButtonProps.WithOnClick); + +export namespace AgentConnectButtonProps { + export type Common = { + className?: string; + style?: CSSProperties; + }; + export type WithUrl = { + url: string; + onClick?: never; + }; + export type WithOnClick = { + url?: never; + onClick: React.MouseEventHandler; + }; +} /** @see */ export const AgentConnectButton = memo( forwardRef((props, ref) => { - const { className, url, style, ...rest } = props; + const { className, url: href, style, onClick, ...rest } = props; assert>(); const { t } = useTranslation(); - const [isMouseHover, setIsMouseHover] = useState(false); - - const { isDark } = useIsDark(); + const Inner = onClick !== undefined ? "button" : "a"; + const innerProps = (onClick !== undefined ? { onClick } : { href }) as any; return (
- setIsMouseHover(true)} - onMouseLeave={() => setIsMouseHover(false)} - > - - + +

>; - style?: CSSProperties; -}; +export type FranceConnectButtonProps = FranceConnectButtonProps.Common & + (FranceConnectButtonProps.WithUrl | FranceConnectButtonProps.WithOnClick); + +export namespace FranceConnectButtonProps { + export type Common = { + className?: string; + /** Default: false */ + plus?: boolean; + classes?: Partial>; + style?: CSSProperties; + }; + export type WithUrl = { + url: string; + onClick?: never; + }; + export type WithOnClick = { + url?: never; + onClick: React.MouseEventHandler; + }; +} /** @see */ export const FranceConnectButton = memo( forwardRef((props, ref) => { - const { classes = {}, className, url, plus = false, style, ...rest } = props; + const { classes = {}, className, url: href, plus = false, style, onClick, ...rest } = props; assert>(); const { t } = useTranslation(); + const Inner = onClick !== undefined ? "button" : "a"; + const innerProps = (onClick !== undefined ? { onClick } : { href }) as any; + return (

- + S’identifier avec FranceConnect{plus ? "+" : ""} - +

>; - style?: CSSProperties; -}; +export type FranceConnectButtonProps = FranceConnectButtonProps.Common & + (FranceConnectButtonProps.WithUrl | FranceConnectButtonProps.WithOnClick); + +export namespace FranceConnectButtonProps { + export type Common = { + className?: string; + classes?: Partial>; + style?: CSSProperties; + }; + export type WithUrl = { + url: string; + onClick?: never; + }; + export type WithOnClick = { + url?: never; + onClick: React.MouseEventHandler; + }; +} /** @see */ export const MonCompteProButton = memo( forwardRef((props, ref) => { - const { classes = {}, className, url, style, ...rest } = props; + const { classes = {}, className, url: href, style, onClick, ...rest } = props; assert>(); const { t } = useTranslation(); + const Inner = onClick !== undefined ? "button" : "a"; + const innerProps = (onClick !== undefined ? { onClick } : { href }) as any; + return (