-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathProConnectButton.tsx
More file actions
105 lines (92 loc) · 3.39 KB
/
Copy pathProConnectButton.tsx
File metadata and controls
105 lines (92 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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 { cx } from "./tools/cx";
import { useAnalyticsId } from "./tools/useAnalyticsId";
import "./assets/proconnect-btn.css";
export type ProConnectButtonProps =
| ProConnectButtonProps.WithUrl
| ProConnectButtonProps.WithOnClick;
export namespace ProConnectButtonProps {
type Common = {
id?: string;
className?: string;
/** Default: false */
classes?: Partial<Record<"root" | "login" | "brand", string>>;
style?: CSSProperties;
};
export type WithUrl = Common & {
url: string;
onClick?: never;
};
export type WithOnClick = Common & {
url?: never;
onClick: React.MouseEventHandler<HTMLButtonElement>;
};
}
/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/components-proconnectbutton> */
export const ProConnectButton = memo(
forwardRef<HTMLDivElement, ProConnectButtonProps>((props, ref) => {
const { classes = {}, className, url: href, style, onClick, id: id_props, ...rest } = props;
assert<Equals<keyof typeof rest, never>>();
const id = useAnalyticsId({
"defaultIdPrefix": "fr-proconnect-button",
"explicitlyProvidedId": id_props
});
const { t } = useTranslation();
const Inner = onClick !== undefined ? "button" : "a";
const innerProps = (onClick !== undefined ? { onClick } : { href }) as any;
return (
<div
id={id}
className={cx(fr.cx("fr-connect-group"), classes.root, className)}
style={style}
ref={ref}
>
<Inner
id={`${id}-button`}
className={cx(fr.cx("fr-btn", "fr-connect"), "pro-connect")}
{...innerProps}
>
<span className={cx(fr.cx("fr-connect__login"), classes.login)}>
S’identifier avec
</span>
<span className={cx(fr.cx("fr-connect__brand"), classes.brand)}>
ProConnect
</span>
</Inner>
<p>
<a
href={"https://www.proconnect.gouv.fr/"}
target="_blank"
rel="noopener"
title={`${t("what is service")} - ${t("new window")}`}
>
{t("what is service")}
</a>
</p>
</div>
);
})
);
ProConnectButton.displayName = symToStr({ ProConnectButton });
export default ProConnectButton;
const { useTranslation, addProConnectButtonTranslations } = createComponentI18nApi({
"componentName": symToStr({ ProConnectButton }),
"frMessages": {
/* spell-checker: disable */
"what is service": "Qu’est-ce que ProConnect ?",
"new window": "nouvelle fenêtre"
/* spell-checker: enable */
}
});
addProConnectButtonTranslations({
"lang": "en",
"messages": {
"what is service": "What's ProConnect?",
"new window": "new window"
}
});
export { addProConnectButtonTranslations };