Skip to content

Commit

Permalink
(3/n) shadcn: tailwind config (#6490)
Browse files Browse the repository at this point in the history
* feat(shadcn): add tailwind version detection

* chore: changeset

* feat(shadcn): css vars for tailwind v4

* fix(shadcn): handle color space

* fix(shadcn): add oklch support

* feat(shadcn): handle single quote

* feat(shadcn): update tailwind config

* feat(shadcn): add keyframes

* feat(shadcn): add animation vars

* fix: var name

* fix(shadcn): handle color values

* feat(shadcn): handle radius

* feat(shadcn): clean up formatting

* feat(shadcn): update next clean up function

* chore: changeset

* feat(shadcn): fix formatting for v3 and v4

* test(shadcn): update snapshots

* fix(shadcn): update tailwind version handling
  • Loading branch information
shadcn authored Jan 30, 2025
1 parent 5ef2bc5 commit 9a14c1d
Show file tree
Hide file tree
Showing 5 changed files with 948 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-cherries-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn": minor
---

add support for tailwind v4
13 changes: 12 additions & 1 deletion packages/shadcn/src/preflights/preflight-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ export async function preFlightInit(
)}.`
)

const tailwindSpinner = spinner(`Validating Tailwind CSS.`, {
let tailwindSpinnerMessage = "Validating Tailwind CSS."

if (projectInfo.tailwindVersion === "v4") {
tailwindSpinnerMessage = `Validating Tailwind CSS config. Found ${highlighter.info(
"v4"
)}.`
}

const tailwindSpinner = spinner(tailwindSpinnerMessage, {
silent: options.silent,
}).start()
if (
Expand All @@ -93,6 +101,9 @@ export async function preFlightInit(
) {
errors[ERRORS.TAILWIND_NOT_CONFIGURED] = true
tailwindSpinner?.fail()
} else if (!projectInfo.tailwindVersion) {
errors[ERRORS.TAILWIND_NOT_CONFIGURED] = true
tailwindSpinner?.fail()
} else {
tailwindSpinner?.succeed()
}
Expand Down
2 changes: 2 additions & 0 deletions packages/shadcn/src/utils/add-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async function addProjectComponents(
cleanupDefaultNextStyles: options.isNewProject,
silent: options.silent,
tailwindVersion,
tailwindConfig: tree.tailwind?.config,
})

await updateDependencies(tree.dependencies, config, {
Expand Down Expand Up @@ -176,6 +177,7 @@ async function addWorkspaceComponents(
await updateCssVars(component.cssVars, targetConfig, {
silent: true,
tailwindVersion,
tailwindConfig: component.tailwind?.config,
})
filesUpdated.push(
path.relative(workspaceRoot, targetConfig.resolvedPaths.tailwindCss)
Expand Down
Loading

0 comments on commit 9a14c1d

Please sign in to comment.