Skip to content

Commit 9c572ab

Browse files
committed
fix: chartColor in presets
1 parent 91403ee commit 9c572ab

6 files changed

Lines changed: 56 additions & 2 deletions

File tree

.changeset/cold-kids-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": patch
3+
---
4+
5+
fix chartColor in presets

apps/v4/app/(create)/init/parse-config.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import { describe, expect, it } from "vitest"
33
import { parseDesignSystemConfig } from "./parse-config"
44

55
describe("parseDesignSystemConfig", () => {
6+
it("defaults missing chartColor from the selected theme", () => {
7+
const result = parseDesignSystemConfig(
8+
new URLSearchParams(
9+
"base=base&style=sera&baseColor=taupe&theme=taupe&iconLibrary=lucide&font=noto-sans&rtl=false&menuAccent=subtle&menuColor=default&radius=default&fontHeading=playfair-display&template=vite&track=1"
10+
)
11+
)
12+
13+
expect(result.success).toBe(true)
14+
if (!result.success) {
15+
throw new Error(result.error)
16+
}
17+
18+
expect(result.data.chartColor).toBe("taupe")
19+
})
20+
621
it("honors explicit fontHeading and chartColor overrides when a preset is present", () => {
722
const result = parseDesignSystemConfig(
823
new URLSearchParams(

apps/v4/registry/config.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ describe("buildRegistryBase", () => {
6565
expect(result.chartColor).toBe("neutral")
6666
})
6767

68+
it("defaults chartColor to the selected theme when omitted", () => {
69+
const result = designSystemConfigSchema.parse({
70+
base: "base",
71+
style: "sera",
72+
iconLibrary: "lucide",
73+
baseColor: "taupe",
74+
theme: "taupe",
75+
font: "noto-sans",
76+
fontHeading: "playfair-display",
77+
menuAccent: "subtle",
78+
menuColor: "default",
79+
radius: "default",
80+
})
81+
82+
expect(result.chartColor).toBe("taupe")
83+
})
84+
6885
it("rejects chartColor values that are unavailable for the selected base color", () => {
6986
const result = designSystemConfigSchema.safeParse({
7087
base: "radix",

apps/v4/registry/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const designSystemConfigSchema = z
9898
theme: z.enum(THEMES.map((t) => t.name) as [ThemeName, ...ThemeName[]]),
9999
chartColor: z
100100
.enum(THEMES.map((t) => t.name) as [ChartColorName, ...ChartColorName[]])
101-
.default("neutral"),
101+
.optional(),
102102
font: z.enum(fontValues).default("inter"),
103103
fontHeading: z.enum(fontHeadingValues).default("inherit"),
104104
item: z.string().optional(),
@@ -136,6 +136,10 @@ export const designSystemConfigSchema = z
136136
.default("next")
137137
.optional(),
138138
})
139+
.transform((data) => ({
140+
...data,
141+
chartColor: data.chartColor ?? data.theme,
142+
}))
139143
.refine(
140144
(data) => {
141145
const availableThemes = getThemesForBaseColor(data.baseColor)

packages/shadcn/src/preset/presets.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { REGISTRY_URL } from "@/src/registry/constants"
22
import { describe, expect, it } from "vitest"
33

4-
import { resolveCreateUrl, resolveInitUrl } from "./presets"
4+
import { DEFAULT_PRESETS, resolveCreateUrl, resolveInitUrl } from "./presets"
55

66
const SHADCN_URL = REGISTRY_URL.replace(/\/r\/?$/, "")
77

@@ -79,6 +79,12 @@ describe("buildInitUrl", () => {
7979
expect(parsed.searchParams.get("chartColor")).toBe("emerald")
8080
})
8181

82+
it("should include chartColor from default presets", () => {
83+
const url = resolveInitUrl({ ...DEFAULT_PRESETS.sera, base: "base" })
84+
const parsed = new URL(url)
85+
expect(parsed.searchParams.get("chartColor")).toBe("taupe")
86+
})
87+
8288
it("should not include chartColor when not provided", () => {
8389
const url = resolveInitUrl(mockPreset)
8490
const parsed = new URL(url)

packages/shadcn/src/preset/presets.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const DEFAULT_PRESETS = {
1919
style: "nova",
2020
baseColor: "neutral",
2121
theme: "neutral",
22+
chartColor: "neutral",
2223
iconLibrary: "lucide",
2324
font: "geist",
2425
fontHeading: "inherit",
@@ -34,6 +35,7 @@ export const DEFAULT_PRESETS = {
3435
style: "vega",
3536
baseColor: "neutral",
3637
theme: "neutral",
38+
chartColor: "neutral",
3739
iconLibrary: "lucide",
3840
font: "inter",
3941
fontHeading: "inherit",
@@ -49,6 +51,7 @@ export const DEFAULT_PRESETS = {
4951
style: "maia",
5052
baseColor: "neutral",
5153
theme: "neutral",
54+
chartColor: "neutral",
5255
iconLibrary: "hugeicons",
5356
font: "figtree",
5457
fontHeading: "inherit",
@@ -64,6 +67,7 @@ export const DEFAULT_PRESETS = {
6467
style: "lyra",
6568
baseColor: "neutral",
6669
theme: "neutral",
70+
chartColor: "neutral",
6771
iconLibrary: "phosphor",
6872
font: "jetbrains-mono",
6973
fontHeading: "inherit",
@@ -79,6 +83,7 @@ export const DEFAULT_PRESETS = {
7983
style: "mira",
8084
baseColor: "neutral",
8185
theme: "neutral",
86+
chartColor: "neutral",
8287
iconLibrary: "hugeicons",
8388
font: "inter",
8489
fontHeading: "inherit",
@@ -94,6 +99,7 @@ export const DEFAULT_PRESETS = {
9499
style: "luma",
95100
baseColor: "neutral",
96101
theme: "neutral",
102+
chartColor: "neutral",
97103
iconLibrary: "lucide",
98104
font: "inter",
99105
fontHeading: "inherit",
@@ -109,6 +115,7 @@ export const DEFAULT_PRESETS = {
109115
style: "sera",
110116
baseColor: "taupe",
111117
theme: "taupe",
118+
chartColor: "taupe",
112119
iconLibrary: "lucide",
113120
font: "noto-sans",
114121
fontHeading: "playfair-display",

0 commit comments

Comments
 (0)