fela-plugin-custom-property
Version:
Fela plugin to use custom properties
29 lines (23 loc) • 755 B
JavaScript
import isPlainObject from 'isobject';
import { assignStyle } from 'css-in-js-utils';
function resolveCustomProperty(style, properties) {
for (var property in style) {
var value = style[property];
if (properties.hasOwnProperty(property)) {
var resolved = properties[property](value);
assignStyle(style, resolved);
if (!resolved.hasOwnProperty(property)) {
delete style[property];
}
}
if (style.hasOwnProperty(property) && isPlainObject(value)) {
style[property] = resolveCustomProperty(value, properties);
}
}
return style;
}
export default function customProperty(properties) {
return function customPropertyPlugin(style) {
return resolveCustomProperty(style, properties);
};
}