@gisce/react-ooui 2.0.0-alpha.28 → 2.0.0-alpha.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "2.0.0-alpha.28",
3
+ "version": "2.0.0-alpha.29",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
@@ -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,10 +22,24 @@ function DropdownButton(props: Props) {
19
22
  onItemClick,
20
23
  label,
21
24
  disabled = false,
25
+ searchable = "auto",
22
26
  } = props;
27
+ const [filteredItems, setFilteredItems] = useState([...items]);
28
+
29
+ const onSearch = (value: string) => {
30
+ if (!value) {
31
+ setFilteredItems([...items]);
32
+ } else {
33
+ setFilteredItems(
34
+ items.filter(
35
+ (item) => item.name.toLowerCase().indexOf(value.toLowerCase()) !== -1,
36
+ ),
37
+ );
38
+ }
39
+ };
23
40
 
24
41
  function getMenu() {
25
- const menuItems = items?.map((item, idx) => {
42
+ const menuItems = filteredItems?.map((item, idx) => {
26
43
  if (item.name === "divider") {
27
44
  return <Menu.Divider key={"divider" + idx} />;
28
45
  }
@@ -31,6 +48,14 @@ function DropdownButton(props: Props) {
31
48
 
32
49
  return (
33
50
  <Menu onClick={handleMenuClick}>
51
+ {((searchable === "auto" && items.length > 3) ||
52
+ searchable === true) && (
53
+ <Search
54
+ onChange={(e) => onSearch(e.target.value)}
55
+ onSearch={onSearch}
56
+ allowClear
57
+ />
58
+ )}
34
59
  <Menu.ItemGroup title={tooltip}>{menuItems}</Menu.ItemGroup>
35
60
  </Menu>
36
61
  );