@web-component-attribute-polyfill/core

v1.0.7
Core logic of the polyfill

npm version install size Known Vulnerabilities license

@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 files
  • npm test: Run tests
  • npm run test:coverage: Run tests and see coverage reports

Contributing

npm i @web-component-attribute-polyfill/core

Metadata

  • MIT
  • ^16.10.0 || ^18.12.0 || >=20.0.0
  • Unknown
  • released 8/16/2024

Downloads

Maintainers