Typed components and recursive children
Build a component with createElement, group its children in a Fragment, and render textual children.
APIs demonstrated
Section titled “APIs demonstrated”- createElement from
@pibbl/core - Fragment from
@pibbl/core - PibblComponent from
@pibbl/core - PibblElement from
@pibbl/core - PibblElementType from
@pibbl/core - PibblKey from
@pibbl/core - PibblNode from
@pibbl/core - PibblNodeInput from
@pibbl/core - PibblContainerChild from
@pibbl/core - PibblEmptyNode from
@pibbl/core - PibblTextChild from
@pibbl/core - PibblTextInput from
@pibbl/core - PibblRenderResult from
@pibbl/core
Complete example
Section titled “Complete example”Plain source. Run as a browser module after the document body exists. TSX uses jsx: "react-jsx" and jsxImportSource: "@pibbl/core".
/** @jsxImportSource @pibbl/core */import { pibbl, createElement, Fragment, Text, type PibblComponent, type PibblElement, type PibblElementType, type PibblKey, type PibblNode, type PibblNodeInput, type PibblContainerChild, type PibblEmptyNode, type PibblTextChild, type PibblTextInput, type PibblRenderResult,} from "@pibbl/core";
const canvas = document.createElement("canvas");canvas.width = 320;canvas.height = 120;document.body.append(canvas);const Label: PibblComponent<{ value: string }> = ({ value }): PibblRenderResult => { const words: PibblTextChild = ["Hello ", value]; const text: PibblTextInput = words; return ( <Text style={{ left: 20, top: 50, font: "24px sans-serif", fill: "#267d7c" }} > {text} </Text> );};const component: PibblElementType<{ value: string }> = Label;const key: PibblKey = "greeting";const element: PibblElement<{ value: string }> = createElement(component, { value: "Pibbl", key,});const empty: PibblEmptyNode = null;const nodes: PibblNode = [element, empty];const input: PibblNodeInput = nodes;const children: PibblContainerChild = input;const controller = pibbl(canvas, <Fragment>{children}</Fragment>);window.addEventListener("pagehide", () => controller.dispose(), { once: true });Usage notes
Section titled “Usage notes”- Textual values belong inside Text; arbitrary strings are not general scene nodes. Components are synchronous and createElement is equivalent to automatic JSX.
Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.