Commit 5bd41a44 authored by Robert Knight's avatar Robert Knight

Make `PreactContainer` render function more flexible

Allow components to render `null` or other non-element values.
parent 53d1ecb0
import type { JSX } from 'preact'; import type { ComponentChild } from 'preact';
import { render } from 'preact'; import { render } from 'preact';
import type { Destroyable } from '../../types/annotator'; import type { Destroyable } from '../../types/annotator';
...@@ -19,7 +19,7 @@ import { createShadowRoot } from './shadow-root'; ...@@ -19,7 +19,7 @@ import { createShadowRoot } from './shadow-root';
export class PreactContainer implements Destroyable { export class PreactContainer implements Destroyable {
private _element: HTMLElement; private _element: HTMLElement;
private _shadowRoot: ShadowRoot; private _shadowRoot: ShadowRoot;
private _render: () => JSX.Element; private _render: () => ComponentChild;
/** /**
* Create a new `<hypothesis-{name}>` container element. * Create a new `<hypothesis-{name}>` container element.
...@@ -30,7 +30,7 @@ export class PreactContainer implements Destroyable { ...@@ -30,7 +30,7 @@ export class PreactContainer implements Destroyable {
* @param name - Suffix for the element * @param name - Suffix for the element
* @param render - Callback that renders the root JSX element for this container * @param render - Callback that renders the root JSX element for this container
*/ */
constructor(name: string, render: () => JSX.Element) { constructor(name: string, render: () => ComponentChild) {
const tag = `hypothesis-${name}`; const tag = `hypothesis-${name}`;
this._element = document.createElement(tag); this._element = document.createElement(tag);
this._shadowRoot = createShadowRoot(this._element); this._shadowRoot = createShadowRoot(this._element);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment