mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 05:45:46 +00:00
a6c990c6fe
* Upgrade @hashicorp/design-system-tokens to 1.9.0 * Upgrade @hashicorp/design-system-components to 1.8.1 * Upgrade @hashicorp/design-system-components and ember-in-viewport * Explicitly install ember-modifier@4.1.0 * rename copy-button * Fix how cleanup is done in with-copyable * Update aria-menu modifier for new structure * Update css-prop modifier to new structure * Convert did-upsert to regular class modifier * Update notification modifier for new structure * Update on-oustside modifier for new structure * Move destroy handler registration in with-copyable * Update style modifier for new structure * Update validate modifier for new structure * Guard against setting on destroyed object * Upgrade @hashicorp/design-system-components to 2.14.1 * Remove debugger * Guard against null in aria-menu * Fix undefined hash in validate addon * Upgrade ember-on-resize-modifier * Fix copy button import, missing import and array destructuring --------- Co-authored-by: wenincode <tyler.wendlandt@hashicorp.com>
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Modifier from 'ember-modifier';
|
|
import { assert } from '@ember/debug';
|
|
|
|
export default class StyleModifier extends Modifier {
|
|
setStyles(newStyles = []) {
|
|
const rulesToRemove = this._oldStyles || new Set();
|
|
if (!Array.isArray(newStyles)) {
|
|
newStyles = Object.entries(newStyles);
|
|
}
|
|
newStyles.forEach(([property, value]) => {
|
|
assert(
|
|
`Your given value for property '${property}' is ${value} (${typeof value}). Accepted types are string and undefined. Please change accordingly.`,
|
|
typeof value === 'undefined' || typeof value === 'string'
|
|
);
|
|
|
|
// priority must be specified as separate argument
|
|
// value must not contain "!important"
|
|
let priority = '';
|
|
if (value.length > 0 && value.includes('!important')) {
|
|
priority = 'important';
|
|
value = value.replace('!important', '');
|
|
}
|
|
|
|
// update CSSOM
|
|
this.element.style.setProperty(property, value, priority);
|
|
|
|
// should not remove rules that have been updated in this cycle
|
|
rulesToRemove.delete(property);
|
|
});
|
|
|
|
// remove rules that were present in last cycle but aren't present in this one
|
|
rulesToRemove.forEach((rule) => this.element.style.removeProperty(rule));
|
|
|
|
// cache styles that in this rendering cycle for the next one
|
|
this._oldStyles = new Set(newStyles.map((e) => e[0]));
|
|
}
|
|
|
|
modify(element, positional, named) {
|
|
this.element = element;
|
|
|
|
if (typeof named.delay !== 'undefined') {
|
|
setTimeout((_) => {
|
|
if (typeof this !== positional[0]) {
|
|
this.setStyles(positional[0]);
|
|
}
|
|
}, named?.delay);
|
|
} else {
|
|
this.setStyles(positional[0]);
|
|
}
|
|
}
|
|
}
|