Skip to content

Commit

Permalink
fix: semantic classes generation for P3 colors
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaidev committed May 27, 2024
1 parent addbdf4 commit a4510a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ test("Given no option, both utility and semantic classes are generated", async (
expect(await format(result)).toStrictEqual(await format(expected));
});

test("Given no option, both utility and semantic classes are generated for P3 colors", async () => {
const expected = `
.bg-slatep3-1 {
background-color: color(display-p3 0.988 0.988 0.992);
}
.bg-slatep3-app {
background-color: color(display-p3 0.988 0.988 0.992);
}
@media (prefers-color-scheme: dark) {
.bg-slatep3-app {
background-color: color(display-p3 0.067 0.067 0.074);
}
}
`;

const result = await run({ content: "bg-slatep3-1 bg-slatep3-app" });

expect(await format(result)).toStrictEqual(await format(expected));
});

test("Given `disableSemantics: true`, only utility classes are generated", async () => {
const expected = `
.bg-slate-1 {
Expand Down
5 changes: 4 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,8 @@ function findColorFamily(palette: Palette, colorName: string) {
* @see https://github.com/tailwindlabs/tailwindcss/discussions/2049
*/
function apply(...classes: string[]) {
return { [`@apply ${classes.join(" ")}`]: {} };
const processedClasses = classes.map((className) =>
className.replaceAll(" ", "_"),
);
return { [`@apply ${processedClasses.join(" ")}`]: {} };
}

0 comments on commit a4510a8

Please sign in to comment.