MCPcopy Create free account
hub / github.com/QuarkGluonPlasma/react-course-code / Form

Function Form

lowcode-editor/src/editor/materials/Form/dev.tsx:7–54  ·  view source on GitHub ↗
({ id, name, children, onFinish }: CommonComponentProps)

Source from the content-addressed store, hash-verified

5import { useDrag } from 'react-dnd';
6
7function Form({ id, name, children, onFinish }: CommonComponentProps) {
8 const [form] = AntdForm.useForm();
9
10 const {canDrop, drop } = useMaterailDrop(['FormItem'], id);
11
12 const divRef = useRef<HTMLDivElement>(null);
13
14 const [_, drag] = useDrag({
15 type: name,
16 item: {
17 type: name,
18 dragType: 'move',
19 id: id
20 }
21 });
22
23 useEffect(() => {
24 drop(divRef);
25 drag(divRef);
26 }, []);
27
28 const formItems = useMemo(() => {
29 return React.Children.map(children, (item: any) => {
30 return {
31 label: item.props?.label,
32 name: item.props?.name,
33 type: item.props?.type,
34 id: item.props?.id,
35 }
36 });
37 }, [children]);
38
39 return <div
40 className={`w-[100%] p-[20px] min-h-[100px] ${canDrop ? 'border-[2px] border-[blue]' : 'border-[1px] border-[#000]'}`}
41 ref={divRef}
42 data-component-id={id}
43 >
44 <AntdForm labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} form={form} onFinish={(values) =>{
45 onFinish && onFinish(values)
46 }}>
47 {formItems.map((item: any) => {
48 return <AntdForm.Item key={item.name} data-component-id={item.id} name={item.name} label={item.label} >
49 <Input style={{pointerEvents: 'none'}}/>
50 </AntdForm.Item>
51 })}
52 </AntdForm>
53 </div>
54}
55
56export default Form;

Callers

nothing calls this directly

Calls 4

useMaterailDropFunction · 0.90
useEffectFunction · 0.90
dropFunction · 0.50
onFinishFunction · 0.50

Tested by

no test coverage detected