forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdropdown.tsx
More file actions
110 lines (102 loc) · 2.76 KB
/
dropdown.tsx
File metadata and controls
110 lines (102 loc) · 2.76 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import Tippy, { TippyProps } from "@tippyjs/react";
import { isValidElement, ReactElement, ReactNode, useState } from "react";
import Tooltip from "./tooltip.tsx";
/**
* A customized (and customizable) implementation of Tippy dropdowns
*/
export default function Dropdown({
items,
tooltip = "More actions",
disabled,
className,
icon,
}: DropdownProps) {
const [visible, setVisible] = useState(false);
const show = () => setVisible(true);
const hide = () => setVisible(false);
return (
<Tooltip content={tooltip}>
<Tippy
visible={visible}
onClickOutside={hide}
{...DefaultDropdownProps}
content={
<div className="jenkins-dropdown">
{items.map((item, index) => {
if (item === "separator") {
return (
<div
key={`separator-${index}`}
className="jenkins-dropdown__separator"
/>
);
}
if (isValidElement(item)) {
return (
<div key={index} className="jenkins-dropdown__custom-item">
{item}
</div>
);
}
const dropdownItem = item as DropdownItem;
return (
<a
key={index}
className="jenkins-dropdown__item"
href={dropdownItem.href}
target={dropdownItem.target}
download={dropdownItem.download}
>
<div className="jenkins-dropdown__item__icon">
{dropdownItem.icon}
</div>
{dropdownItem.text}
</a>
);
})}
</div>
}
>
<button
className={"jenkins-button " + className}
type="button"
disabled={disabled}
onClick={visible ? hide : show}
>
<span className={"jenkins-visually-hidden"}>{tooltip}</span>
{icon || (
<div className="jenkins-overflow-button__ellipsis">
<span />
<span />
<span />
</div>
)}
</button>
</Tippy>
</Tooltip>
);
}
export const DefaultDropdownProps: TippyProps = {
theme: "dropdown",
duration: 250,
touch: true,
animation: "dropdown",
interactive: true,
offset: [0, 0],
placement: "bottom-start",
arrow: false,
};
interface DropdownProps {
items: (DropdownItem | ReactElement | "separator")[];
tooltip?: string;
disabled?: boolean;
className?: string;
icon?: ReactNode;
}
interface DropdownItem {
text: string;
href?: string;
icon: ReactNode;
target?: string;
download?: string;
}