UNPKG

3.27 kBTypeScriptView Raw
1import React, { forwardRef, memo, type CSSProperties } from "react";
2import { symToStr } from "tsafe/symToStr";
3import { createComponentI18nApi } from "./i18n";
4import { fr } from "./fr";
5import { assert, type Equals } from "tsafe/assert";
6import { cx } from "./tools/cx";
7import "./assets/moncomptepro.css";
8
9export type FranceConnectButtonProps =
10 | FranceConnectButtonProps.WithUrl
11 | FranceConnectButtonProps.WithOnClick;
12
13export 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/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/components-franceconnectbutton> */
31export 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://moncomptepro.beta.gouv.fr/"
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
75MonCompteProButton.displayName = symToStr({ MonCompteProButton });
76
77export default MonCompteProButton;
78
79const { useTranslation, addMonCompteProButtonTranslations } = createComponentI18nApi({
80 "componentName": symToStr({ MonCompteProButton }),
81 "frMessages": {
82 /* spell-checker: disable */
83 "what is service": "Qu’est-ce que MonComptePro ?",
84 "new window": "nouvelle fenêtre"
85 /* spell-checker: enable */
86 }
87});
88
89addMonCompteProButtonTranslations({
90 "lang": "en",
91 "messages": {
92 "what is service": "What's MonComptePro",
93 "new window": "new window"
94 }
95});
96
97export { addMonCompteProButtonTranslations };
98
\No newline at end of file