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 "./assets/agentconnect.css";
|
7 | import { cx } from "./tools/cx";
|
8 |
|
9 | export type AgentConnectButtonProps =
|
10 | | AgentConnectButtonProps.WithUrl
|
11 | | AgentConnectButtonProps.WithOnClick;
|
12 |
|
13 | export namespace AgentConnectButtonProps {
|
14 | type Common = {
|
15 | className?: string;
|
16 | id?: string;
|
17 | style?: CSSProperties;
|
18 | };
|
19 | export type WithUrl = Common & {
|
20 | url: string;
|
21 | onClick?: never;
|
22 | };
|
23 | export type WithOnClick = Common & {
|
24 | url?: never;
|
25 | onClick: React.MouseEventHandler<HTMLButtonElement>;
|
26 | };
|
27 | }
|
28 |
|
29 |
|
30 | export const AgentConnectButton = memo(
|
31 | forwardRef<HTMLDivElement, AgentConnectButtonProps>((props, ref) => {
|
32 | const { className, url: href, style, onClick, id: id_props, ...rest } = props;
|
33 |
|
34 | assert<Equals<keyof typeof rest, never>>();
|
35 |
|
36 | const { t } = useTranslation();
|
37 |
|
38 | const Inner = onClick !== undefined ? "button" : "a";
|
39 |
|
40 | return (
|
41 | <div
|
42 | id={id_props ?? "fr-agentconnect-button"}
|
43 | className={className}
|
44 | style={style}
|
45 | ref={ref}
|
46 | >
|
47 | <span className="agentconnect-button__preload-hover" />
|
48 | <Inner
|
49 | className="agentconnect-button__link"
|
50 | {...((onClick !== undefined ? { onClick } : { href }) as any)}
|
51 | />
|
52 | <p>
|
53 | <a
|
54 | className={cx(
|
55 | "agentconnect-button__hint",
|
56 | fr.cx("fr-text--sm", "fr-mt-1v")
|
57 | )}
|
58 | href="https:
|
59 | target="_blank"
|
60 | >
|
61 | {t("what is AgentConnect ?")}
|
62 | </a>
|
63 | </p>
|
64 | </div>
|
65 | );
|
66 | })
|
67 | );
|
68 |
|
69 | AgentConnectButton.displayName = symToStr({ AgentConnectButton });
|
70 |
|
71 | export default AgentConnectButton;
|
72 |
|
73 | const { useTranslation, addAgentConnectButtonTranslations } = createComponentI18nApi({
|
74 | "componentName": symToStr({ AgentConnectButton }),
|
75 | "frMessages": {
|
76 |
|
77 | "what is AgentConnect ?": "Qu’est-ce que AgentConnect ?"
|
78 |
|
79 | }
|
80 | });
|
81 |
|
82 | addAgentConnectButtonTranslations({
|
83 | "lang": "en",
|
84 | "messages": {
|
85 | "what is AgentConnect ?": "What's AgentConnect ?"
|
86 | }
|
87 | });
|
88 |
|
89 | export { addAgentConnectButtonTranslations };
|
90 |
|
\ | No newline at end of file |