-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Transform style initial implemented with simply important (#6)
- Loading branch information
Showing
3 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/transform-to-vanilla/src/transform-object/index.ts
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,48 @@ | ||
import { simplyImportant } from "@/transform-values/simply-important"; | ||
import type { StyleRule } from "@vanilla-extract/css"; | ||
import type { | ||
CSSRule, | ||
CSSRuleKey, | ||
CSSRuleValue, | ||
StyleRuleValue | ||
} from "@/types/style-rule"; | ||
|
||
// == Interface ================================================================ | ||
export function transformStyle(style: CSSRule) { | ||
const result: { | ||
// key in StyleRuleKey occur a error | ||
// Type '{}' is missing the following properties from type | ||
// '{ accentColor: StyleRuleValue; alignContent: StyleRuleValue; alignItems: StyleRuleValue; alignSelf: StyleRuleValue; ... 904 more ...; | ||
// vars: StyleRuleValue; }': accentColor, alignContent, alignItems, alignSelf, and 905 more.ts(2740) | ||
[key in string]: StyleRuleValue; | ||
} = {}; | ||
|
||
for (const [key, value] of Object.entries(style) as [ | ||
CSSRuleKey, | ||
CSSRuleValue | ||
][]) { | ||
if (typeof value === "string") { | ||
result[key] = simplyImportant(value); | ||
continue; | ||
} | ||
result[key] = value; | ||
} | ||
return result as StyleRule; | ||
} | ||
|
||
// == Tests ==================================================================== | ||
if (import.meta.vitest) { | ||
const { describe, it, expect } = import.meta.vitest; | ||
|
||
describe.concurrent("transform", () => { | ||
it("Simply Important", () => { | ||
expect( | ||
transformStyle({ | ||
color: "red!" | ||
}) | ||
).toStrictEqual({ | ||
color: "red !important" | ||
} satisfies StyleRule); | ||
}); | ||
}); | ||
} |
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