Skip to content

Commit f678c3f

Browse files
author
Ian Vieira
committed
Fix component style attribute parser
1 parent faad529 commit f678c3f

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

lib/attributes-to-props.js

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
var utilities = require('./utilities');
77
var propertyConfig = require('./property-config');
8+
var cssToReactNative = require('css-to-react-native');
89
var config = propertyConfig.config;
910
var isCustomAttribute = propertyConfig.HTMLDOMPropertyConfig.isCustomAttribute;
1011

@@ -63,33 +64,16 @@ function cssToJs(style) {
6364
throw new Error('`cssToJs`: first argument must be a string. ');
6465
}
6566

66-
var result = {};
67-
// e.g., `color: #f00`
68-
var declarations = style.split(';');
69-
// css property itemized as key and value
70-
var properties;
71-
var j;
72-
var propertiesLen;
67+
var styles = style.split(';');
68+
styles = styles.map(function (style) {
69+
var parts = style.split(':');
70+
var propName = parts[0];
71+
parts.shift();
72+
var propValue = parts.join(':');
73+
return [propName.trim(), propValue.trim()];
74+
});
7375

74-
for (var i = 0, declarationsLen = declarations.length; i < declarationsLen; i++) {
75-
properties = declarations[i].trim().split(':');
76-
77-
// skip if not a css property
78-
if (properties.length !== 2) { continue; }
79-
80-
// css property name
81-
properties[0] = properties[0].trim();
82-
// css property value
83-
properties[1] = properties[1].trim();
84-
85-
if (properties[0] && properties[1]) {
86-
for (j = 0, propertiesLen = properties.length; j < propertiesLen; j++) {
87-
result[utilities.camelCase(properties[0])] = properties[1];
88-
}
89-
}
90-
}
91-
92-
return result;
76+
return cssToReactNative.default(styles);
9377
}
9478

9579
/**

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"converter"
3030
],
3131
"dependencies": {
32+
"css-to-react-native": "^2.0.4",
3233
"html-dom-parser": "0.1.2",
3334
"react-dom-core": "0.0.2"
3435
},

0 commit comments

Comments
 (0)