-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCustomDropdown.tsx
81 lines (76 loc) · 1.91 KB
/
CustomDropdown.tsx
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
75
76
77
78
79
80
81
import React, { useState } from 'react';
import { theme } from 'flipper-plugin';
import { DropdownPropertyType, MenuItem } from '../CommonTypes';
const listItem = (menuItem: MenuItem) => {
const [hover, setHover] = useState(false);
const handleMouseEnter = () => {
setHover(true);
};
const handleMouseLeave = () => {
setHover(false);
};
return (
<li
onClick={menuItem.onClick}
key={menuItem.key}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
style={{
clear: 'both',
color: 'rgba(0, 0, 0, 0.65)',
cursor: 'pointer',
fontSize: '14px',
fontWeight: 'normal',
lineHeight: '22px',
margin: 0,
padding: '5px 12px',
whiteSpace: 'nowrap',
backgroundColor: hover ? theme.primaryColor : 'white',
zIndex: 99,
}}
>
{' '}
<div style={{ color: hover ? 'white' : 'black' }}>{menuItem.text}</div>
</li>
);
};
export const CustomDropdown = ({
generateMenuItems,
record,
schemaProperty,
currentSchema,
visible,
pointerX,
pointerY,
scrollX,
scrollY,
}: DropdownPropertyType) => {
if (visible && schemaProperty && record) {
const menuItems = generateMenuItems(record, schemaProperty, currentSchema);
return (
<ul
className="popup"
style={{
left: `${pointerX + scrollX}px`,
top: `${pointerY + scrollY}px`,
position: 'absolute',
backgroundClip: 'padding-box',
backgroundColor: '#fff',
borderRadius: '4px',
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
listStyleType: 'none',
margin: 0,
outline: 'none',
padding: 0,
textAlign: 'left',
overflow: 'hidden',
zIndex: '10',
}}
>
{menuItems.map((menuItem) => listItem(menuItem))}
</ul>
);
} else {
return <></>;
}
};