Skip to content

Commit

Permalink
fix(hiccup-css): update conditional formatting
Browse files Browse the repository at this point in the history
- add tests
  • Loading branch information
postspectacular committed Dec 14, 2023
1 parent 08628b3 commit f126005
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/hiccup-css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"export",
"fileformat",
"hiccup",
"iterator",
"json",
"typescript",
"ui"
Expand Down
6 changes: 4 additions & 2 deletions packages/hiccup-css/src/conditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const formatCond = (cond: any) => {
if (cond.hasOwnProperty(c)) {
let v = cond[c];
if (v === true) {
v = c;
v = MEDIA_TYPES.has(c) ? c : `(${c})`;
} else if (v === false) {
v = "not " + c;
v = "not " + (MEDIA_TYPES.has(c) ? c : `(${c})`);
} else if (v === "only") {
v += " " + c;
} else {
Expand All @@ -36,3 +36,5 @@ const formatCond = (cond: any) => {
}
return acc.join(" and ");
};

const MEDIA_TYPES = new Set(["all", "print", "screen"]);
6 changes: 6 additions & 0 deletions packages/hiccup-css/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ test("@media", () => {
).toBe(
"@media screen and print{div .foo{color:red;}@media print and (max-width:20rem){div{border:0;}}}"
);
expect(css(at_media({ "prefers-reduced-motion": true }, []))).toBe(
`@media (prefers-reduced-motion){}`
);
expect(css(at_media({ "prefers-reduced-motion": false }, []))).toBe(
`@media not (prefers-reduced-motion){}`
);
});

test("animation", () => {
Expand Down

0 comments on commit f126005

Please sign in to comment.