mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 01:45:44 +03:00
Move new glimmer style string to its own home
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { htmlSafe } from '@ember/template';
|
||||
import { action } from '@ember/object';
|
||||
import styleString from 'nomad-ui/utils/properties/glimmer-style-string';
|
||||
|
||||
const iconFor = {
|
||||
error: 'cancel-circle-fill',
|
||||
@@ -12,30 +13,6 @@ const iconClassFor = {
|
||||
info: '',
|
||||
};
|
||||
|
||||
// TODO: This is what styleStringProperty looks like in the pure decorator world
|
||||
function styleString(target, name, descriptor) {
|
||||
if (!descriptor.get) throw new Error('styleString only works on getters');
|
||||
const orig = descriptor.get;
|
||||
descriptor.get = function() {
|
||||
const styles = orig.apply(this);
|
||||
|
||||
let str = '';
|
||||
|
||||
if (styles) {
|
||||
str = Object.keys(styles)
|
||||
.reduce(function(arr, key) {
|
||||
const val = styles[key];
|
||||
arr.push(key + ':' + (typeof val === 'number' ? val.toFixed(2) + 'px' : val));
|
||||
return arr;
|
||||
}, [])
|
||||
.join(';');
|
||||
}
|
||||
|
||||
return htmlSafe(str);
|
||||
};
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
export default class ChartPrimitiveVAnnotations extends Component {
|
||||
@styleString
|
||||
get chartAnnotationsStyle() {
|
||||
|
||||
31
ui/app/utils/properties/glimmer-style-string.js
Normal file
31
ui/app/utils/properties/glimmer-style-string.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { htmlSafe } from '@ember/template';
|
||||
|
||||
// A decorator for transforming an object into an html
|
||||
// compatible style attribute string.
|
||||
//
|
||||
// ex. @styleString
|
||||
// get styleStr() {
|
||||
// return { color: '#FF0', 'border-width': '1px' }
|
||||
// }
|
||||
export default function styleString(target, name, descriptor) {
|
||||
if (!descriptor.get) throw new Error('styleString only works on getters');
|
||||
const orig = descriptor.get;
|
||||
descriptor.get = function() {
|
||||
const styles = orig.apply(this);
|
||||
|
||||
let str = '';
|
||||
|
||||
if (styles) {
|
||||
str = Object.keys(styles)
|
||||
.reduce(function(arr, key) {
|
||||
const val = styles[key];
|
||||
arr.push(key + ':' + (typeof val === 'number' ? val.toFixed(2) + 'px' : val));
|
||||
return arr;
|
||||
}, [])
|
||||
.join(';');
|
||||
}
|
||||
|
||||
return htmlSafe(str);
|
||||
};
|
||||
return descriptor;
|
||||
}
|
||||
Reference in New Issue
Block a user