github.com/manicqin/nomad@v0.9.5/ui/app/utils/properties/style-string.js (about)

     1  import { computed } from '@ember/object';
     2  
     3  // An Ember.Computed property for transforming an object into an
     4  // html compatible style attribute
     5  //
     6  // ex. styleProps: { color: '#FF0', border-width: '1px' }
     7  //     styleStr: styleStringProperty('styleProps') // color:#FF0;border-width:1px
     8  export default function styleStringProperty(prop) {
     9    return computed(prop, function() {
    10      const styles = this.get(prop);
    11      let str = '';
    12  
    13      if (styles) {
    14        str = Object.keys(styles)
    15          .reduce(function(arr, key) {
    16            const val = styles[key];
    17            arr.push(key + ':' + (typeof val === 'number' ? val.toFixed(2) + 'px' : val));
    18            return arr;
    19          }, [])
    20          .join(';');
    21      }
    22  
    23      return str.htmlSafe();
    24    });
    25  }