@gisce/react-ooui 1.5.6 → 1.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actionbar/DropdownButton.d.ts +1 -0
- package/dist/actionbar/DropdownButton.d.ts.map +1 -1
- package/dist/react-ooui.es.js +213 -189
- package/dist/react-ooui.es.js.map +1 -1
- package/dist/react-ooui.umd.js +5 -5
- package/dist/react-ooui.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/actionbar/DropdownButton.tsx +44 -3
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Menu, Dropdown, Button } from "antd";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Menu, Dropdown, Button, Input } from "antd";
|
|
3
3
|
import { DownOutlined } from "@ant-design/icons";
|
|
4
4
|
|
|
5
|
+
const { Search } = Input;
|
|
6
|
+
|
|
5
7
|
type Props = {
|
|
6
8
|
onItemClick: (event: any) => void;
|
|
7
9
|
items: any[];
|
|
@@ -9,6 +11,7 @@ type Props = {
|
|
|
9
11
|
icon: any;
|
|
10
12
|
label?: string;
|
|
11
13
|
disabled?: boolean;
|
|
14
|
+
searchable?: true | false | "auto";
|
|
12
15
|
};
|
|
13
16
|
|
|
14
17
|
function DropdownButton(props: Props) {
|
|
@@ -19,18 +22,56 @@ function DropdownButton(props: Props) {
|
|
|
19
22
|
onItemClick,
|
|
20
23
|
label,
|
|
21
24
|
disabled = false,
|
|
25
|
+
searchable = "auto",
|
|
22
26
|
} = props;
|
|
27
|
+
const [searchValue, setSearchValue] = useState<string>();
|
|
28
|
+
|
|
29
|
+
const onSearch = (value?: string) => {
|
|
30
|
+
if (!value) {
|
|
31
|
+
setSearchValue(undefined);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const sanitizedValue = value.trim();
|
|
36
|
+
|
|
37
|
+
if (sanitizedValue.length === 0) {
|
|
38
|
+
setSearchValue(undefined);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setSearchValue(sanitizedValue);
|
|
43
|
+
};
|
|
23
44
|
|
|
24
45
|
function getMenu() {
|
|
25
|
-
|
|
46
|
+
let itemsData = [];
|
|
47
|
+
if (searchValue) {
|
|
48
|
+
itemsData = items.filter((item) => {
|
|
49
|
+
return item.name.toLowerCase().includes(searchValue.toLowerCase());
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
itemsData = items;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const menuItems = itemsData.map((item, idx) => {
|
|
26
56
|
if (item.name === "divider") {
|
|
27
57
|
return <Menu.Divider key={"divider" + idx} />;
|
|
28
58
|
}
|
|
29
59
|
return <Menu.Item key={item.id}>{item.name}</Menu.Item>;
|
|
30
60
|
});
|
|
31
61
|
|
|
62
|
+
const mustShowSearch =
|
|
63
|
+
searchable === true || (searchable === "auto" && items.length > 3);
|
|
64
|
+
|
|
32
65
|
return (
|
|
33
66
|
<Menu onClick={handleMenuClick}>
|
|
67
|
+
{mustShowSearch && (
|
|
68
|
+
<Search
|
|
69
|
+
onChange={(e: any) => onSearch(e.target.value)}
|
|
70
|
+
onSearch={onSearch}
|
|
71
|
+
allowClear
|
|
72
|
+
style={{ padding: 5 }}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
34
75
|
<Menu.ItemGroup title={tooltip}>{menuItems}</Menu.ItemGroup>
|
|
35
76
|
</Menu>
|
|
36
77
|
);
|