@tecsinapse/cortex-react 2.2.0-beta.3 → 2.2.0-beta.4

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.
@@ -6,21 +6,8 @@ var index = require('../Popover/index.js');
6
6
  var index$1 = require('../Input/index.js');
7
7
  var react = require('@floating-ui/react');
8
8
 
9
- const selectOptions = [
10
- { label: "Brasil", value: "brasil" },
11
- { label: "Alemanha", value: "alemanha" },
12
- { label: "Jap\xE3o", value: "japao" },
13
- { label: "Canad\xE1", value: "canada" },
14
- { label: "Austr\xE1lia", value: "australia" },
15
- { label: "Fran\xE7a", value: "franca" },
16
- { label: "It\xE1lia", value: "italia" },
17
- { label: "M\xE9xico", value: "mexico" },
18
- { label: "Portugal", value: "portugal" },
19
- { label: "Argentina", value: "argentina" }
20
- ];
21
9
  const Autocomplete = ({
22
10
  inputValue,
23
- setInputValue,
24
11
  label,
25
12
  onChange,
26
13
  onSelect,
@@ -28,24 +15,16 @@ const Autocomplete = ({
28
15
  options
29
16
  }) => {
30
17
  const [triggerWidth, setTriggerWidth] = React.useState();
31
- const [selectedValue, setSelectedValue] = React.useState({
32
- label: "",
33
- value: ""
34
- });
35
18
  const [open, setOpen] = React.useState(true);
36
19
  const filteredOptions = React.useMemo(() => {
37
- const optionsList = (selectOptions ?? []).filter(
20
+ const optionsList = (options ?? []).filter(
38
21
  (op) => op.label.toLowerCase().includes(inputValue.toLowerCase())
39
22
  );
40
23
  return optionsList;
41
- }, [selectOptions, inputValue]);
24
+ }, [options, inputValue]);
42
25
  const handleSelect = (option) => {
43
- if (!(selectedValue.value === option.value)) {
44
- setSelectedValue(option);
45
- }
46
- setInputValue("");
47
26
  setOpen(false);
48
- onSelect(option);
27
+ onSelect?.(option);
49
28
  };
50
29
  const handleChange = (event) => {
51
30
  onChange(event);
@@ -88,12 +67,12 @@ const Autocomplete = ({
88
67
  width: triggerWidth ? `${triggerWidth}px` : "auto"
89
68
  },
90
69
  initialFocus: -1,
91
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex flex-col overflow-y-auto", children: (options ?? filteredOptions ?? []).map((op) => /* @__PURE__ */ jsxRuntime.jsx(
70
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex flex-col overflow-y-auto", children: (options ?? filteredOptions ?? []).map((option) => /* @__PURE__ */ jsxRuntime.jsx(
92
71
  "div",
93
72
  {
94
73
  className: "flex w-full h-[3rem] items-center gap-centi p-centi cursor-pointer hover:bg-secondary-xlight bg-inherit",
95
- onClick: () => handleSelect(op),
96
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-base truncate", children: op.label })
74
+ onClick: () => handleSelect(option),
75
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-base truncate", children: option.label })
97
76
  }
98
77
  )) })
99
78
  }
@@ -4,21 +4,8 @@ import { Popover } from '../Popover/index.js';
4
4
  import { Input } from '../Input/index.js';
5
5
  import { FloatingPortal } from '@floating-ui/react';
6
6
 
7
- const selectOptions = [
8
- { label: "Brasil", value: "brasil" },
9
- { label: "Alemanha", value: "alemanha" },
10
- { label: "Jap\xE3o", value: "japao" },
11
- { label: "Canad\xE1", value: "canada" },
12
- { label: "Austr\xE1lia", value: "australia" },
13
- { label: "Fran\xE7a", value: "franca" },
14
- { label: "It\xE1lia", value: "italia" },
15
- { label: "M\xE9xico", value: "mexico" },
16
- { label: "Portugal", value: "portugal" },
17
- { label: "Argentina", value: "argentina" }
18
- ];
19
7
  const Autocomplete = ({
20
8
  inputValue,
21
- setInputValue,
22
9
  label,
23
10
  onChange,
24
11
  onSelect,
@@ -26,24 +13,16 @@ const Autocomplete = ({
26
13
  options
27
14
  }) => {
28
15
  const [triggerWidth, setTriggerWidth] = useState();
29
- const [selectedValue, setSelectedValue] = useState({
30
- label: "",
31
- value: ""
32
- });
33
16
  const [open, setOpen] = useState(true);
34
17
  const filteredOptions = useMemo(() => {
35
- const optionsList = (selectOptions ?? []).filter(
18
+ const optionsList = (options ?? []).filter(
36
19
  (op) => op.label.toLowerCase().includes(inputValue.toLowerCase())
37
20
  );
38
21
  return optionsList;
39
- }, [selectOptions, inputValue]);
22
+ }, [options, inputValue]);
40
23
  const handleSelect = (option) => {
41
- if (!(selectedValue.value === option.value)) {
42
- setSelectedValue(option);
43
- }
44
- setInputValue("");
45
24
  setOpen(false);
46
- onSelect(option);
25
+ onSelect?.(option);
47
26
  };
48
27
  const handleChange = (event) => {
49
28
  onChange(event);
@@ -86,12 +65,12 @@ const Autocomplete = ({
86
65
  width: triggerWidth ? `${triggerWidth}px` : "auto"
87
66
  },
88
67
  initialFocus: -1,
89
- children: /* @__PURE__ */ jsx("div", { className: "w-full flex flex-col overflow-y-auto", children: (options ?? filteredOptions ?? []).map((op) => /* @__PURE__ */ jsx(
68
+ children: /* @__PURE__ */ jsx("div", { className: "w-full flex flex-col overflow-y-auto", children: (options ?? filteredOptions ?? []).map((option) => /* @__PURE__ */ jsx(
90
69
  "div",
91
70
  {
92
71
  className: "flex w-full h-[3rem] items-center gap-centi p-centi cursor-pointer hover:bg-secondary-xlight bg-inherit",
93
- onClick: () => handleSelect(op),
94
- children: /* @__PURE__ */ jsx("span", { className: "text-base truncate", children: op.label })
72
+ onClick: () => handleSelect(option),
73
+ children: /* @__PURE__ */ jsx("span", { className: "text-base truncate", children: option.label })
95
74
  }
96
75
  )) })
97
76
  }
@@ -3,15 +3,15 @@ interface AutocompleteProps {
3
3
  inputValue: string;
4
4
  setInputValue: React.Dispatch<React.SetStateAction<string>>;
5
5
  onChange: ChangeEventHandler<HTMLInputElement>;
6
- onSelect: (option: Option) => void;
6
+ options: Option[];
7
+ onSelect?: (option: Option) => void;
7
8
  label?: string;
8
9
  placeholder?: string;
9
10
  disabled?: boolean;
10
- options: Option[];
11
11
  }
12
12
  interface Option {
13
13
  label: string;
14
14
  value: string;
15
15
  }
16
- export declare const Autocomplete: ({ inputValue, setInputValue, label, onChange, onSelect, disabled, options, }: AutocompleteProps) => import("react/jsx-runtime").JSX.Element;
16
+ export declare const Autocomplete: ({ inputValue, label, onChange, onSelect, disabled, options, }: AutocompleteProps) => import("react/jsx-runtime").JSX.Element;
17
17
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tecsinapse/cortex-react",
3
- "version": "2.2.0-beta.3",
3
+ "version": "2.2.0-beta.4",
4
4
  "description": "React components based in @tecsinapse/cortex-core",
5
5
  "license": "MIT",
6
6
  "main": "dist/esm/index.js",
@@ -48,5 +48,5 @@
48
48
  "react-icons": ">=5.2.0",
49
49
  "tailwindcss": "^4.1.16"
50
50
  },
51
- "gitHead": "a8768e0f4e02c8b8c0494f0741284d21c2eb0e4b"
51
+ "gitHead": "69afce08c648a4bd087d25e7009b9a4182f66083"
52
52
  }