-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from vnphanquang/main
Add support for Tailwind v4 CSS theme override
- Loading branch information
Showing
6 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const snapshot = {}; | ||
|
||
snapshot[`Tailwind v4 palette theme override 1`] = ` | ||
" | ||
@theme { | ||
--color-*: initial; | ||
--color-white: #fff; | ||
--color-black: #000; | ||
--color-red-100:oklch(0.966797 0.0171875 20); | ||
--color-red-500:oklch(0.742188 0.151562 20); | ||
--color-orange-100:oklch(0.966797 0.0171875 43.3333); | ||
}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { path } from "../deps.ts"; | ||
import type { ExportTarget } from "../types.ts"; | ||
|
||
const css = String.raw; | ||
|
||
export const buildTailwindv4Palette: ExportTarget = async ( | ||
{ palette, targetDir }, | ||
) => { | ||
const vars: string[] = []; | ||
|
||
for (const [color, shades] of Object.entries(palette)) { | ||
for (const [shade, value] of Object.entries(shades)) { | ||
vars.push(`--color-${color}-${shade}:${value.oklch};`); | ||
} | ||
vars.push(""); | ||
} | ||
|
||
const template = css` | ||
@theme { | ||
--color-*: initial; | ||
--color-white: #fff; | ||
--color-black: #000; | ||
${vars.join("\n ")} | ||
}`; | ||
|
||
await Deno.writeTextFile(path.join(targetDir, "index.css"), template); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { buildTailwindv4Palette } from "./tailwind-v4.ts"; | ||
import { testExportTarget } from "./testUtils.ts"; | ||
|
||
Deno.test("Tailwind v4 palette theme override", async (t) => { | ||
await testExportTarget(t, buildTailwindv4Palette, [ | ||
"index.css", | ||
]); | ||
}); | ||
|