Skip to content

Commit daa8782

Browse files
committed
#129 Add mon compte pro
1 parent 459f2a8 commit daa8782

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

.storybook/preview.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const { getHardCodedWeight } = (() => {
110110
"components/Button",
111111
"components/FranceConnectButton",
112112
"components/AgentConnectButton",
113+
"components/MonCompteProButton"
113114
];
114115

115116
function getHardCodedWeight(kind) {

src/MonCompteProButton.tsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
className?: string;
11+
url: string;
12+
classes?: Partial<Record<"root" | "login" | "brand", string>>;
13+
style?: CSSProperties;
14+
};
15+
16+
/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-franceconnectbutton> */
17+
export const MonCompteProButton = memo(
18+
forwardRef<HTMLDivElement, FranceConnectButtonProps>((props, ref) => {
19+
const { classes = {}, className, url, style, ...rest } = props;
20+
21+
assert<Equals<keyof typeof rest, never>>();
22+
23+
const { t } = useTranslation();
24+
25+
return (
26+
<div
27+
className={cx(fr.cx("fr-connect-group"), classes.root, className)}
28+
style={style}
29+
ref={ref}
30+
>
31+
<a className={cx(fr.cx("fr-btn", "fr-connect"), "moncomptepro-button")} href={url}>
32+
<span className={cx(fr.cx("fr-connect__login"), classes.login)}>
33+
S’identifier avec
34+
</span>
35+
<span className={cx(fr.cx("fr-connect__brand"), classes.brand)}>
36+
MonComptePro
37+
</span>
38+
</a>
39+
<p>
40+
<a
41+
href="https://moncomptepro.beta.gouv.fr/"
42+
target="_blank"
43+
rel="noopener"
44+
title={`${t("what is service")} - ${t("new window")}`}
45+
>
46+
{t("what is service")}
47+
</a>
48+
</p>
49+
</div>
50+
);
51+
})
52+
);
53+
54+
MonCompteProButton.displayName = symToStr({ MonCompteProButton });
55+
56+
export default MonCompteProButton;
57+
58+
const { useTranslation, addMonCompteProButtonTranslations } = createComponentI18nApi({
59+
"componentName": symToStr({ MonCompteProButton }),
60+
"frMessages": {
61+
/* spell-checker: disable */
62+
"what is service": "Qu’est-ce que MonComptePro ?",
63+
"new window": "nouvelle fenêtre"
64+
/* spell-checker: enable */
65+
}
66+
});
67+
68+
addMonCompteProButtonTranslations({
69+
"lang": "en",
70+
"messages": {
71+
"what is service": "What's MonComptePro",
72+
"new window": "new window"
73+
}
74+
});
75+
76+
export { addMonCompteProButtonTranslations };

src/assets/moncomptepro.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stories/MonComptePro.stories.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { MonCompteProButton } from "../dist/MonCompteProButton";
2+
import { sectionName } from "./sectionName";
3+
import { getStoryFactory } from "./getStory";
4+
5+
const { meta, getStory } = getStoryFactory({
6+
sectionName,
7+
"wrappedComponent": { MonCompteProButton },
8+
"description": `
9+
- [See MonComptePro documentation](https://github.com/betagouv/moncomptepro#sp%C3%A9cifications-visuelles)
10+
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/MonCompteProButton.tsx)`
11+
});
12+
13+
export default meta;
14+
15+
export const Default = getStory({
16+
"url": "https://example.com"
17+
});
18+
19+
export const Centered = getStory({
20+
"style": {
21+
"textAlign": "center"
22+
},
23+
"url": "https://example.com"
24+
});

0 commit comments

Comments
 (0)