@web-component-attribute-polyfill/types

v1.0.2-beta.0
Typescript definition of the polyfill
Typescript typings types

npm version install size Known Vulnerabilities license

@web-component-attribute-polyfill/types

Typescript definition of the polyfill

Usage

import type { AttributeName } from '@web-component-attribute-polyfill/core';
import type {
  Window,
  CustomElementRegistry,
} from '@web-component-attribute-polyfill/browser';

import '@web-component-attribute-polyfill/browser';
import { CustomAttribute } from '@web-component-attribute-polyfill/core';

const window = globalThis.window as unknown as Window;
const customElements = window.customElements as CustomElementRegistry;

class BorderStylingAttribute extends CustomAttribute {
  attributeChangedCallback(
    name: AttributeName,
    oldValue: string,
    newValue: string,
  ) {
    super.attributeChangedCallback(name, oldValue, newValue);
    this.applyColor(newValue);
  }

  connectedCallback() {
    super.connectedCallback();

    const element = this.element as HTMLElement;

    element.style.padding = '1rem';
    element.style.border = '3px solid black';
    element.style.borderRadius = '1rem';
    this.applyColor();
  }

  applyColor(styling: string = 'default') {
    const element = this.element as HTMLElement;

    if (styling === 'variant') {
      element.style.borderColor = 'red';
    } else {
      element.style.borderColor = 'black';
    }
  }
}

customElements.defineAttribute('border-styling', BorderStylingAttribute);

Commands

  • npm run dev:build: Generate the typings from Typescrip's definition files
  • npm test: Ensure we define correclty the definitions

Contributing

npm i @web-component-attribute-polyfill/[email protected]

Metadata

  • MIT
  • ^16.10.0 || ^18.12.0 || >=20.0.0
  • Unknown
  • released 7/21/2024

Downloads

Maintainers