1.0.8 • Published 7 months ago

@web-component-attribute-polyfill/core v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@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

1.0.8

7 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.2-beta.0

1 year ago

1.0.1-beta.0

1 year ago

1.0.0

1 year ago