mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-16 12:21:35 +00:00
Compare commits
9 Commits
shadcn@2.5
...
v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0826d58d3a | ||
|
|
995b6fd1a8 | ||
|
|
410998525b | ||
|
|
0f18c2775a | ||
|
|
b84c990e42 | ||
|
|
2773f9e2e2 | ||
|
|
c41c6ece86 | ||
|
|
a6034127f9 | ||
|
|
eaf8156fc0 |
5
.changeset/honest-humans-invite.md
Normal file
5
.changeset/honest-humans-invite.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"shadcn": patch
|
||||
---
|
||||
|
||||
resolved prefixing issue for Tailwind CSS v4 compatibility
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
import * as React from "react"
|
||||
import {
|
||||
closestCenter,
|
||||
DndContext,
|
||||
KeyboardSensor,
|
||||
MouseSensor,
|
||||
TouchSensor,
|
||||
closestCenter,
|
||||
useSensor,
|
||||
useSensors,
|
||||
type DragEndEvent,
|
||||
@@ -14,8 +14,8 @@ import {
|
||||
} from "@dnd-kit/core"
|
||||
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||
import {
|
||||
SortableContext,
|
||||
arrayMove,
|
||||
SortableContext,
|
||||
useSortable,
|
||||
verticalListSortingStrategy,
|
||||
} from "@dnd-kit/sortable"
|
||||
@@ -37,9 +37,6 @@ import {
|
||||
import {
|
||||
ColumnDef,
|
||||
ColumnFiltersState,
|
||||
Row,
|
||||
SortingState,
|
||||
VisibilityState,
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
getFacetedRowModel,
|
||||
@@ -47,7 +44,10 @@ import {
|
||||
getFilteredRowModel,
|
||||
getPaginationRowModel,
|
||||
getSortedRowModel,
|
||||
Row,
|
||||
SortingState,
|
||||
useReactTable,
|
||||
VisibilityState,
|
||||
} from "@tanstack/react-table"
|
||||
import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"
|
||||
import { toast } from "sonner"
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Toaster } from "@/registry/new-york-v4/ui/sonner"
|
||||
import { siteConfig } from "@/www/config/site"
|
||||
|
||||
import "./globals.css"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { ActiveThemeProvider } from "@/components/active-theme"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"use client"
|
||||
|
||||
import {
|
||||
ReactNode,
|
||||
createContext,
|
||||
ReactNode,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
"type": "registry:style",
|
||||
"dependencies": [
|
||||
"class-variance-authority",
|
||||
"lucide-react",
|
||||
"lucide-react"
|
||||
],
|
||||
"devDependencies": [
|
||||
"tw-animate-css"
|
||||
],
|
||||
"registryDependencies": [
|
||||
@@ -2803,4 +2805,4 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
import * as React from "react"
|
||||
import {
|
||||
closestCenter,
|
||||
DndContext,
|
||||
KeyboardSensor,
|
||||
MouseSensor,
|
||||
TouchSensor,
|
||||
closestCenter,
|
||||
useSensor,
|
||||
useSensors,
|
||||
type DragEndEvent,
|
||||
@@ -14,8 +14,8 @@ import {
|
||||
} from "@dnd-kit/core"
|
||||
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||
import {
|
||||
SortableContext,
|
||||
arrayMove,
|
||||
SortableContext,
|
||||
useSortable,
|
||||
verticalListSortingStrategy,
|
||||
} from "@dnd-kit/sortable"
|
||||
@@ -37,9 +37,6 @@ import {
|
||||
import {
|
||||
ColumnDef,
|
||||
ColumnFiltersState,
|
||||
Row,
|
||||
SortingState,
|
||||
VisibilityState,
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
getFacetedRowModel,
|
||||
@@ -47,7 +44,10 @@ import {
|
||||
getFilteredRowModel,
|
||||
getPaginationRowModel,
|
||||
getSortedRowModel,
|
||||
Row,
|
||||
SortingState,
|
||||
useReactTable,
|
||||
VisibilityState,
|
||||
} from "@tanstack/react-table"
|
||||
import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"
|
||||
import { toast } from "sonner"
|
||||
|
||||
@@ -39,7 +39,7 @@ function ResizableHandle({
|
||||
<ResizablePrimitive.PanelResizeHandle
|
||||
data-slot="resizable-handle"
|
||||
className={cn(
|
||||
"bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",
|
||||
"bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:translate-x-0 data-[panel-group-direction=vertical]:after:-translate-y-1/2 [&[data-panel-group-direction=vertical]>div]:rotate-90",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { VariantProps, cva } from "class-variance-authority"
|
||||
import { cva, VariantProps } from "class-variance-authority"
|
||||
import { PanelLeftIcon } from "lucide-react"
|
||||
|
||||
import { useIsMobile } from "@/registry/new-york-v4/hooks/use-mobile"
|
||||
|
||||
@@ -20,11 +20,8 @@ const registry = {
|
||||
{
|
||||
name: "index",
|
||||
type: "registry:style",
|
||||
dependencies: [
|
||||
"class-variance-authority",
|
||||
"lucide-react",
|
||||
"tw-animate-css",
|
||||
],
|
||||
dependencies: ["class-variance-authority", "lucide-react"],
|
||||
devDependencies: ["tw-animate-css"],
|
||||
registryDependencies: ["utils"],
|
||||
cssVars: {},
|
||||
files: [],
|
||||
@@ -78,6 +75,11 @@ const registry = {
|
||||
if (item.name === "dashboard-01") {
|
||||
item.dependencies?.push("@tabler/icons-react")
|
||||
}
|
||||
|
||||
if (item.name === "accordion" && "tailwind" in item) {
|
||||
delete item.tailwind
|
||||
}
|
||||
|
||||
return item
|
||||
})
|
||||
),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import "@/styles/globals.css"
|
||||
import { Metadata, Viewport } from "next"
|
||||
import Link from "next/link"
|
||||
import { ArrowRightIcon } from "lucide-react"
|
||||
|
||||
import { META_THEME_COLORS, siteConfig } from "@/config/site"
|
||||
import { fontMono, fontSans } from "@/lib/fonts"
|
||||
@@ -91,7 +93,7 @@ export default function RootLayout({ children }: RootLayoutProps) {
|
||||
</head>
|
||||
<body
|
||||
className={cn(
|
||||
"min-h-svh bg-background font-sans antialiased",
|
||||
"bg-background min-h-svh font-sans antialiased",
|
||||
fontSans.variable,
|
||||
fontMono.variable
|
||||
)}
|
||||
@@ -104,7 +106,16 @@ export default function RootLayout({ children }: RootLayoutProps) {
|
||||
enableColorScheme
|
||||
>
|
||||
<div vaul-drawer-wrapper="">
|
||||
<div className="relative flex min-h-svh flex-col bg-background">
|
||||
<div className="bg-background relative flex min-h-svh flex-col">
|
||||
<div className="bg-muted text-muted-foreground sticky top-0 z-[100] flex h-10 items-center justify-center gap-2 px-4 text-sm">
|
||||
You are viewing the v3 docs.{" "}
|
||||
<Link
|
||||
href="https://ui.shadcn.com"
|
||||
className="text-primary flex items-center gap-1 underline"
|
||||
>
|
||||
Switch to latest <ArrowRightIcon className="size-3" />
|
||||
</Link>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,12 @@ import { createContentlayerPlugin } from "next-contentlayer2"
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
eslint: {
|
||||
ignoreDuringBuilds: true,
|
||||
},
|
||||
typescript: {
|
||||
ignoreBuildErrors: true,
|
||||
},
|
||||
experimental: {
|
||||
outputFileTracingIncludes: {
|
||||
"/blocks/*": ["./registry/**/*"],
|
||||
|
||||
@@ -11,35 +11,5 @@
|
||||
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport * as AccordionPrimitive from \"@radix-ui/react-accordion\"\nimport { ChevronDownIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nfunction Accordion({\n ...props\n}: React.ComponentProps<typeof AccordionPrimitive.Root>) {\n return <AccordionPrimitive.Root data-slot=\"accordion\" {...props} />\n}\n\nfunction AccordionItem({\n className,\n ...props\n}: React.ComponentProps<typeof AccordionPrimitive.Item>) {\n return (\n <AccordionPrimitive.Item\n data-slot=\"accordion-item\"\n className={cn(\"border-b last:border-b-0\", className)}\n {...props}\n />\n )\n}\n\nfunction AccordionTrigger({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {\n return (\n <AccordionPrimitive.Header className=\"flex\">\n <AccordionPrimitive.Trigger\n data-slot=\"accordion-trigger\"\n className={cn(\n \"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180\",\n className\n )}\n {...props}\n >\n {children}\n <ChevronDownIcon className=\"text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200\" />\n </AccordionPrimitive.Trigger>\n </AccordionPrimitive.Header>\n )\n}\n\nfunction AccordionContent({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof AccordionPrimitive.Content>) {\n return (\n <AccordionPrimitive.Content\n data-slot=\"accordion-content\"\n className=\"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm\"\n {...props}\n >\n <div className={cn(\"pt-0 pb-4\", className)}>{children}</div>\n </AccordionPrimitive.Content>\n )\n}\n\nexport { Accordion, AccordionItem, AccordionTrigger, AccordionContent }\n",
|
||||
"type": "registry:ui"
|
||||
}
|
||||
],
|
||||
"tailwind": {
|
||||
"config": {
|
||||
"theme": {
|
||||
"extend": {
|
||||
"keyframes": {
|
||||
"accordion-down": {
|
||||
"from": {
|
||||
"height": "0"
|
||||
},
|
||||
"to": {
|
||||
"height": "var(--radix-accordion-content-height)"
|
||||
}
|
||||
},
|
||||
"accordion-up": {
|
||||
"from": {
|
||||
"height": "var(--radix-accordion-content-height)"
|
||||
},
|
||||
"to": {
|
||||
"height": "0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"animation": {
|
||||
"accordion-down": "accordion-down 0.2s ease-out",
|
||||
"accordion-up": "accordion-up 0.2s ease-out"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -4,7 +4,9 @@
|
||||
"type": "registry:style",
|
||||
"dependencies": [
|
||||
"class-variance-authority",
|
||||
"lucide-react",
|
||||
"lucide-react"
|
||||
],
|
||||
"devDependencies": [
|
||||
"tw-animate-css"
|
||||
],
|
||||
"registryDependencies": [
|
||||
|
||||
@@ -78,7 +78,8 @@
|
||||
"registry:hook",
|
||||
"registry:theme",
|
||||
"registry:page",
|
||||
"registry:file"
|
||||
"registry:file",
|
||||
"registry:style"
|
||||
],
|
||||
"description": "The type of the file. This is used to determine the type of the file when resolved for a project."
|
||||
},
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { Transformer } from "@/src/utils/transformers"
|
||||
import { SyntaxKind } from "ts-morph"
|
||||
|
||||
import {
|
||||
TailwindVersion,
|
||||
getProjectTailwindVersionFromConfig,
|
||||
} from "../get-project-info"
|
||||
import { splitClassName } from "./transform-css-vars"
|
||||
|
||||
export const transformTwPrefixes: Transformer = async ({
|
||||
@@ -10,6 +14,7 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
if (!config.tailwind?.prefix) {
|
||||
return sourceFile
|
||||
}
|
||||
const tailwindVersion = await getProjectTailwindVersionFromConfig(config)
|
||||
|
||||
// Find the cva function calls.
|
||||
sourceFile
|
||||
@@ -23,7 +28,8 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
defaultClassNames.replaceWithText(
|
||||
`"${applyPrefix(
|
||||
defaultClassNames.getText()?.replace(/"|'/g, ""),
|
||||
config.tailwind.prefix
|
||||
config.tailwind.prefix,
|
||||
tailwindVersion
|
||||
)}"`
|
||||
)
|
||||
}
|
||||
@@ -47,7 +53,8 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
classNames?.replaceWithText(
|
||||
`"${applyPrefix(
|
||||
classNames.getText()?.replace(/"|'/g, ""),
|
||||
config.tailwind.prefix
|
||||
config.tailwind.prefix,
|
||||
tailwindVersion
|
||||
)}"`
|
||||
)
|
||||
}
|
||||
@@ -66,7 +73,8 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
value.replaceWithText(
|
||||
`"${applyPrefix(
|
||||
value.getText()?.replace(/"|'/g, ""),
|
||||
config.tailwind.prefix
|
||||
config.tailwind.prefix,
|
||||
tailwindVersion
|
||||
)}"`
|
||||
)
|
||||
}
|
||||
@@ -92,7 +100,8 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
node.replaceWithText(
|
||||
`"${applyPrefix(
|
||||
node.getText()?.replace(/"|'/g, ""),
|
||||
config.tailwind.prefix
|
||||
config.tailwind.prefix,
|
||||
tailwindVersion
|
||||
)}"`
|
||||
)
|
||||
})
|
||||
@@ -102,7 +111,8 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
node.replaceWithText(
|
||||
`"${applyPrefix(
|
||||
node.getText()?.replace(/"|'/g, ""),
|
||||
config.tailwind.prefix
|
||||
config.tailwind.prefix,
|
||||
tailwindVersion
|
||||
)}"`
|
||||
)
|
||||
}
|
||||
@@ -131,7 +141,8 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
node.replaceWithText(
|
||||
`"${applyPrefix(
|
||||
node.getText()?.replace(/"|'/g, ""),
|
||||
config.tailwind.prefix
|
||||
config.tailwind.prefix,
|
||||
tailwindVersion
|
||||
)}"`
|
||||
)
|
||||
})
|
||||
@@ -141,7 +152,8 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
arg.replaceWithText(
|
||||
`"${applyPrefix(
|
||||
arg.getText()?.replace(/"|'/g, ""),
|
||||
config.tailwind.prefix
|
||||
config.tailwind.prefix,
|
||||
tailwindVersion
|
||||
)}"`
|
||||
)
|
||||
}
|
||||
@@ -156,7 +168,8 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
classNames.replaceWithText(
|
||||
`"${applyPrefix(
|
||||
classNames.getText()?.replace(/"|'/g, ""),
|
||||
config.tailwind.prefix
|
||||
config.tailwind.prefix,
|
||||
tailwindVersion
|
||||
)}"`
|
||||
)
|
||||
}
|
||||
@@ -170,30 +183,49 @@ export const transformTwPrefixes: Transformer = async ({
|
||||
return sourceFile
|
||||
}
|
||||
|
||||
export function applyPrefix(input: string, prefix: string = "") {
|
||||
const classNames = input.split(" ")
|
||||
const prefixed: string[] = []
|
||||
for (let className of classNames) {
|
||||
const [variant, value, modifier] = splitClassName(className)
|
||||
if (variant) {
|
||||
modifier
|
||||
? prefixed.push(`${variant}:${prefix}${value}/${modifier}`)
|
||||
: prefixed.push(`${variant}:${prefix}${value}`)
|
||||
} else {
|
||||
modifier
|
||||
? prefixed.push(`${prefix}${value}/${modifier}`)
|
||||
: prefixed.push(`${prefix}${value}`)
|
||||
}
|
||||
export function applyPrefix(
|
||||
input: string,
|
||||
prefix: string = "",
|
||||
tailwindVersion: TailwindVersion
|
||||
) {
|
||||
if (tailwindVersion === "v3") {
|
||||
return input
|
||||
.split(" ")
|
||||
.map((className) => {
|
||||
const [variant, value, modifier] = splitClassName(className)
|
||||
if (variant) {
|
||||
return modifier
|
||||
? `${variant}:${prefix}${value}/${modifier}`
|
||||
: `${variant}:${prefix}${value}`
|
||||
} else {
|
||||
return modifier
|
||||
? `${prefix}${value}/${modifier}`
|
||||
: `${prefix}${value}`
|
||||
}
|
||||
})
|
||||
.join(" ")
|
||||
}
|
||||
return prefixed.join(" ")
|
||||
|
||||
return input
|
||||
.split(" ")
|
||||
.map((className) =>
|
||||
className.indexOf(`${prefix}:`) === 0
|
||||
? className
|
||||
: `${prefix}:${className.trim()}`
|
||||
)
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
export function applyPrefixesCss(css: string, prefix: string) {
|
||||
export function applyPrefixesCss(
|
||||
css: string,
|
||||
prefix: string,
|
||||
tailwindVersion: TailwindVersion
|
||||
) {
|
||||
const lines = css.split("\n")
|
||||
for (let line of lines) {
|
||||
if (line.includes("@apply")) {
|
||||
const originalTWCls = line.replace("@apply", "").trim()
|
||||
const prefixedTwCls = applyPrefix(originalTWCls, prefix)
|
||||
const prefixedTwCls = applyPrefix(originalTWCls, prefix, tailwindVersion)
|
||||
css = css.replace(originalTWCls, prefixedTwCls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
exports[`transform tailwind prefix 1`] = `
|
||||
"import * as React from "react"
|
||||
export function Foo() {
|
||||
return <div className="tw-bg-background hover:tw-bg-muted tw-text-primary-foreground sm:focus:tw-text-accent-foreground">foo</div>
|
||||
return <div className="tw:bg-background hover:tw:bg-muted tw:text-primary-foreground sm:focus:tw:text-accent-foreground">foo</div>
|
||||
}
|
||||
"
|
||||
`;
|
||||
@@ -11,7 +11,7 @@ exports[`transform tailwind prefix 1`] = `
|
||||
exports[`transform tailwind prefix 2`] = `
|
||||
"import * as React from "react"
|
||||
export function Foo() {
|
||||
return <div className="tw-bg-white hover:tw-bg-stone-100 tw-text-stone-50 sm:focus:tw-text-stone-900 dark:tw-bg-stone-950 dark:hover:tw-bg-stone-800 dark:tw-text-stone-900 dark:sm:focus:tw-text-stone-50">foo</div>
|
||||
return <div className="tw:bg-white hover:tw:bg-stone-100 tw:text-stone-50 sm:focus:tw:text-stone-900 dark:tw:bg-stone-950 dark:hover:tw:bg-stone-800 dark:tw:text-stone-900 dark:sm:focus:tw:text-stone-50">foo</div>
|
||||
}
|
||||
"
|
||||
`;
|
||||
@@ -19,7 +19,7 @@ export function Foo() {
|
||||
exports[`transform tailwind prefix 3`] = `
|
||||
"import * as React from "react"
|
||||
export function Foo() {
|
||||
return <div className={cn("tw-bg-white hover:tw-bg-stone-100 dark:tw-bg-stone-950 dark:hover:tw-bg-stone-800", true && "tw-text-stone-50 sm:focus:tw-text-stone-900 dark:tw-text-stone-900 dark:sm:focus:tw-text-stone-50")}>foo</div>
|
||||
return <div className={cn("tw:bg-white hover:tw:bg-stone-100 dark:tw:bg-stone-950 dark:hover:tw:bg-stone-800", true && "tw:text-stone-50 sm:focus:tw:text-stone-900 dark:tw:text-stone-900 dark:sm:focus:tw:text-stone-50")}>foo</div>
|
||||
}
|
||||
"
|
||||
`;
|
||||
@@ -27,7 +27,7 @@ export function Foo() {
|
||||
exports[`transform tailwind prefix 4`] = `
|
||||
"import * as React from "react"
|
||||
export function Foo() {
|
||||
return <div className={cn("tw-bg-background hover:tw-bg-muted", true && "tw-text-primary-foreground sm:focus:tw-text-accent-foreground")}>foo</div>
|
||||
return <div className={cn("tw:bg-background hover:tw:bg-muted", true && "tw:text-primary-foreground sm:focus:tw:text-accent-foreground")}>foo</div>
|
||||
}
|
||||
"
|
||||
`;
|
||||
@@ -105,10 +105,10 @@ exports[`transform tailwind prefix 5`] = `
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply tw-border-border;
|
||||
@apply tw::border-border;
|
||||
}
|
||||
body {
|
||||
@apply tw-bg-background tw-text-foreground;
|
||||
@apply tw::bg-background tw::text-foreground;
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe, expect, test } from "vitest"
|
||||
|
||||
import { applyPrefix } from "../../src/utils/transformers/transform-tw-prefix"
|
||||
|
||||
describe("apply tailwind prefix", () => {
|
||||
describe("apply tailwind prefix v3", () => {
|
||||
test.each([
|
||||
{
|
||||
input: "bg-slate-800 text-gray-500",
|
||||
@@ -37,6 +37,45 @@ describe("apply tailwind prefix", () => {
|
||||
"tw-absolute tw-right-4 tw-top-4 tw-bg-primary tw-rounded-sm tw-opacity-70 tw-ring-offset-background tw-transition-opacity hover:tw-opacity-100 focus:tw-outline-none focus:tw-ring-2 focus:tw-ring-ring focus:tw-ring-offset-2 disabled:tw-pointer-events-none data-[state=open]:tw-bg-secondary",
|
||||
},
|
||||
])(`applyTwPrefix($input) -> $output`, ({ input, output }) => {
|
||||
expect(applyPrefix(input, "tw-")).toBe(output)
|
||||
expect(applyPrefix(input, "tw-", "v3")).toBe(output)
|
||||
})
|
||||
})
|
||||
|
||||
describe("apply tailwind prefix v4", () => {
|
||||
test.each([
|
||||
{
|
||||
input: "bg-slate-800 text-gray-500",
|
||||
output: "tw:bg-slate-800 tw:text-gray-500",
|
||||
},
|
||||
{
|
||||
input: "hover:dark:bg-background dark:text-foreground",
|
||||
output: "tw:hover:dark:bg-background tw:dark:text-foreground",
|
||||
},
|
||||
{
|
||||
input:
|
||||
"rounded-lg border border-slate-200 bg-white text-slate-950 shadow-sm dark:border-slate-800 dark:bg-slate-950 dark:text-slate-50",
|
||||
output:
|
||||
"tw:rounded-lg tw:border tw:border-slate-200 tw:bg-white tw:text-slate-950 tw:shadow-sm tw:dark:border-slate-800 tw:dark:bg-slate-950 tw:dark:text-slate-50",
|
||||
},
|
||||
{
|
||||
input:
|
||||
"text-red-500 border-red-500/50 dark:border-red-500 [&>svg]:text-red-500 text-red-500 dark:text-red-900 dark:border-red-900/50 dark:dark:border-red-900 dark:[&>svg]:text-red-900 dark:text-red-900",
|
||||
output:
|
||||
"tw:text-red-500 tw:border-red-500/50 tw:dark:border-red-500 tw:[&>svg]:text-red-500 tw:text-red-500 tw:dark:text-red-900 tw:dark:border-red-900/50 tw:dark:dark:border-red-900 tw:dark:[&>svg]:text-red-900 tw:dark:text-red-900",
|
||||
},
|
||||
{
|
||||
input:
|
||||
"flex h-full w-full items-center justify-center rounded-full bg-muted",
|
||||
output:
|
||||
"tw:flex tw:h-full tw:w-full tw:items-center tw:justify-center tw:rounded-full tw:bg-muted",
|
||||
},
|
||||
{
|
||||
input:
|
||||
"absolute right-4 top-4 bg-primary rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",
|
||||
output:
|
||||
"tw:absolute tw:right-4 tw:top-4 tw:bg-primary tw:rounded-sm tw:opacity-70 tw:ring-offset-background tw:transition-opacity tw:hover:opacity-100 tw:focus:outline-none tw:focus:ring-2 tw:focus:ring-ring tw:focus:ring-offset-2 tw:disabled:pointer-events-none tw:data-[state=open]:bg-secondary",
|
||||
},
|
||||
])(`applyTwPrefix($input) -> $output`, ({ input, output }) => {
|
||||
expect(applyPrefix(input, "tw", "v4")).toBe(output)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -16,7 +16,7 @@ test("transform tailwind prefix", async () => {
|
||||
config: {
|
||||
tailwind: {
|
||||
baseColor: "stone",
|
||||
prefix: "tw-",
|
||||
prefix: "tw:",
|
||||
},
|
||||
aliases: {
|
||||
components: "@/components",
|
||||
@@ -39,7 +39,7 @@ export function Foo() {
|
||||
tailwind: {
|
||||
baseColor: "stone",
|
||||
cssVariables: false,
|
||||
prefix: "tw-",
|
||||
prefix: "tw:",
|
||||
},
|
||||
aliases: {
|
||||
components: "@/components",
|
||||
@@ -62,7 +62,7 @@ export function Foo() {
|
||||
tailwind: {
|
||||
baseColor: "stone",
|
||||
cssVariables: false,
|
||||
prefix: "tw-",
|
||||
prefix: "tw:",
|
||||
},
|
||||
aliases: {
|
||||
components: "@/components",
|
||||
@@ -85,7 +85,7 @@ export function Foo() {
|
||||
tailwind: {
|
||||
baseColor: "stone",
|
||||
cssVariables: false,
|
||||
prefix: "tw-",
|
||||
prefix: "tw:",
|
||||
},
|
||||
aliases: {
|
||||
components: "@/components",
|
||||
@@ -99,7 +99,8 @@ export function Foo() {
|
||||
expect(
|
||||
applyPrefixesCss(
|
||||
"@tailwind base;\n@tailwind components;\n@tailwind utilities;\n \n@layer base {\n :root {\n --background: 0 0% 100%;\n --foreground: 224 71.4% 4.1%;\n \n --muted: 220 14.3% 95.9%;\n --muted-foreground: 220 8.9% 46.1%;\n \n --popover: 0 0% 100%;\n --popover-foreground: 224 71.4% 4.1%;\n \n --card: 0 0% 100%;\n --card-foreground: 224 71.4% 4.1%;\n \n --border: 220 13% 91%;\n --input: 220 13% 91%;\n \n --primary: 220.9 39.3% 11%;\n --primary-foreground: 210 20% 98%;\n \n --secondary: 220 14.3% 95.9%;\n --secondary-foreground: 220.9 39.3% 11%;\n \n --accent: 220 14.3% 95.9%;\n --accent-foreground: 220.9 39.3% 11%;\n \n --destructive: 0 84.2% 60.2%;\n --destructive-foreground: 210 20% 98%;\n \n --ring: 217.9 10.6% 64.9%;\n \n --radius: 0.5rem;\n }\n \n .dark {\n --background: 224 71.4% 4.1%;\n --foreground: 210 20% 98%;\n \n --muted: 215 27.9% 16.9%;\n --muted-foreground: 217.9 10.6% 64.9%;\n \n --popover: 224 71.4% 4.1%;\n --popover-foreground: 210 20% 98%;\n \n --card: 224 71.4% 4.1%;\n --card-foreground: 210 20% 98%;\n \n --border: 215 27.9% 16.9%;\n --input: 215 27.9% 16.9%;\n \n --primary: 210 20% 98%;\n --primary-foreground: 220.9 39.3% 11%;\n \n --secondary: 215 27.9% 16.9%;\n --secondary-foreground: 210 20% 98%;\n \n --accent: 215 27.9% 16.9%;\n --accent-foreground: 210 20% 98%;\n \n --destructive: 0 62.8% 30.6%;\n --destructive-foreground: 0 85.7% 97.3%;\n \n --ring: 215 27.9% 16.9%;\n }\n}\n \n@layer base {\n * {\n @apply border-border;\n }\n body {\n @apply bg-background text-foreground;\n }\n}",
|
||||
"tw-"
|
||||
"tw:",
|
||||
"v4"
|
||||
)
|
||||
).toMatchSnapshot()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user