-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathdragWrapper.tsx
More file actions
74 lines (63 loc) · 2.28 KB
/
dragWrapper.tsx
File metadata and controls
74 lines (63 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { FC, PropsWithChildren, useMemo, useState } from 'react';
import { ShaForm } from '@/providers/form';
import { Tooltip } from 'antd';
import { useFormDesigner, useFormDesignerSelectedComponentId, useFormDesignerIsDebug } from '@/providers/formDesigner';
import { FunctionOutlined } from '@ant-design/icons';
import { useStyles } from '../styles/styles';
interface IDragWrapperProps {
componentId: string;
readOnly?: boolean;
}
export const DragWrapper: FC<PropsWithChildren<IDragWrapperProps>> = (props) => {
const { styles } = useStyles();
const selectedComponentId = useFormDesignerSelectedComponentId();
const isDebug = useFormDesignerIsDebug();
const { setSelectedComponent } = useFormDesigner();
const [isOpen, setIsOpen] = useState(false);
const componentModel = ShaForm.useComponentModel(props.componentId);
const tooltip = useMemo(() => (
<div>
{isDebug && (
<div>
<strong>Id:</strong> {componentModel.id}
</div>
)}
<div>
<strong>Type:</strong> {componentModel.type}
</div>
{Boolean(componentModel.propertyName) && (
<div>
<strong>Property name: </strong>
{typeof (componentModel.propertyName) === 'string' ? componentModel.propertyName : ''}
{typeof (componentModel.propertyName) === 'object' && <FunctionOutlined />}
</div>
)}
{Boolean(componentModel.componentName) && (
<div><strong>Component name: </strong>{componentModel.componentName}</div>
)}
</div>
), [componentModel]);
const onClick = (event: React.MouseEvent<HTMLElement>): void => {
event.stopPropagation();
if (selectedComponentId !== props.componentId)
setSelectedComponent(
props.componentId,
);
};
const onMouseOver = (event: React.MouseEvent<HTMLElement>): void => {
event.stopPropagation();
setIsOpen(true);
};
const onMouseOut = (event: React.MouseEvent<HTMLElement>): void => {
event.stopPropagation();
setIsOpen(false);
};
return (
<div className={styles.componentDragHandle} onClick={onClick} onMouseOver={onMouseOver} onMouseOut={onMouseOut}>
<Tooltip title={tooltip} placement="right" open={isOpen}>
{props.children}
</Tooltip>
</div>
);
};
export default DragWrapper;