import 'react' declare global { type DetailProps = Omit, T>, 'className'> type CustomElementProps = DetailProps & P interface TestComponentElementProps { 'simple-attr'?: string, callback?: (arg: string | null) => void, class?: string | null } interface TestComponentElement extends HTMLElement, TestComponentElementProps { } // eslint-disable-next-line @typescript-eslint/no-namespace namespace JSX { interface IntrinsicElements { 'test-component': CustomElementProps } } } export default class TestWebComponent extends HTMLElement { static get observedAttributes (): string[] { return ['simple-attr'] } callback?: (arg: string | null) => void connectedCallback (): void { this.buildContent() } attributeChangedCallback (name: string, oldValue: any, newValue: any): void { if (oldValue !== newValue) this.buildContent() } private buildContent (): void { const textContent = this.getAttribute('simple-attr') this.innerHTML = `
${textContent ?? ''}
` this.querySelector('#button')!.onclick = evt => { this.callback?.(textContent) this.dispatchEvent(new CustomEvent('button-clicked', { detail: { attributeValue: textContent } })) this.dispatchEvent(new CustomEvent('buttonClicked', { detail: { attributeValue: textContent } })) } } }