({ id, name, children, onFinish }: CommonComponentProps)
| 5 | import { useDrag } from 'react-dnd'; |
| 6 | |
| 7 | function 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 | |
| 56 | export default Form; |
nothing calls this directly
no test coverage detected