Skip to content

Commit

Permalink
feat(shadcn): default to cssVariables: true. add --no-css-variables o…
Browse files Browse the repository at this point in the history
…ption (#6707)

* feat(shadcn): default to css vars

* chore: changeset

* fix(shadcn): add command
  • Loading branch information
shadcn authored Feb 21, 2025
1 parent 1879594 commit 3db8a07
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-olives-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn": minor
---

default to css vars. add --no-css-variables
9 changes: 9 additions & 0 deletions packages/shadcn/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const addOptionsSchema = z.object({
path: z.string().optional(),
silent: z.boolean(),
srcDir: z.boolean().optional(),
cssVariables: z.boolean(),
})

export const add = new Command()
Expand All @@ -62,6 +63,12 @@ export const add = new Command()
"use the src directory when creating a new project.",
false
)
.option(
"--no-src-dir",
"do not use the src directory when creating a new project."
)
.option("--css-variables", "use css variables for theming.", true)
.option("--no-css-variables", "do not use css variables for theming.")
.action(async (components, opts) => {
try {
const options = addOptionsSchema.parse({
Expand Down Expand Up @@ -136,6 +143,7 @@ export const add = new Command()
silent: true,
isNewProject: false,
srcDir: options.srcDir,
cssVariables: options.cssVariables,
})
}

Expand Down Expand Up @@ -166,6 +174,7 @@ export const add = new Command()
silent: true,
isNewProject: true,
srcDir: options.srcDir,
cssVariables: options.cssVariables,
})

shouldUpdateAppIndex =
Expand Down
19 changes: 8 additions & 11 deletions packages/shadcn/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const initOptionsSchema = z.object({
silent: z.boolean(),
isNewProject: z.boolean(),
srcDir: z.boolean().optional(),
cssVariables: z.boolean(),
})

export const init = new Command()
Expand All @@ -61,6 +62,12 @@ export const init = new Command()
"use the src directory when creating a new project.",
false
)
.option(
"--no-src-dir",
"do not use the src directory when creating a new project."
)
.option("--css-variables", "use css variables for theming.", true)
.option("--no-css-variables", "do not use css variables for theming.")
.action(async (components, opts) => {
try {
const options = initOptionsSchema.parse({
Expand Down Expand Up @@ -318,21 +325,11 @@ async function promptForMinimalConfig(
value: color.name,
})),
},
{
type: "toggle",
name: "tailwindCssVariables",
message: `Would you like to use ${highlighter.info(
"CSS variables"
)} for theming?`,
initial: defaultConfig?.tailwind.cssVariables,
active: "yes",
inactive: "no",
},
])

style = options.style ?? "new-york"
baseColor = options.tailwindBaseColor
cssVariables = options.tailwindCssVariables
cssVariables = opts.cssVariables
}

return rawConfigSchema.parse({
Expand Down

0 comments on commit 3db8a07

Please sign in to comment.