diff --git a/README.md b/README.md index 90d23f2b7..7f19657c5 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,8 @@ A few projects that use `@codegouvfr/react-dsfr`. - https://code.gouv.fr/sill - https://immersion-facile.beta.gouv.fr/ +- https://egapro.travail.gouv.fr/ +- https://maisondelautisme.gouv.fr/ - https://refugies.info/fr - https://www.mediateur-public.fr/ - https://signal.conso.gouv.fr/ diff --git a/package.json b/package.json index 7a30dd92a..031dc9f2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codegouvfr/react-dsfr", - "version": "0.76.4", + "version": "0.77.0-rc.1", "description": "French State Design System React integration library", "repository": { "type": "git", @@ -97,7 +97,7 @@ "husky": "^4.3.8", "lint-staged": "^11.0.0", "memoizee": "^0.4.15", - "next": "13.4.4", + "next": "13.5.1", "oppa": "^0.4.0", "parse-numeric-range": "^1.3.0", "powerhooks": "^0.22.0", @@ -107,7 +107,7 @@ "remixicon": "^3.2.0", "storybook-dark-mode": "^1.1.2", "ts-node": "^10.9.1", - "tss-react": "^4.9.0", + "tss-react": "^4.9.1", "type-route": "^1.0.1", "typescript": "^4.9.1", "vitest": "^0.24.3" diff --git a/src/next-appdir/DsfrHead.tsx b/src/next-appdir/DsfrHead.tsx index 293663d1d..bed5e6467 100644 --- a/src/next-appdir/DsfrHead.tsx +++ b/src/next-appdir/DsfrHead.tsx @@ -8,10 +8,13 @@ import { getScriptToRunAsap } from "../useIsDark/scriptToRunAsap"; import { fontUrlByFileBasename } from "./zz_internal/fontUrlByFileBasename"; import { getDefaultColorSchemeServerSide } from "./zz_internal/defaultColorScheme"; import { setLink, type RegisteredLinkProps } from "../link"; +import { assert } from "tsafe/assert"; //NOTE: As of now there is no way to enforce ordering in Next Appdir //See: https://github.com/vercel/next.js/issues/16630 // @import url(...) doesn't work. Using Sass and @use is our last resort. import "../assets/dsfr_plus_icons.scss"; +// eslint-disable-next-line @typescript-eslint/no-unused-vars -- used in doc +import { type startReactDsfr } from "./zz_internal/start"; export type DsfrHeadProps = { /** If not provided no fonts are preloaded. @@ -20,12 +23,32 @@ export type DsfrHeadProps = { preloadFonts?: (keyof typeof fontUrlByFileBasename)[]; /** Default: */ Link?: (props: RegisteredLinkProps & { children: ReactNode }) => ReturnType; + /** + * When set, the value will be used as the nonce attribute of subsequent script tags. + * + * Don't forget to add `doCheckNonce: true` in {@link startReactDsfr} options. + * + * @see https://developer.mozilla.org/fr/docs/Web/HTML/Global_attributes/nonce + */ + nonce?: string; + /** + * Enable Trusted Types with a custom policy name. + * + * Don't forget to add `trustedTypesPolicyName` in {@link startReactDsfr} options. + * + * @see https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types + * @see {@link DEFAULT_TRUSTED_TYPES_POLICY_NAME} + * @default "react-dsfr" + */ + trustedTypesPolicyName?: string; }; const isProduction = process.env.NODE_ENV !== "development"; export function DsfrHead(props: DsfrHeadProps) { - const { preloadFonts = [], Link } = props; + const { preloadFonts = [], Link, nonce, trustedTypesPolicyName = "react-dsfr" } = props; + + assert(nonce !== "", "nonce cannot be an empty string"); const defaultColorScheme = getDefaultColorSchemeServerSide(); @@ -53,9 +76,25 @@ export function DsfrHead(props: DsfrHeadProps) { - {isProduction && ( +