UserComponent
Type
A wrapper of React.ComponentType<Props>
. Accepts a static craft
property for configuring the User Component.
#
Reference#
Properties- React.ComponentType<T> &
craft
ObjectdisplayName
StringA user-friendly name for the User Component. The value here will be used to set the node.data.displayName property.props
TSpecify default values for the props Tcustom
Record<string, any>Specify default custom values for the User Componentrelated
Record<string, React.ElementType>A map of React Components to share the same Node context. This components will be able access the useNode hookrules?
canDrag
(currentNode: Node, helpers: NodeHelpers) => booleanSpecifies if the component can be dragged. Applicable only to components whose corresponding Node is a direct child of a CanvascanDrop
(targetNode: Node, currentNode, helpers: NodeHelpers) => booleanSpecifies if the current Node that is being dragged can be dropped in its target. Applicable only if the current Node is a direct child of a Canvas NodecanMoveIn
(incomingNode: Node, currentNode: Node, helpers: NodeHelpers) => booleanSpecifies if an incoming Node can be dropped into the current component. Applicable only to components whose corresponding Node is a CanvascanMoveOut
(outgoingNode: Node, currentNode: Node, helpers: NodeHelpers) => booleanSpecifies if a child Node can be dragged out of the current component. Applicable only to components whose corresponding Node is a Canvas
#
Exampletype TextProps = { color: string; text: string;};
const TextComponent: UserComponent<TextProps> = ({color, text}) => { return ( <h2 style={{color}}>{text}</h2> )}
const TextSettings = () => { const {props, setProp} = useNode(); return ( <div> Text: <input type="text" value={props.text} onChange={e => setProp(props => props.text = e.target.value) }/> Color: <input type="text" value={props.color} onChange={e => setProp(props => props.color = e.target.value) }/> </div> )}TextComponent.craft = { displayName: "My Text Component", props: { color: "#000", text: "Hi" }, rules: { canDrag: (self: Node, helper) => true, canMoveIn: (incoming: Node, self: Node, helper) => true, canMoveOut: (outgoing: Node, self: Node, helper) => true }, related: { settings: TextSettings }}