Skip to content

Commit

Permalink
feat(color-mode): add support for nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
dodas committed Feb 8, 2021
1 parent b77049f commit 7f3bb35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/hungry-coins-hang.md
@@ -0,0 +1,6 @@
---
"@chakra-ui/color-mode": minor
---

You can now customize the `nonce` of the `<script>` that `ColorModeScript`
creates by passing `nonce` prop.
5 changes: 4 additions & 1 deletion packages/color-mode/src/color-mode-script.tsx
Expand Up @@ -35,6 +35,7 @@ function setScript(initialValue: Mode) {

interface ColorModeScriptProps {
initialColorMode?: Mode
nonce?: string
}

/**
Expand All @@ -44,5 +45,7 @@ interface ColorModeScriptProps {
export const ColorModeScript = (props: ColorModeScriptProps) => {
const { initialColorMode = "light" } = props
const html = `(${String(setScript)})('${initialColorMode}')`
return <script dangerouslySetInnerHTML={{ __html: html }} />
return (
<script nonce={props.nonce} dangerouslySetInnerHTML={{ __html: html }} />
)
}

0 comments on commit 7f3bb35

Please sign in to comment.