How to add a new component in the visual editor? #169
Replies: 7 comments
-
To add a new component, follow these steps:
You might see a piece of code that looks like this:
Here, we are specifying the name of icon that will show on the component manager side bar. |
Beta Was this translation helpful? Give feedback.
-
In the code for Button component here export const Button = forwardRef<
HTMLButtonElement,
{
styles: React.CSSProperties;
custom: { text: string };
onClick: (event: { pageX: number; pageY: number }) => void;
className: string;
}
>((props, ref) => {
const onClick = useCallback(
(e: React.MouseEvent) => {
props.onClick({ pageX: e.pageX, pageY: e.pageY });
},
[props]
);
return (
<button ref={ref} style={props.styles} onClick={onClick} className={props.className}>
{props.custom.text}
</button>
);
});
You might see a piece of code that looks like this: const cssTreeOptions: CSSTreeOptions = {
flexContainerOptions: false,
flexChildOptions: true,
positionOptions: true,
typographyOptions: true,
spacingOptions: true,
sizeOptions: true,
borderOptions: true,
outlineOptions: true,
backgroundOptions: true,
miscellaneousOptions: true,
}; Here, we are specifying what kind of CSS properties are applicable to the component you are trying to create. |
Beta Was this translation helpful? Give feedback.
-
You might see a piece of code that describes what are the custom fields that this component can take: const customTreeOptions: CustomPropsTreeOptions = {
dataTypes: {
text: "text",
},
}; Here, we are specifying that a custom prop called Please refer #184 for detailed discussion on custom props. |
Beta Was this translation helpful? Give feedback.
-
Each component's behavior inside the editor and in the generated app is described using a manifest. For button component, you will see a manifest like this const compManifest: ReactComponentManifestSchema = {
meta: { key: "Button", category: "Basics" },
render: {
comp: Button,
},
dev: {
decorators: [],
attachProps: {
styles: {
treeId: CSSTreeId,
initialValue: {
color: "#fff",
backgroundColor: "#1890ff",
},
treeOptions: cssTreeOptions,
canvasOptions: { groupByBreakpoint: true },
},
custom: {
treeId: CustomTreeId,
initialValue: {
text: "Submit",
},
treeOptions: customTreeOptions,
canvasOptions: { groupByBreakpoint: false },
},
},
attachCallbacks: {
onClick: [{ type: "do_nothing" }],
},
defaultCallbackHandlers: {
onClick: [{ sendEventData: true }],
},
},
}; The The description for other fields are in the comments below. |
Beta Was this translation helpful? Give feedback.
-
Please refer discussion #186 for more details on this. |
Beta Was this translation helpful? Give feedback.
-
In some components, like any chart component, you might find two React Components defined. One react component maybe named as The reason behind this design of having two different components is that we want to keep the components that becomes part of the generater app as light as possible. |
Beta Was this translation helpful? Give feedback.
-
Video tutorial on how to add a new component: https://www.youtube.com/watch?v=h3FNiiPZqpo&t=1s |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions