Home / Function/ DesignSystemProvider() — ui Function Reference

DesignSystemProvider() — ui Function Reference

Architecture documentation for the DesignSystemProvider() function in design-system-provider.tsx from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  3713478a_c793_9938_bcce_774f042097da["DesignSystemProvider()"]
  8cd76466_2b61_eda9_5470_c5e644ff3e2f["design-system-provider.tsx"]
  3713478a_c793_9938_bcce_774f042097da -->|defined in| 8cd76466_2b61_eda9_5470_c5e644ff3e2f
  style 3713478a_c793_9938_bcce_774f042097da fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/v4/app/(create)/components/design-system-provider.tsx lines 14–174

export function DesignSystemProvider({
  children,
}: {
  children: React.ReactNode
}) {
  const [
    { style, theme, font, baseColor, menuAccent, menuColor, radius },
    setSearchParams,
  ] = useDesignSystemSearchParams({
    shallow: true, // No need to go through the server…
    history: "replace", // …or push updates into the iframe history.
  })
  useIframeMessageListener("design-system-params", setSearchParams)
  const [isReady, setIsReady] = React.useState(false)

  // Use useLayoutEffect for synchronous style updates to prevent flash.
  React.useLayoutEffect(() => {
    if (!style || !theme || !font || !baseColor) {
      return
    }

    const body = document.body

    // Update style class in place (remove old, add new).
    body.classList.forEach((className) => {
      if (className.startsWith("style-")) {
        body.classList.remove(className)
      }
    })
    body.classList.add(`style-${style}`)

    // Update base color class in place.
    body.classList.forEach((className) => {
      if (className.startsWith("base-color-")) {
        body.classList.remove(className)
      }
    })
    body.classList.add(`base-color-${baseColor}`)

    // Update font.
    const selectedFont = FONTS.find((f) => f.value === font)
    if (selectedFont) {
      const fontFamily = selectedFont.font.style.fontFamily
      document.documentElement.style.setProperty("--font-sans", fontFamily)
    }

    setIsReady(true)
  }, [style, theme, font, baseColor])

  const registryTheme = React.useMemo(() => {
    if (!baseColor || !theme || !menuAccent || !radius) {
      return null
    }

    const config: DesignSystemConfig = {
      ...DEFAULT_CONFIG,
      baseColor,
      theme,
      menuAccent,
      radius,
    }

    return buildRegistryTheme(config)
  }, [baseColor, theme, menuAccent, radius])

  // Use useLayoutEffect for synchronous CSS var updates.
  React.useLayoutEffect(() => {
    if (!registryTheme || !registryTheme.cssVars) {
      return
    }

    const styleId = "design-system-theme-vars"
    let styleElement = document.getElementById(
      styleId
    ) as HTMLStyleElement | null

    if (!styleElement) {
      styleElement = document.createElement("style")
      styleElement.id = styleId
      document.head.appendChild(styleElement)
    }

Domain

Subdomains

Frequently Asked Questions

What does DesignSystemProvider() do?
DesignSystemProvider() is a function in the ui codebase, defined in apps/v4/app/(create)/components/design-system-provider.tsx.
Where is DesignSystemProvider() defined?
DesignSystemProvider() is defined in apps/v4/app/(create)/components/design-system-provider.tsx at line 14.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free