registerEditorItem
Registers a custom React component under a string name so the editor's items array can reference it via comp. With { readonly: true }, registers the component that renders that comp type when the editor is read-only. Call once at module scope.
The kanban editor pre-registers richselect, multicombo, datepicker, and slider. @svar-ui/react-editor exports Attachments, CodeMirror, and TinyMCE field components that aren't pre-registered and are typical candidates for registration.
Usage
import { registerEditorItem } from "@svar-ui/react-kanban";
import type { ComponentType } from "react";
registerEditorItem(
type: string,
handler: ComponentType<any>,
config?: { readonly?: boolean } | null
): void;
| Parameter | Type | Description |
|---|---|---|
type | string | Identifier used as comp in editor item descriptors |
handler | ComponentType<any> | React component receiving value, onChange, and promoted config fields |
config | { readonly?: boolean } | null | Optional. { readonly: true } registers handler as the read-only renderer for type |
When the editor is read-only, each item renders with the read-only handler registered for its comp. Without one, the editor falls back to its built-in read-only renderer.
The component must call onChange({ value }) on change. Fields in the item's config object are promoted to top-level props.
Example
Registering a custom comments component:
import { useState } from "react";
import { Kanban, Editor, registerEditorItem } from "@svar-ui/react-kanban";
import Comments from "./Comments.jsx";
registerEditorItem("comments", Comments);
const items = [
{ comp: "text", key: "label", label: "Label" },
{ comp: "textarea", key: "description", label: "Description" },
{ comp: "comments", key: "comments", label: "Comments" },
];
function App() {
const [api, setApi] = useState(null);
return (
<>
<Kanban init={setApi} cards={cards} columns={columns} />
{api && <Editor api={api} items={items} />}
</>
);
}
Registering a bundled component from @svar-ui/react-editor:
import { registerEditorItem } from "@svar-ui/react-kanban";
import { Attachments } from "@svar-ui/react-editor";
registerEditorItem("files", Attachments);
const items = [
{ comp: "text", key: "label", label: "Label" },
{ comp: "files", key: "attachments", label: "Attachments", uploadURL: "/api/files" },
];
Registering a read-only renderer for a custom type:
import { registerEditorItem } from "@svar-ui/react-kanban";
import Comments from "./Comments.jsx";
import CommentsView from "./CommentsView.jsx";
registerEditorItem("comments", Comments);
registerEditorItem("comments", CommentsView, { readonly: true });
Registering multiple components:
import { registerEditorItem } from "@svar-ui/react-kanban";
import Comments from "./Comments.jsx";
import Tasklist from "./Tasklist.jsx";
registerEditorItem("comments", Comments);
registerEditorItem("tasks", Tasklist);
const items = [
{ comp: "text", key: "label", label: "Label" },
{ comp: "comments", key: "comments", label: "Comments" },
{ comp: "tasks", key: "tasks", label: "Checklist" },
];
Related
- Editing guide - comments, checklists, and custom field components
- Editor - the component that renders registered items
- getEditorItems - default editor field set