mirror of
https://github.com/status-im/consul.git
synced 2025-02-07 19:35:35 +00:00
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
55 lines
1.7 KiB
JavaScript
55 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]));
|
|
}
|
|
|
|
didReceiveArguments() {
|
|
if (typeof this.args.named.delay !== 'undefined') {
|
|
setTimeout((_) => {
|
|
if (typeof this !== this.args.positional[0]) {
|
|
this.setStyles(this.args.positional[0]);
|
|
}
|
|
}, this.args.named.delay);
|
|
} else {
|
|
this.setStyles(this.args.positional[0]);
|
|
}
|
|
}
|
|
}
|