styled-components
Version:
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
21 lines (18 loc) • 624 B
JavaScript
import camelizeStyleName from 'fbjs/lib/camelizeStyleName'
import hyphenateStyleName from 'fbjs/lib/hyphenateStyleName'
import { autoprefix } from 'glamor/lib/autoprefix'
export default root => {
root.walkDecls(decl => {
/* No point even checking custom props */
if (decl.prop.startsWith('--')) return
const objStyle = { [camelizeStyleName(decl.prop)]: decl.value }
const prefixed = autoprefix(objStyle)
Object.keys(prefixed).reverse().forEach(newProp => {
decl.cloneBefore({
prop: hyphenateStyleName(newProp),
value: prefixed[newProp],
})
})
decl.remove()
})
}