Skip to content

← All components

Foundation and layout

ThemeScript

Applies the saved theme before first paint.

Live example

<ThemeScript />

Usage

Each example includes the complete adapter-specific parameter reference. Copy it as a starting point, then remove options your use case does not need.

React

tsx
import { ThemeScript } from "@cofob/design-system-react";

/**
 * Complete ThemeScript parameter reference.
 * @param storageKey
 *   type: string
 *   default: "cf-theme"
 *   example: "cf-theme"
 * @param nonce
 *   type: string
 *   default: —
 *   example: nonce
 */
export function ThemeScriptExample() {
  return (
    <ThemeScript nonce={nonce} />
  );
}

Svelte

svelte
<script lang="ts">
  import { ThemeScript } from "@cofob/design-system-svelte";

  // Complete ThemeScript parameter reference.
  // storageKey
  //   type: string
  //   default: "cf-theme"
  //   example: "cf-theme"
  // nonce
  //   type: string
  //   default: —
  //   example: nonce
</script>

<ThemeScript nonce={nonce} />

HTML

html
<!--
  Complete ThemeScript parameter reference.
  storageKey
    type: string
    default: "cf-theme"
    example: "cf-theme"
  nonce
    type: string
    default: —
    example: nonce
-->
<script>/* getThemeScript() */</script>

Parameters

Adapter differences are explicit. Native element attributes are forwarded in React and Svelte and can be written directly in HTML.

ParameterTypeDefaultAdaptersExampleDescription
storageKeystring"cf-theme"React · Svelte · HTML"cf-theme"Browser storage key shared by ThemeScript and ThemeProvider.
noncestringReact · Svelte · HTMLnonceCSP nonce forwarded to the inline before-paint script.