@playcanvas/react
Version:
A React renderer for PlayCanvas – build interactive 3D applications using React's declarative paradigm.
33 lines • 1.41 kB
JavaScript
"use client";
import { useComponent } from "../hooks/index.js";
import { Entity } from "playcanvas";
import { validatePropsWithDefaults, createComponentDefinition, getStaticNullApplication } from "../utils/validation.js";
/**
* The Screen component allows an entity to render a 2D screen space UI element.
* This is useful for creating UI elements that are rendered in screen space rather than world space.
*
* @param {ElementProps} props - The props to pass to the screen component.
* @see https://api.playcanvas.com/engine/classes/ElementComponent.html
*
* @example
* <Entity>
* <Screen screenSpace={true} />
* <Element>Hey</Element>
* </Screen>
* </Entity>
*/
export const Element = (props) => {
const safeProps = validatePropsWithDefaults(props, componentDefinition);
useComponent("element", safeProps, componentDefinition.schema);
return null;
};
const componentDefinition = createComponentDefinition("Element", () => new Entity("mock-element", getStaticNullApplication()).addComponent("element"), (component) => component.system.destroy(), "ElementComponent");
componentDefinition.schema = {
...componentDefinition.schema,
children: {
validate: (value) => typeof value === "string",
errorMsg: (value) => `Invalid value for prop "children": ${value}. Expected a string.`,
default: "Invalid children"
}
};
//# sourceMappingURL=Element.js.map