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 | | FranceConnectButtonProps.WithUrl
|
11 | | FranceConnectButtonProps.WithOnClick;
|
12 |
|
13 | export namespace FranceConnectButtonProps {
|
14 | type Common = {
|
15 | id?: string;
|
16 | className?: string;
|
17 | classes?: Partial<Record<"root" | "login" | "brand", string>>;
|
18 | style?: CSSProperties;
|
19 | };
|
20 | export type WithUrl = Common & {
|
21 | url: string;
|
22 | onClick?: never;
|
23 | };
|
24 | export type WithOnClick = Common & {
|
25 | url?: never;
|
26 | onClick: React.MouseEventHandler<HTMLButtonElement>;
|
27 | };
|
28 | }
|
29 |
|
30 |
|
31 | export const MonCompteProButton = memo(
|
32 | forwardRef<HTMLDivElement, FranceConnectButtonProps>((props, ref) => {
|
33 | const { classes = {}, className, url: href, style, onClick, id: id_props, ...rest } = props;
|
34 |
|
35 | assert<Equals<keyof typeof rest, never>>();
|
36 |
|
37 | const { t } = useTranslation();
|
38 |
|
39 | const Inner = onClick !== undefined ? "button" : "a";
|
40 | const innerProps = (onClick !== undefined ? { onClick } : { href }) as any;
|
41 |
|
42 | return (
|
43 | <div
|
44 | id={id_props ?? "fr-moncomptepro"}
|
45 | className={cx(fr.cx("fr-connect-group"), classes.root, className)}
|
46 | style={style}
|
47 | ref={ref}
|
48 | >
|
49 | <Inner
|
50 | className={cx(fr.cx("fr-btn", "fr-connect"), "moncomptepro-button")}
|
51 | {...innerProps}
|
52 | >
|
53 | <span className={cx(fr.cx("fr-connect__login"), classes.login)}>
|
54 | S’identifier avec
|
55 | </span>
|
56 | <span className={cx(fr.cx("fr-connect__brand"), classes.brand)}>
|
57 | MonComptePro
|
58 | </span>
|
59 | </Inner>
|
60 | <p>
|
61 | <a
|
62 | href="https:
|
63 | target="_blank"
|
64 | rel="noopener"
|
65 | title={`${t("what is service")} - ${t("new window")}`}
|
66 | >
|
67 | {t("what is service")}
|
68 | </a>
|
69 | </p>
|
70 | </div>
|
71 | );
|
72 | })
|
73 | );
|
74 |
|
75 | MonCompteProButton.displayName = symToStr({ MonCompteProButton });
|
76 |
|
77 | export default MonCompteProButton;
|
78 |
|
79 | const { useTranslation, addMonCompteProButtonTranslations } = createComponentI18nApi({
|
80 | "componentName": symToStr({ MonCompteProButton }),
|
81 | "frMessages": {
|
82 |
|
83 | "what is service": "Qu’est-ce que MonComptePro ?",
|
84 | "new window": "nouvelle fenêtre"
|
85 |
|
86 | }
|
87 | });
|
88 |
|
89 | addMonCompteProButtonTranslations({
|
90 | "lang": "en",
|
91 | "messages": {
|
92 | "what is service": "What's MonComptePro",
|
93 | "new window": "new window"
|
94 | }
|
95 | });
|
96 |
|
97 | export { addMonCompteProButtonTranslations };
|
98 |
|
\ | No newline at end of file |