We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
styleMap
1 parent 3bd182f commit df32e14Copy full SHA for df32e14
src/lib/utils.ts
@@ -373,11 +373,16 @@ export function removeItems(target: any[], items: any[]) {
373
});
374
}
375
376
-export function styleMap(obj: Partial<CSSStyleDeclaration>) {
+type StyleProp = keyof CSSStyleDeclaration | `--${string}`;
377
+
378
+export type StyleObject = Partial<Record<StyleProp, string | number | undefined>>;
379
380
+// 不支持 webkit 属性
381
+export function styleMap(object: StyleObject) {
382
let styleString = '';
- for (const key in obj) {
- if (obj[key]) {
- styleString += `${camelToKebabCase(key)}:${obj[key]};`;
383
+ for (const key in object) {
384
+ if (object[key as StyleProp] !== undefined) {
385
+ styleString += `${camelToKebabCase(key)}:${object[key as StyleProp]};`;
386
387
388
return styleString;
0 commit comments