Skip to main content

Tree Form

"tree + from" combined high-level component, suitable for dynamic and complex form submission functionality.

show code
import { TreeForm } from "mui-eazy";
import { useMemo } from "react";
import useTreeConfig from "./treeConfig";
import "mui-eazy/dist/style.css";
// ----------------------------------------------------------------------
export type EventType = "Create" | "Draft" | "Update" | "Submit" | "Publish";

const transferInput = (value: any) => {
let newValue = {};
// ...
// transfer logic
// ...
return newValue;
};

const transferResult = (result: any) => {
let newValue = {};
// ...
// transfer logic
// ...
return newValue;
};
export default function ProductEditView() {
const treeFromConfig = useTreeConfig();
// handler
const handleClick = async ({
type,
isSuccess,
result,
}: {
type: EventType;
isSuccess: boolean;
result: any;
}) => {
if (!isSuccess) return;
switch (type) {
case "Draft":
// ...
// handler logic
// ...
break;
default:
break;
}
};
const actionBtnArr = useMemo<
{
name: EventType;
}[]
>(() => {
return [
{
name: "Update",
},
{
name: "Submit",
},
];
}, []);
return (
<TreeForm
handleClick={handleClick}
treeConfig={treeFromConfig}
actionBtnArr={actionBtnArr}
value={null}
transferInput={transferInput}
transferResult={transferResult}
/>
);
}

Props

tip
  • Type: any, can be customized as needed.
  • Default value:
    • Not specified: optional.
    • Specified as "require": mandatory.
  • Type link: Click to navigate to the details below.
OptionTypeDefaultDescription
treeConfigTreeConfigrequiredDriving the display of data for tree+form.
handleClickHandleClickrequiredclick event handler
actionBtnArrActionBtnArrrequiredWhether to sync the selected converter across all code blocks.
valueanynullThe value to be edited. Note that you should pass null or not pass it when creating, and pass it when editing.
transferInput(value)=>valueTranslate the target data. into form results.
transferResult(value)=>valueTranslate the form results into target data.

Type

TreeConfig

export interface TreeItemProps {
isError?: boolean;
formConfig?: FormConfig | null;
formCreater?: () => TreeItemProps | null;
id?: string;
parentId?: string;
uuid?: string;
active: boolean;
isCurrent?: boolean;
depth: number;
label: string;
name?: string;
sx?: SxProps<Theme>;
isAdd?: boolean;
type?: "array" | "object";
onAdd?: (listArr: TreeItemProps[]) => void;
onDelete?: (id: string, listArr: TreeItemProps[]) => void;
children?: React.ReactNode | undefined;
sections?: TreeItemProps[];
judeShow?: () => boolean;
}

HandleClick

  ({ type, isSuccess, result, }: {
type: any;
isSuccess: boolean;
result: any;
}) => void

ActionBtnArr

{
name: string;
}
[];