1.0.8 • Published 6 months ago

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

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

@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

1.0.8

6 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

12 months ago

1.0.1

1 year ago

1.0.2-beta.0

12 months ago

1.0.1-beta.0

1 year ago

1.0.0

1 year ago