Function Component

  • Class decorator factory. Registers the decorated class as Component through the customElements registry. Registered Components can be used in conjunction with any of the Attribute, Fluctuate and Reference prototype property decorators which will trigger their respective callbacks or Component.renderComponent whenever one of the Component.observedAttributes, Component.observedFluctuations or Component.observedReferences changes. While any Component registered by this decorator is enriched with basic rendering functionality, any implemented method will cancel out its super logic.

    Type Parameters

    Parameters

    • selector: S

      The custom Component tag name selector.

    • Optional inherits: K

      The HTMLElement this Component inherits from.

    Returns (<T>(constructor) => T)

    A class constructor decorator.

      • <T>(constructor): T
      • Type Parameters

        • T extends (new () => Component & HTMLElementTagNameMap[S] & HTMLElementTagNameMap[K])

        Parameters

        • constructor: T

        Returns T

    Example

    Register a Component:

    import { Component } from '@sgrud/shell';

    declare global {
    interface HTMLElementTagNameMap {
    'example-component': ExampleComponent;
    }
    }

    ⁠@Component('example-component')
    export class ExampleComponent extends HTMLElement implements Component {

    public readonly styles: string[] = [`
    span {
    font-style: italic;
    }
    `];

    public get template(): JSX.Element {
    return <span>Example component</span>;
    }

    }

    See

Generated using TypeDoc