@web-component-attribute-polyfill/core
v1.0.7
Published
Core logic of the polyfill
Downloads
8
Readme
@web-component-attribute-polyfill/core
Core logic of the polyfill with the observations of the mutations of the elements and attributes, etc...
Usage
import {
defineAttribute,
enableClosedShadowRoot,
observeAttributes,
CustomAttribute,
} from '@web-component-attribute-polyfill/core';
class BorderStylingAttribute extends CustomAttribute {
attributeChangedCallback(name, oldValue, newValue) {
super.attributeChangedCallback(name, oldValue, newValue);
this.applyColor(newValue);
}
connectedCallback() {
super.connectedCallback();
this.element.style.padding = '1rem';
this.element.style.border = '3px solid black';
this.element.style.borderRadius = '1rem';
this.applyColor();
}
applyColor(styling) {
if (styling === 'variant') {
this.element.style.borderColor = 'red';
} else {
this.element.style.borderColor = 'black';
}
}
}
defineAttribute('border-styling', BorderStylingAttribute);
enableClosedShadowRoot(globalThis); // If we want to be able to look on closed shadow dom
globalThis.addEventListener('DOMContentLoaded', () => {
observeAttributes();
});
Commands
npm run dev:linting
: Lint filesnpm test
: Run testsnpm run test:coverage
: Run tests and see coverage reports