Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for css vars in hyphenate properties #30

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-vans-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@navita/engine': minor
---

css vars will not be automatically hyphenated
2 changes: 1 addition & 1 deletion packages/engine/src/helpers/declarationsToBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hyphenateProperty } from "./hypenateProperty";
import { hyphenateProperty } from "./hyphenateProperty";

// https://github.com/styletron/styletron/blob/b552ddc5050a8cc5eec84a46a299d937d3bb0112/packages/styletron-engine-atomic/src/css.ts#L36
export function declarationsToBlock(style: Record<string, string | number>): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Modified from
// https://github.com/styletron/styletron/blob/b552ddc5050a8cc5eec84a46a299d937d3bb0112/packages/styletron-engine-atomic/src/hyphenate-style-name.ts
const uppercasePattern = /[A-Z]/g;
const msPattern = /^ms-/;
const cssVarPattern = /^--/;
const cache = {};

export function hyphenateProperty(property: string): string {
if (cssVarPattern.test(property)) {
return property;
}

return property in cache
? cache[property]
: (cache[property] = property
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/src/processStyles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StyleRule } from "@navita/types";
import type { Cache } from "./cache";
import { generateCombinedAtRules } from "./helpers/generateCombinedAtRules";
import { hyphenateProperty } from "./helpers/hypenateProperty";
import { hyphenateProperty } from "./helpers/hyphenateProperty";
import { isMediaQuery } from "./helpers/isMediaQuery";
import { isNestedSelector } from "./helpers/isNestedSelector";
import { isObject } from "./helpers/isObject";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hyphenateProperty } from "../../../src/helpers/hypenateProperty";
import { hyphenateProperty } from "../../../src/helpers/hyphenateProperty";

describe("hypenateProperty", () => {
it("should return the same value if it is already hyphenated", () => {
Expand All @@ -12,4 +12,8 @@ describe("hypenateProperty", () => {
it('ms- prefix should be lowercase', () => {
expect(hyphenateProperty('msBackground')).toBe('-ms-background');
});

it(`it doesn't hyphenate css vars`, () => {
expect(hyphenateProperty('--myVar')).toBe('--myVar');
});
});
Loading