rofrischmann/react-look

View on GitHub
packages/react-look/modules/plugins/fallbackValue.js

Summary

Maintainability
A
0 mins
Test Coverage
import assignStyles from 'assign-styles'
import _ from 'lodash'

import camelToDashCase from '../utils/camelToDashCase'

/**
 * Resolves alternative values provided as an Array
 */
export default function fallbackValue({ styles, resolve, ...pluginInterface }) {
  Object.keys(styles).forEach(property => {
    const value = styles[property]
    if (_.isArray(value)) {
      styles[property] = value.join(';' + camelToDashCase(property) + ':')
    } else if (_.isPlainObject(value)) {
      styles[property] = resolve({
        ...pluginInterface,
        styles: assignStyles({ }, value),
        resolve
      })
    }
  })

  return styles
}