mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
5ab7e48862
This commit/PR beings to move away from using CSS preprocessing for our icons and towards using native CSS via native CSS property composition
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
import { modifier } from 'ember-modifier';
|
|
const STYLE_RULE = 1;
|
|
const getCustomProperties = function() {
|
|
return Object.fromEntries(
|
|
[...document.styleSheets].reduce(
|
|
(prev, item) =>
|
|
prev.concat(
|
|
[...item.cssRules]
|
|
.filter(item => item.type === STYLE_RULE)
|
|
.reduce((prev, rule) => {
|
|
const props = [...rule.style]
|
|
.filter(prop => prop.startsWith('--'))
|
|
.map(prop => [prop.trim(), rule.style.getPropertyValue(prop).trim()]);
|
|
return [...prev, ...props];
|
|
}, [])
|
|
),
|
|
[]
|
|
)
|
|
);
|
|
};
|
|
const props = getCustomProperties();
|
|
export default modifier(function($element, [returns], hash) {
|
|
const re = new RegExp(`^--${hash.prefix || '.'}${hash.group || ''}+`);
|
|
const obj = {};
|
|
Object.entries(props).forEach(([key, value]) => {
|
|
const res = key.match(re);
|
|
if(res) {
|
|
let prop = res[0];
|
|
if (prop.charAt(prop.length - 1) === '-') {
|
|
prop = prop.substr(0, prop.length - 1);
|
|
}
|
|
if(hash.group) {
|
|
if (typeof obj[prop] === 'undefined') {
|
|
obj[prop] = {};
|
|
}
|
|
obj[prop][key] = value;
|
|
} else {
|
|
obj[key] = value;
|
|
}
|
|
}
|
|
});
|
|
returns(obj);
|
|
});
|