From edcdc798e1d4c239f61e1a6ceaca7f5c88571953 Mon Sep 17 00:00:00 2001 From: Enguerran Weiss Date: Thu, 24 Jul 2025 10:01:48 +0200 Subject: [PATCH] handle subFinality description in typing and DOM --- .../ConsentBannerAndConsentManagement.tsx | 12 ++++- .../ConsentManagement.tsx | 49 ++++++++++++------- .../createConsentManagement.ts | 14 ++++-- src/consentManagement/types.ts | 12 +++-- stories/ConsentManagement.stories.tsx | 12 ++++- 5 files changed, 72 insertions(+), 27 deletions(-) diff --git a/src/consentManagement/ConsentBannerAndConsentManagement/ConsentBannerAndConsentManagement.tsx b/src/consentManagement/ConsentBannerAndConsentManagement/ConsentBannerAndConsentManagement.tsx index c0b0e5a79..2f15a32bc 100644 --- a/src/consentManagement/ConsentBannerAndConsentManagement/ConsentBannerAndConsentManagement.tsx +++ b/src/consentManagement/ConsentBannerAndConsentManagement/ConsentBannerAndConsentManagement.tsx @@ -1,6 +1,10 @@ import React, { useReducer, useEffect, type ReactNode } from "react"; import type { RegisteredLinkProps } from "../../link"; -import type { ExtractFinalityFromFinalityDescription, FinalityConsent } from "../types"; +import type { + ExtractFinalityFromFinalityDescription, + FinalityConsent, + SubFinalityContent +} from "../types"; import type { ProcessConsentChanges } from "../processConsentChanges"; import { FooterBottomItem } from "../../Footer"; import { createConsentBanner } from "./ConsentBanner"; @@ -10,7 +14,11 @@ import { useTranslation } from "./translation"; export function createConsentBannerAndConsentManagement< FinalityDescription extends Record< string, - { title: ReactNode; description?: ReactNode; subFinalities?: Record } + { + title: ReactNode; + description?: ReactNode; + subFinalities?: Record; + } > >(params: { finalityDescription: ((params: { lang: string }) => FinalityDescription) | FinalityDescription; diff --git a/src/consentManagement/ConsentBannerAndConsentManagement/ConsentManagement.tsx b/src/consentManagement/ConsentBannerAndConsentManagement/ConsentManagement.tsx index 16b7351a6..d03e2989f 100644 --- a/src/consentManagement/ConsentBannerAndConsentManagement/ConsentManagement.tsx +++ b/src/consentManagement/ConsentBannerAndConsentManagement/ConsentManagement.tsx @@ -2,7 +2,11 @@ import React, { useEffect, useMemo, useState, useId, type ReactNode } from "reac import { fr } from "../../fr"; import type { RegisteredLinkProps } from "../../link"; import { createModal } from "../../Modal"; -import type { ExtractFinalityFromFinalityDescription, FinalityConsent } from "../types"; +import type { + ExtractFinalityFromFinalityDescription, + FinalityConsent, + SubFinalityContent +} from "../types"; import type { ProcessConsentChanges } from "../processConsentChanges"; import { useLang } from "../../i18n"; import { useIsModalOpen } from "../../Modal/useIsModalOpen"; @@ -20,7 +24,11 @@ import { useConst } from "../../tools/powerhooks/useConst"; export function createConsentManagement< FinalityDescription extends Record< string, - { title: ReactNode; description?: ReactNode; subFinalities?: Record } + { + title: ReactNode; + description?: ReactNode; + subFinalities?: Record; + } > >(params: { personalDataPolicyLinkProps: RegisteredLinkProps | undefined; @@ -238,7 +246,7 @@ export function createConsentManagement< function ConsentService(props: { title: ReactNode; description: ReactNode | undefined; - subFinalities: Record | undefined; + subFinalities: Record | undefined; finalityConsent: | boolean | ({ @@ -378,19 +386,22 @@ export function createConsentManagement< className={fr.cx("fr-consent-services", "fr-collapse")} id={subFinalityDivId} > - {Object.entries(subFinalities).map(([subFinality, title]) => ( - - onChange({ - subFinality, - isConsentGiven - }) - } - /> - ))} + {Object.entries(subFinalities).map( + ([subFinality, { title, description }]) => ( + + onChange({ + subFinality, + isConsentGiven + }) + } + /> + ) + )} ))} @@ -401,10 +412,11 @@ export function createConsentManagement< function SubConsentService(props: { title: ReactNode; + description?: ReactNode; onChange: (params: { isConsentGiven: boolean }) => void; isConsentGiven: boolean; }) { - const { title, onChange, isConsentGiven } = props; + const { title, description, onChange, isConsentGiven } = props; const { t } = useTranslation(); @@ -421,6 +433,9 @@ export function createConsentManagement<
{title} + {description !== undefined && ( +

{description}

+ )}