import { HTMLWidget, publish, SVGWidget } from "@hpcc-js/common"; import * as React from "@hpcc-js/preact-shim"; export function render
(C: React.FunctionComponent
, props: Readonly
, parent: Element | Document | ShadowRoot | DocumentFragment, replaceNode?: Element | Text) {
React.render(React.h(C, props), parent, replaceNode);
}
export interface FunctionComponent (C: React.FunctionComponent , props: Readonly , parent: Element | Document | ShadowRoot | DocumentFragment, replaceNode?: Element | Text) {
React.render(React.h("svg", null, React.h(C, props)), parent, replaceNode);
}
export class HTMLAdapter extends HTMLWidget {
@publish({}, "object", "Properties")
protected _props: P = {} as P;
props(): P;
props(_: Partial ): this;
props(_?: Partial ): P | this {
if (!arguments.length) return this._props;
this._props = { ...this._props, ..._ };
return this;
}
prop ) {
super();
}
update(domNode, element) {
super.update(domNode, element);
render(this._component, this._props, domNode);
}
}
export class SVGAdapter extends SVGWidget {
@publish({}, "object", "Properties")
protected _props: P = {} as P;
props(): P;
props(_: Partial ): this;
props(_?: Partial ): P | this {
if (!arguments.length) return this._props;
this._props = { ...this._props, ..._ };
return this;
}
prop ) {
super();
}
update(domNode, element) {
super.update(domNode, element);
render(this._component, this._props, domNode);
}
}