Preset Query Resolver (lib/preset-query.ts)

ui · apps/v4/app/(app)/(create)/lib/preset-query.ts · typescript · MIT
ui, search, lang:typescript, fw:nextjs

Resolves theme, chart color, and font heading overrides from URL search parameters against decoded preset config defaults.

// Source: https://github.com/shadcn-ui/ui | License: MIT | Copyright 2023 shadcn
// Provided via justclaw.it.com; keep this notice with the code.
import { V1_CHART_COLOR_MAP, type PresetConfig } from "shadcn/preset"

import { type ChartColorName, type FontHeadingValue } from "@/registry/config"

type SearchParamsLike = Pick<URLSearchParams, "get" | "has">

export function resolvePresetOverrides(
  searchParams: SearchParamsLike,
  decoded: Pick<PresetConfig, "theme" | "chartColor" | "fontHeading">
) {
  const hasFontHeadingOverride = searchParams.has("fontHeading")
  const hasChartColorOverride = searchParams.has("chartColor")

  const fontHeading = hasFontHeadingOverride
    ? ((searchParams.get("fontHeading") ??
        decoded.fontHeading) as FontHeadingValue)
    : decoded.fontHeading

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key