|
| 1 | +import * as React from "react"; |
| 2 | +import { ConsentBanner, ConsentBannerProps, consentModalButtonProps } from "../dist/ConsentBanner"; |
| 3 | +import { sectionName } from "./sectionName"; |
| 4 | +import { getStoryFactory } from "./getStory"; |
| 5 | +import { symToStr } from "tsafe/symToStr"; |
| 6 | +import { ConsentBannerContent } from "../dist/ConsentBanner/ConsentBannerContent"; |
| 7 | + |
| 8 | +const { meta, getStory } = getStoryFactory({ |
| 9 | + sectionName, |
| 10 | + "wrappedComponent": { |
| 11 | + [symToStr({ ConsentBanner })]: Story |
| 12 | + }, |
| 13 | + "description": ` |
| 14 | +Manage cookies and consent with a banner and a dedicated modal. |
| 15 | +
|
| 16 | +- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/gestionnaire-de-consentement), |
| 17 | +- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/ConsentBanner/index.tsx) |
| 18 | +
|
| 19 | +Optionally, you can also use \`import { useGdprStore } from "@codegouvfr/react-dsfr/gdpr"\` to manually monitor and controls |
| 20 | +the consent state. |
| 21 | +
|
| 22 | +## Usage example |
| 23 | +
|
| 24 | +\`\`\`tsx |
| 25 | +import { Footer } from "@codegouvfr/react-dsfr/Footer"; |
| 26 | +import { ConsentBanner, consentModalButtonProps } from "@codegouvfr/react-dsfr/ConsentBanner"; |
| 27 | +
|
| 28 | +function App(){ |
| 29 | +
|
| 30 | + return ( |
| 31 | + <> |
| 32 | + {/* must be on root level */} |
| 33 | + <ConsentBanner |
| 34 | + gdprPageLink="#" |
| 35 | + services={[ |
| 36 | + { |
| 37 | + name: "mandatory-cookie-consumer", |
| 38 | + title: "Any service consuming 🍪", |
| 39 | + description: "As a mandatory service, user cannot disable it.", |
| 40 | + mandatory: true |
| 41 | + }, |
| 42 | + { |
| 43 | + name: "cookie-consumer", |
| 44 | + title: "Any service consuming 🍪", |
| 45 | + description: "Here you can describe why this service use cookies." |
| 46 | + } |
| 47 | + ]} |
| 48 | + siteName={siteName} |
| 49 | + /> |
| 50 | + {/* ... Header ...*/} |
| 51 | + {/* ... your app ...*/} |
| 52 | + <Footer |
| 53 | + // other Footer props... |
| 54 | + cookiesManagementButtonProps={consentModalButtonProps} |
| 55 | + /> |
| 56 | + <> |
| 57 | + ); |
| 58 | +
|
| 59 | +} |
| 60 | +\`\`\` |
| 61 | +`, |
| 62 | + argTypes: { |
| 63 | + gdprPageLink: { |
| 64 | + description: "Usually the same as FooterProps.personalDataLinkProps" |
| 65 | + }, |
| 66 | + siteName: { |
| 67 | + description: "Current website name" |
| 68 | + } |
| 69 | + }, |
| 70 | + "disabledProps": ["containerWidth"] |
| 71 | +}); |
| 72 | + |
| 73 | +export default meta; |
| 74 | + |
| 75 | +const siteName = "Nom de l’entité (ministère, secrétariat d‘état, gouvernement)"; |
| 76 | + |
| 77 | +function Story(props: ConsentBannerProps) { |
| 78 | + return ( |
| 79 | + <> |
| 80 | + <ConsentBanner {...props} /> |
| 81 | + <style>{` |
| 82 | + .fr-consent-banner { |
| 83 | + position: static; |
| 84 | + } |
| 85 | + `}</style> |
| 86 | + <ConsentBannerContent {...props} consentModalButtonProps={consentModalButtonProps} /> |
| 87 | + </> |
| 88 | + ); |
| 89 | +} |
| 90 | + |
| 91 | +export const Default = getStory({ |
| 92 | + gdprPageLink: "#", |
| 93 | + services: [ |
| 94 | + { |
| 95 | + name: "mandatory-cookie-consumer", |
| 96 | + title: "Any service consuming 🍪", |
| 97 | + description: "As a mandatory service, user cannot disable it.", |
| 98 | + mandatory: true |
| 99 | + }, |
| 100 | + { |
| 101 | + name: "cookie-consumer", |
| 102 | + title: "Any service consuming 🍪", |
| 103 | + description: "Here you can describe why this service use cookies." |
| 104 | + } |
| 105 | + ], |
| 106 | + siteName |
| 107 | +}); |
0 commit comments