Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayPawarExist authored Feb 5, 2025
2 parents b4b7d93 + 1e357cb commit 12ba3c6
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-cheetahs-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn": minor
---

default for new-york for v4
18 changes: 12 additions & 6 deletions packages/shadcn/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
resolveConfigPaths,
type Config,
} from "@/src/utils/get-config"
import { getProjectConfig, getProjectInfo } from "@/src/utils/get-project-info"
import {
getProjectConfig,
getProjectInfo,
getProjectTailwindVersionFromConfig,
} from "@/src/utils/get-project-info"
import { handleError } from "@/src/utils/handle-error"
import { highlighter } from "@/src/utils/highlighter"
import { logger } from "@/src/utils/logger"
Expand Down Expand Up @@ -285,21 +289,23 @@ async function promptForMinimalConfig(
let cssVariables = defaultConfig.tailwind.cssVariables

if (!opts.defaults) {
const [styles, baseColors] = await Promise.all([
const [styles, baseColors, tailwindVersion] = await Promise.all([
getRegistryStyles(),
getRegistryBaseColors(),
getProjectTailwindVersionFromConfig(defaultConfig),
])

const options = await prompts([
{
type: "select",
type: tailwindVersion === "v4" ? null : "select",
name: "style",
message: `Which ${highlighter.info("style")} would you like to use?`,
choices: styles.map((style) => ({
title: style.label,
title:
style.name === "new-york" ? "New York (Recommended)" : style.label,
value: style.name,
})),
initial: styles.findIndex((s) => s.name === style),
initial: 0,
},
{
type: "select",
Expand All @@ -324,7 +330,7 @@ async function promptForMinimalConfig(
},
])

style = options.style
style = options.style ?? "new-york"
baseColor = options.tailwindBaseColor
cssVariables = options.tailwindCssVariables
}
Expand Down
15 changes: 13 additions & 2 deletions packages/shadcn/src/registry/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import path from "path"
import { Config, getTargetStyleFromConfig } from "@/src/utils/get-config"
import { getProjectInfo } from "@/src/utils/get-project-info"
import {
getProjectInfo,
getProjectTailwindVersionFromConfig,
} from "@/src/utils/get-project-info"
import { handleError } from "@/src/utils/handle-error"
import { highlighter } from "@/src/utils/highlighter"
import { logger } from "@/src/utils/logger"
Expand Down Expand Up @@ -350,7 +353,10 @@ async function resolveRegistryDependencies(
}

export async function registryGetTheme(name: string, config: Config) {
const baseColor = await getRegistryBaseColor(name)
const [baseColor, tailwindVersion] = await Promise.all([
getRegistryBaseColor(name),
getProjectTailwindVersionFromConfig(config),
])
if (!baseColor) {
return null
}
Expand Down Expand Up @@ -398,6 +404,11 @@ export async function registryGetTheme(name: string, config: Config) {
}
}

// Update theme to be v4 compatible.
if (tailwindVersion === "v4") {
theme.cssVars.light.radius = "0.6rem"
}

return theme
}

Expand Down
2 changes: 1 addition & 1 deletion packages/shadcn/src/utils/get-project-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export async function getProjectConfig(
export async function getProjectTailwindVersionFromConfig(
config: Config
): Promise<TailwindVersion> {
if (!config.resolvedPaths.cwd) {
if (!config.resolvedPaths?.cwd) {
return "v3"
}

Expand Down
8 changes: 5 additions & 3 deletions packages/shadcn/src/utils/updaters/update-css-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export async function transformCssVars(
from: undefined,
})

let output = result.css.replace(/\/\* ---break--- \*\//g, "")
let output = result.css

output = output.replace(/\/\* ---break--- \*\//g, "")

if (options.tailwindVersion === "v4") {
output = output.replace(/(\n\s*\n)+/g, "\n\n")
Expand All @@ -121,7 +123,7 @@ function updateBaseLayerPlugin() {
postcssPlugin: "update-base-layer",
Once(root: Root) {
const requiredRules = [
{ selector: "*", apply: "border-border" },
{ selector: "*", apply: "border-border outline-ring/50" },
{ selector: "body", apply: "bg-background text-foreground" },
]

Expand Down Expand Up @@ -359,7 +361,7 @@ function updateCssVarsPluginV4(
node.type === "rule" && node.selector === selector
)

if (!ruleNode) {
if (!ruleNode && Object.keys(vars).length > 0) {
ruleNode = postcss.rule({
selector,
nodes: [],
Expand Down
58 changes: 39 additions & 19 deletions packages/shadcn/test/utils/updaters/update-css-vars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("transformCssVars", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -110,7 +110,7 @@ describe("transformCssVars", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -176,6 +176,17 @@ describe("transformCssVars", () => {
@apply bg-background text-foreground;
}
}
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
"
`)
})
Expand Down Expand Up @@ -222,7 +233,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -282,7 +293,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -346,7 +357,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -413,7 +424,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -492,6 +503,15 @@ describe("transformCssVarsV4", () => {
@apply bg-background text-foreground;
}
}
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
"
`)
})
Expand Down Expand Up @@ -536,7 +556,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -586,7 +606,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -636,7 +656,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -684,7 +704,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -732,7 +752,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -777,7 +797,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -808,7 +828,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -846,7 +866,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -884,7 +904,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -949,7 +969,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -1024,7 +1044,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -1095,7 +1115,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down Expand Up @@ -1168,7 +1188,7 @@ describe("transformCssVarsV4", () => {
@layer base {
* {
@apply border-border;
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
Expand Down

0 comments on commit 12ba3c6

Please sign in to comment.