snapshot of https://github.com/shadcn-ui/ui.git (main, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
32
apps/v4/app/(app)/(create)/lib/merge-theme.ts
Normal file
32
apps/v4/app/(app)/(create)/lib/merge-theme.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { registryItemSchema, type RegistryItem } from "shadcn/schema"
|
||||
|
||||
import { BASE_COLORS, THEMES } from "@/registry/config"
|
||||
|
||||
export function buildTheme(baseColorName: string, themeName: string) {
|
||||
const baseColor = BASE_COLORS.find((c) => c.name === baseColorName)
|
||||
const theme = THEMES.find((t) => t.name === themeName)
|
||||
|
||||
if (!baseColor || !theme) {
|
||||
throw new Error(
|
||||
`Base color "${baseColorName}" or theme "${themeName}" not found`
|
||||
)
|
||||
}
|
||||
|
||||
const mergedTheme: RegistryItem = {
|
||||
name: `${baseColor.name}-${theme.name}`,
|
||||
title: `${baseColor.title} ${theme.title}`,
|
||||
type: "registry:theme",
|
||||
cssVars: {
|
||||
light: {
|
||||
...baseColor.cssVars?.light,
|
||||
...theme.cssVars?.light,
|
||||
},
|
||||
dark: {
|
||||
...baseColor.cssVars?.dark,
|
||||
...theme.cssVars?.dark,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return registryItemSchema.parse(mergedTheme)
|
||||
}
|
||||
Reference in New Issue
Block a user