lion/packages-node/providence-analytics/dashboard/app/utils/DecorateMixin.js
2023-11-08 19:01:20 +01:00

40 lines
1.1 KiB
JavaScript

import { GlobalDecorator } from './GlobalDecorator.js';
// TODO: dedupe via @lion
export const DecorateMixin = superclass => {
// eslint-disable-next-line no-shadow
class DecorateMixin extends superclass {
/**
*
* @param {CssResult[]} styles
* @param {boolean} prepend
*/
static decorateStyles(styles, { prepend } = {}) {
if (!prepend) {
this.__decoratedStyles.push(styles);
} else {
this.__decoratedStylesPrepended.push(styles);
}
}
static decorateMethod(name, fn) {
const originalMethod = this.prototype[name];
this.prototype[name] = (...args) => {
fn(originalMethod, ...args);
};
}
static get styles() {
return [
...GlobalDecorator.globalDecoratedStylesPrepended,
...this.__decoratedStylesPrepended,
...(super.styles || []),
...GlobalDecorator.globalDecoratedStyles,
...this.__decoratedStyles,
];
}
}
DecorateMixin.__decoratedStyles = [];
DecorateMixin.__decoratedStylesPrepended = [];
return DecorateMixin;
};