| 6 | * CSSStyle 转换为 style 字符串 |
| 7 | */ |
| 8 | export const cssStyleToString = (style: Partial<CSSStyleDeclaration>): string => { |
| 9 | return Object.keys(style).reduce((accumulator, key) => { |
| 10 | // transform the key from camelCase to kebab-case |
| 11 | const cssKey = kebabCase(key) |
| 12 | // remove ' in value |
| 13 | const cssValue = (style as Record<string, any>)[key].replace("'", '') |
| 14 | // build the result |
| 15 | // you can break the line, add indent for it if you need |
| 16 | return `${accumulator}${cssKey}:${cssValue};` |
| 17 | }, '') |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * React.HTMLAttributes<HTMLElement> 转换为 attributes 字符串 |