registerEditorItem
Description
Registers a custom UI component for use as a field in the EditorIt registers a custom React component to be used as an editor field (comp). The registered component must support the value property and onChange callback as in Editor.
Usage
registerEditorItem?: (
type: string,
handler: React.ComponentType<any>
) => void;
Parameters
type- (required) a unique identifier for the editor controlcontrol- a React component that implementsvalueproperty andonChangecallback as in Editor.
Example
The example shows how to add a custom editor field using the radio button component:
import { useState } from "react";
import { Gantt, Editor, defaultEditorItems, registerEditorItem } from "@svar-ui/react-gantt";
import { RadioButtonGroup } from "@svar-ui/react-core";
registerEditorItem("radio", RadioButtonGroup);
const items = [
...defaultEditorItems,
{
key: "type",
comp: "radio",
label: "Type",
options, // options for radio
type: "inline",
},
];
export default function Example() {
const [api, setApi] = useState(null);
return (
<>
<Gantt init={setApi} />
{api && <Editor api={api} items={items} />}
</>
);
}
Related articles: