-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Add FranceConnect and MonComptePerso connexion buttons (#128)
* feat: ✨ Add FranceConnect and MonComptePerso connexion buttons * fixup review
- Loading branch information
Showing
3 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React, { forwardRef, memo } from "react"; | ||
import { symToStr } from "tsafe/symToStr"; | ||
import { createComponentI18nApi } from "./i18n"; | ||
import { cx } from "./tools/cx"; | ||
import { fr } from "./fr"; | ||
import { getLink } from "./link"; | ||
|
||
export enum Service { | ||
AGENT_CONNECT, | ||
FRANCE_CONNECT, | ||
FRANCE_CONNECT_PLUS, | ||
MON_COMPTE_PRO | ||
} | ||
|
||
const services = { | ||
[Service.AGENT_CONNECT]: { | ||
name: "AgentConnect", | ||
url: "https://agentconnect.gouv.fr/", | ||
class: "fr-agentconnect" | ||
}, | ||
[Service.FRANCE_CONNECT]: { | ||
name: "FranceConnect", | ||
url: "https://franceconnect.gouv.fr/", | ||
class: "" | ||
}, | ||
[Service.FRANCE_CONNECT_PLUS]: { | ||
name: "FranceConnect+", | ||
url: "https://franceconnect.gouv.fr/france-connect-plus", | ||
class: "fr-connect--plus" | ||
}, | ||
[Service.MON_COMPTE_PRO]: { | ||
name: "MonComptePro", | ||
url: "https://moncomptepro.beta.gouv.fr/", | ||
class: "fr-moncomptepro" | ||
} | ||
}; | ||
|
||
export type ConnectButtonProps = { | ||
classes?: Partial<Record<"root", string>>; | ||
className?: string; | ||
loginUrl: string; | ||
service: Service; | ||
}; | ||
|
||
const ConnectButton = memo( | ||
forwardRef<HTMLDivElement, ConnectButtonProps>((props, ref) => { | ||
const { classes = {}, className, loginUrl, service } = props; | ||
const { t } = useTranslation(); | ||
const { Link } = getLink(); | ||
|
||
const _service = services[service]; | ||
|
||
return ( | ||
<div className={cx(fr.cx("fr-connect-group"), className, classes?.root)} ref={ref}> | ||
<form action={loginUrl} method="post" className="fr-m-0"> | ||
<button className={cx(fr.cx("fr-connect"), _service.class)}> | ||
<span className="fr-connect__login">{t("identify with")}</span> | ||
<span className="fr-connect__brand">{_service.name}</span> | ||
</button> | ||
</form> | ||
<p> | ||
<Link | ||
href={_service.url} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
title={`${t("what is", _service.name)} - nouvelle fenêtre`} | ||
> | ||
{t("what is", _service.name)} | ||
</Link> | ||
</p> | ||
</div> | ||
); | ||
}) | ||
); | ||
|
||
ConnectButton.displayName = symToStr({ ConnectButton }); | ||
|
||
export default ConnectButton; | ||
|
||
const { useTranslation } = createComponentI18nApi({ | ||
"componentName": symToStr({ ConnectButton }), | ||
"frMessages": { | ||
/* spell-checker: disable */ | ||
"identify with": "S’identifier avec", | ||
"what is": (service: string) => `Qu’est-ce que ${service} ?` | ||
/* spell-checker: enable */ | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import ConnectButton, { Service } from "../dist/ConnectButton"; | ||
import { sectionName } from "./sectionName"; | ||
import { getStoryFactory } from "./getStory"; | ||
|
||
const { meta, getStory } = getStoryFactory({ | ||
sectionName, | ||
"wrappedComponent": { ConnectButton }, | ||
"description": ` | ||
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/bouton-franceconnect/) | ||
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/FranceConnect.tsx)`, | ||
"disabledProps": ["lang"] | ||
}); | ||
|
||
export default meta; | ||
|
||
export const Default = getStory({ | ||
"loginUrl": "https://dummy", | ||
service: Service.FRANCE_CONNECT | ||
}); | ||
|
||
export const FranceConnect = getStory({ | ||
"loginUrl": "https://dummy", | ||
service: Service.FRANCE_CONNECT | ||
}); | ||
|
||
export const FranceConnectPlus = getStory({ | ||
"loginUrl": "https://dummy", | ||
service: Service.FRANCE_CONNECT_PLUS | ||
}); | ||
|
||
export const AgentConnect = getStory({ | ||
"loginUrl": "https://dummy", | ||
service: Service.AGENT_CONNECT | ||
}); | ||
|
||
export const MonComptePro = getStory({ | ||
"loginUrl": "https://dummy", | ||
service: Service.MON_COMPTE_PRO | ||
}); |