rofrischmann/fela

View on GitHub
packages/fela-plugin-custom-property/src/index.js

Summary

Maintainability
A
1 hr
Test Coverage
import isPlainObject from 'isobject'
import { assignStyle } from 'css-in-js-utils'

function resolveCustomProperty(style, properties) {
  for (const property in style) {
    const value = style[property]

    if (properties.hasOwnProperty(property)) {
      const 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)
  }
}