Skip to content

Commit 2a5abb6

Browse files
committed
Permettre l'ajout d'un bandeau d'information
1 parent 9c026ca commit 2a5abb6

File tree

6 files changed

+80
-4
lines changed

6 files changed

+80
-4
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Several environment variables can be used to tailor the theme to your needs:
2929
DSFR_THEME_HOME_URL
3030
DSFR_THEME_SERVICE_TITLE
3131
DSFR_THEME_BRAND_TOP
32+
DSFR_NOTICE_TITLE
33+
DSFR_NOTICE_DESCRIPTION
34+
DSFR_NOTICE_SEVERITY
3235
```
3336

3437
These variables should be made available to the process running Keycloak on your server.
@@ -44,6 +47,12 @@ If you are deploying Keycloak on Kubernetes using Helm, here's how to configure
4447
value: CodeGouv
4548
- name: DSFR_THEME_BRAND_TOP
4649
value: "République<br/>Française"
50+
- name: DSFR_NOTICE_TITLE
51+
value: Title
52+
- name: DSFR_NOTICE_DESCRIPTION
53+
value: Description
54+
- name: DSFR_NOTICE_SEVERITY
55+
value: info
4756
...
4857
```
4958

src/account/Template.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import { Header as DsfrHeader } from "@codegouvfr/react-dsfr/Header";
1313
import { Footer as DsfrFooter } from "@codegouvfr/react-dsfr/Footer";
1414
import { SideMenu } from "@codegouvfr/react-dsfr/SideMenu";
1515
import { Alert } from "@codegouvfr/react-dsfr/Alert";
16+
import { Notice } from "@codegouvfr/react-dsfr/Notice";
1617
import { headerFooterDisplayItem } from "@codegouvfr/react-dsfr/Display";
1718
import { fr } from "@codegouvfr/react-dsfr";
1819
import { getColorScheme } from "../shared/getColorScheme";
20+
import { getNoticeSeverityOrDefault } from "../shared/noticeSeverity";
1921

2022
startReactDsfr({ defaultColorScheme: getColorScheme() ?? "system" });
2123

@@ -83,6 +85,26 @@ export default function Template(props: TemplateProps<KcContext, I18n>) {
8385
]}
8486
/>
8587

88+
{(kcContext.properties.DSFR_NOTICE_TITLE || kcContext.properties.DSFR_NOTICE_DESCRIPTION) && (
89+
<Notice
90+
severity={getNoticeSeverityOrDefault(kcContext.properties.DSFR_NOTICE_SEVERITY)}
91+
title={
92+
<span
93+
dangerouslySetInnerHTML={{
94+
__html: kcContext.properties.DSFR_NOTICE_TITLE
95+
}}
96+
/>
97+
}
98+
description={
99+
<span
100+
dangerouslySetInnerHTML={{
101+
__html: kcContext.properties.DSFR_NOTICE_DESCRIPTION
102+
}}
103+
/>
104+
}
105+
/>
106+
)}
107+
86108
<div
87109
className={fr.cx("fr-container")}
88110
style={{

src/kc.gen.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This file is auto-generated by the `update-kc-gen` command. Do not edit it manually.
2-
// Hash: 3b508e89452af5c2abfd702000cd0e56db6739ec9016997d6b32b8ac1f39195d
2+
// Hash: 415229e332a814cae52152aa8f2b43dab69ceadc6ed220a115d8a8349abbde0b
33

44
/* eslint-disable */
55

@@ -16,18 +16,27 @@ export const themeNames: ThemeName[] = ["DSFR"];
1616
export type KcEnvName =
1717
| "DSFR_THEME_HOME_URL"
1818
| "DSFR_THEME_SERVICE_TITLE"
19-
| "DSFR_THEME_BRAND_TOP";
19+
| "DSFR_THEME_BRAND_TOP"
20+
| "DSFR_NOTICE_TITLE"
21+
| "DSFR_NOTICE_DESCRIPTION"
22+
| "DSFR_NOTICE_SEVERITY";
2023

2124
export const kcEnvNames: KcEnvName[] = [
2225
"DSFR_THEME_HOME_URL",
2326
"DSFR_THEME_SERVICE_TITLE",
24-
"DSFR_THEME_BRAND_TOP"
27+
"DSFR_THEME_BRAND_TOP",
28+
"DSFR_NOTICE_TITLE",
29+
"DSFR_NOTICE_DESCRIPTION",
30+
"DSFR_NOTICE_SEVERITY"
2531
];
2632

2733
export const kcEnvDefaults: Record<KcEnvName, string> = {
2834
DSFR_THEME_HOME_URL: "",
2935
DSFR_THEME_SERVICE_TITLE: "",
30-
DSFR_THEME_BRAND_TOP: "République<br/>Française"
36+
DSFR_THEME_BRAND_TOP: "République<br/>Française",
37+
DSFR_NOTICE_TITLE: "Mon super titre",
38+
DSFR_NOTICE_DESCRIPTION: "Ma super description",
39+
DSFR_NOTICE_SEVERITY: "info"
3140
};
3241

3342
/**

src/login/Template.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import { redirectUrlOrigin } from "./shared/redirectUrlOrigin";
1212
import { headerFooterDisplayItem } from "@codegouvfr/react-dsfr/Display";
1313
import { Footer as DSFRFooter } from "@codegouvfr/react-dsfr/Footer";
1414
import { Alert } from "@codegouvfr/react-dsfr/Alert";
15+
import { Notice } from "@codegouvfr/react-dsfr/Notice";
1516
import { fr } from "@codegouvfr/react-dsfr";
1617
import "@codegouvfr/react-dsfr/main.css";
1718
import { startReactDsfr } from "@codegouvfr/react-dsfr/spa";
1819
import { getColorScheme } from "../shared/getColorScheme";
20+
import { getNoticeSeverityOrDefault, isNoticeSeverity } from "../shared/noticeSeverity";
1921

2022
startReactDsfr({ defaultColorScheme: getColorScheme() ?? "system" });
2123

@@ -90,6 +92,25 @@ export default function Template(props: Props) {
9092
}
9193
/>
9294
<main role="main" id="content">
95+
{(kcContext.properties.DSFR_NOTICE_TITLE || kcContext.properties.DSFR_NOTICE_DESCRIPTION) && (
96+
<Notice
97+
severity={getNoticeSeverityOrDefault(kcContext.properties.DSFR_NOTICE_SEVERITY)}
98+
title={
99+
<span
100+
dangerouslySetInnerHTML={{
101+
__html: kcContext.properties.DSFR_NOTICE_TITLE
102+
}}
103+
/>
104+
}
105+
description={
106+
<span
107+
dangerouslySetInnerHTML={{
108+
__html: kcContext.properties.DSFR_NOTICE_DESCRIPTION
109+
}}
110+
/>
111+
}
112+
/>
113+
)}
93114
<div className={fr.cx("fr-container", "fr-container--fluid", "fr-my-md-14v")}>
94115
<div className={fr.cx("fr-grid-row", "fr-grid-row--gutters", "fr-grid-row--center")}>
95116
<div className={fr.cx("fr-col-12", "fr-col-md-8", "fr-col-lg-6")}>

src/shared/noticeSeverity.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const allowedNoticeSeverities = ["info", "warning", "alert"] as const;
2+
export type NoticeSeverity = typeof allowedNoticeSeverities[number];
3+
4+
export function isNoticeSeverity(value: unknown): value is NoticeSeverity {
5+
return (allowedNoticeSeverities as readonly string[]).includes(value as string);
6+
}
7+
8+
export function getNoticeSeverityOrDefault(value: unknown, fallback: NoticeSeverity = "info"): NoticeSeverity {
9+
return isNoticeSeverity(value) ? value : fallback;
10+
}
11+
12+

vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default defineConfig({
1313
{ name: "DSFR_THEME_HOME_URL", default: "" },
1414
{ name: "DSFR_THEME_SERVICE_TITLE", default: "" },
1515
{ name: "DSFR_THEME_BRAND_TOP", default: "République<br/>Française" },
16+
{ name: "DSFR_NOTICE_TITLE", default: "" },
17+
{ name: "DSFR_NOTICE_DESCRIPTION", default: "" },
18+
{ name: "DSFR_NOTICE_SEVERITY", default: "info" },
1619
]
1720
})
1821
]

0 commit comments

Comments
 (0)