}
})
})
+ test('style', () => {
+ let props1: Data = {
+ style: 'width:100px;right:10;top:10'
+ }
+ let props2: Data = {
+ style: [
+ {
+ color: 'blue',
+ width: '200px'
+ },
+ {
+ width: '300px',
+ height: '300px',
+ fontSize: 30
+ }
+ ]
+ }
+ expect(mergeProps(props1, props2)).toMatchObject({
+ style: {
+ color: 'blue',
+ width: '300px',
+ height: '300px',
+ fontSize: 30,
+ right: 10,
+ top: 10
+ }
+ })
+ })
test('handlers', () => {
let clickHandler1 = function() {}
if (isArray(value)) {
const res: Record<string, string | number> = {}
for (let i = 0; i < value.length; i++) {
- const normalized = normalizeStyle(value[i])
+ const styles = isString(value[i]) ? strStyleToObj(value[i]) : value[i]
+ const normalized = normalizeStyle(styles)
if (normalized) {
for (const key in normalized) {
res[key] = normalized[key]
}
}
+function strStyleToObj(style: string) {
+ const ret: Record<string, string | number> = {}
+ style
+ .replace(/\s*/g, '')
+ .split(';')
+ .forEach((item: string) => {
+ const [key, val] = item.split(':')
+ ret[key] = isNaN(Number(val)) ? val : Number(val)
+ })
+ return ret
+}
+
export function stringifyStyle(
styles: Record<string, string | number> | undefined
): string {