Skip to content

Commit 3db8a07

Browse files
authored
feat(shadcn): default to cssVariables: true. add --no-css-variables option (#6707)
* feat(shadcn): default to css vars * chore: changeset * fix(shadcn): add command
1 parent 1879594 commit 3db8a07

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

.changeset/great-olives-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": minor
3+
---
4+
5+
default to css vars. add --no-css-variables

packages/shadcn/src/commands/add.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const addOptionsSchema = z.object({
3838
path: z.string().optional(),
3939
silent: z.boolean(),
4040
srcDir: z.boolean().optional(),
41+
cssVariables: z.boolean(),
4142
})
4243

4344
export const add = new Command()
@@ -62,6 +63,12 @@ export const add = new Command()
6263
"use the src directory when creating a new project.",
6364
false
6465
)
66+
.option(
67+
"--no-src-dir",
68+
"do not use the src directory when creating a new project."
69+
)
70+
.option("--css-variables", "use css variables for theming.", true)
71+
.option("--no-css-variables", "do not use css variables for theming.")
6572
.action(async (components, opts) => {
6673
try {
6774
const options = addOptionsSchema.parse({
@@ -136,6 +143,7 @@ export const add = new Command()
136143
silent: true,
137144
isNewProject: false,
138145
srcDir: options.srcDir,
146+
cssVariables: options.cssVariables,
139147
})
140148
}
141149

@@ -166,6 +174,7 @@ export const add = new Command()
166174
silent: true,
167175
isNewProject: true,
168176
srcDir: options.srcDir,
177+
cssVariables: options.cssVariables,
169178
})
170179

171180
shouldUpdateAppIndex =

packages/shadcn/src/commands/init.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const initOptionsSchema = z.object({
3838
silent: z.boolean(),
3939
isNewProject: z.boolean(),
4040
srcDir: z.boolean().optional(),
41+
cssVariables: z.boolean(),
4142
})
4243

4344
export const init = new Command()
@@ -61,6 +62,12 @@ export const init = new Command()
6162
"use the src directory when creating a new project.",
6263
false
6364
)
65+
.option(
66+
"--no-src-dir",
67+
"do not use the src directory when creating a new project."
68+
)
69+
.option("--css-variables", "use css variables for theming.", true)
70+
.option("--no-css-variables", "do not use css variables for theming.")
6471
.action(async (components, opts) => {
6572
try {
6673
const options = initOptionsSchema.parse({
@@ -318,21 +325,11 @@ async function promptForMinimalConfig(
318325
value: color.name,
319326
})),
320327
},
321-
{
322-
type: "toggle",
323-
name: "tailwindCssVariables",
324-
message: `Would you like to use ${highlighter.info(
325-
"CSS variables"
326-
)} for theming?`,
327-
initial: defaultConfig?.tailwind.cssVariables,
328-
active: "yes",
329-
inactive: "no",
330-
},
331328
])
332329

333330
style = options.style ?? "new-york"
334331
baseColor = options.tailwindBaseColor
335-
cssVariables = options.tailwindCssVariables
332+
cssVariables = opts.cssVariables
336333
}
337334

338335
return rawConfigSchema.parse({

0 commit comments

Comments
 (0)