allaw-ui 0.1.53 → 0.1.54
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.
|
@@ -12,7 +12,8 @@ export interface ComboBoxProps {
|
|
|
12
12
|
isRequired?: boolean;
|
|
13
13
|
showError?: boolean;
|
|
14
14
|
width?: number;
|
|
15
|
-
|
|
15
|
+
onSelect?: (selected: string) => void;
|
|
16
|
+
onInput?: (value: string) => void;
|
|
16
17
|
onError?: (error: string) => void;
|
|
17
18
|
openOnMount?: boolean;
|
|
18
19
|
title?: string;
|
|
@@ -5,7 +5,7 @@ import TinyInfo from "../typography/TinyInfo";
|
|
|
5
5
|
import Paragraph from "../typography/Paragraph";
|
|
6
6
|
import { createPortal } from "react-dom";
|
|
7
7
|
function ComboBox(_a, ref) {
|
|
8
|
-
var items = _a.items, selectedItem = _a.selectedItem, _b = _a.placeholder, placeholder = _b === void 0 ? "Sélectionner..." : _b, _c = _a.isRequired, isRequired = _c === void 0 ? false : _c, _d = _a.showError, showError = _d === void 0 ? false : _d, _e = _a.width, width = _e === void 0 ? 100 : _e,
|
|
8
|
+
var items = _a.items, selectedItem = _a.selectedItem, _b = _a.placeholder, placeholder = _b === void 0 ? "Sélectionner..." : _b, _c = _a.isRequired, isRequired = _c === void 0 ? false : _c, _d = _a.showError, showError = _d === void 0 ? false : _d, _e = _a.width, width = _e === void 0 ? 100 : _e, onSelect = _a.onSelect, onError = _a.onError, _f = _a.openOnMount, openOnMount = _f === void 0 ? true : _f, title = _a.title, onInput = _a.onInput;
|
|
9
9
|
var _g = useState(openOnMount), isOpen = _g[0], setIsOpen = _g[1];
|
|
10
10
|
var _h = useState(""), inputValue = _h[0], setInputValue = _h[1];
|
|
11
11
|
var _j = useState(items), filteredItems = _j[0], setFilteredItems = _j[1];
|
|
@@ -60,13 +60,13 @@ function ComboBox(_a, ref) {
|
|
|
60
60
|
var handleInputChange = function (event) {
|
|
61
61
|
var value = event.target.value;
|
|
62
62
|
setInputValue(value);
|
|
63
|
+
onInput === null || onInput === void 0 ? void 0 : onInput(value);
|
|
63
64
|
var filtered = items.filter(function (item) {
|
|
64
65
|
return item.label.toLowerCase().includes(value.toLowerCase());
|
|
65
66
|
});
|
|
66
67
|
setFilteredItems(filtered);
|
|
67
68
|
setIsInputValid(filtered.length > 0 || value === "");
|
|
68
69
|
setIsOpen(true);
|
|
69
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(value);
|
|
70
70
|
};
|
|
71
71
|
var handleInputFocus = function () {
|
|
72
72
|
setIsOpen(true);
|
|
@@ -77,7 +77,7 @@ function ComboBox(_a, ref) {
|
|
|
77
77
|
setSelectedIndex(index);
|
|
78
78
|
setFilteredItems(items);
|
|
79
79
|
setIsOpen(false);
|
|
80
|
-
|
|
80
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(item.value);
|
|
81
81
|
validateSelect(item.value);
|
|
82
82
|
};
|
|
83
83
|
var validateSelect = function (value) {
|