albinasoft-ui-package 1.0.63 → 1.0.64
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/assets/css/custom-autocomplete-input.css +8 -0
- package/dist/components/CustomAutocompleteInput.d.ts +1 -1
- package/dist/components/CustomAutocompleteInput.js +40 -24
- package/dist/components/CustomForm.d.ts +1 -1
- package/dist/components/CustomInput.d.ts +1 -0
- package/dist/components/CustomInput.js +3 -3
- package/package.json +1 -1
@@ -16,7 +16,7 @@ interface CustomAutocompleteInputProps {
|
|
16
16
|
className?: string;
|
17
17
|
style?: React.CSSProperties;
|
18
18
|
lang?: string;
|
19
|
-
fetchOptions: (query: string) => string[]
|
19
|
+
fetchOptions: (query: string) => Promise<string[]>;
|
20
20
|
onSelect: (value: string) => void;
|
21
21
|
}
|
22
22
|
declare const CustomAutocompleteInput: React.FC<CustomAutocompleteInputProps>;
|
@@ -67,11 +67,11 @@ var CustomInput_1 = __importStar(require("./CustomInput"));
|
|
67
67
|
var CustomAutocompleteInput = function (_a) {
|
68
68
|
var id = _a.id, name = _a.name, label = _a.label, value = _a.value, placeholder = _a.placeholder, _b = _a.required, required = _b === void 0 ? false : _b, description = _a.description, errorMessage = _a.errorMessage, conditionalErrorVisible = _a.conditionalErrorVisible, conditionalErrorMessage = _a.conditionalErrorMessage, _c = _a.disabled, disabled = _c === void 0 ? false : _c, tooltip = _a.tooltip, _d = _a.className, className = _d === void 0 ? '' : _d, style = _a.style, _e = _a.lang, lang = _e === void 0 ? 'tr-TR' : _e, fetchOptions = _a.fetchOptions, onSelect = _a.onSelect;
|
69
69
|
var _f = (0, react_1.useState)(value || ''), inputValue = _f[0], setInputValue = _f[1];
|
70
|
-
var _g = (0, react_1.useState)(
|
71
|
-
var _h = (0, react_1.useState)(
|
72
|
-
var _j = (0, react_1.useState)(
|
70
|
+
var _g = (0, react_1.useState)([]), options = _g[0], setOptions = _g[1];
|
71
|
+
var _h = (0, react_1.useState)(false), isDropdownVisible = _h[0], setIsDropdownVisible = _h[1];
|
72
|
+
var _j = (0, react_1.useState)(-1), highlightedIndex = _j[0], setHighlightedIndex = _j[1];
|
73
73
|
var dropdownRef = (0, react_1.useRef)(null);
|
74
|
-
// Input
|
74
|
+
// Input değeri değişince fetchOptions ile seçenekleri getiriyoruz.
|
75
75
|
var handleInputChange = function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
76
76
|
var value, fetchedOptions, error_1;
|
77
77
|
return __generator(this, function (_a) {
|
@@ -79,7 +79,6 @@ var CustomAutocompleteInput = function (_a) {
|
|
79
79
|
case 0:
|
80
80
|
value = e.target.value;
|
81
81
|
setInputValue(value);
|
82
|
-
setSelectedValue(null);
|
83
82
|
if (!value) return [3 /*break*/, 5];
|
84
83
|
_a.label = 1;
|
85
84
|
case 1:
|
@@ -89,6 +88,7 @@ var CustomAutocompleteInput = function (_a) {
|
|
89
88
|
fetchedOptions = _a.sent();
|
90
89
|
setOptions(fetchedOptions);
|
91
90
|
setIsDropdownVisible(fetchedOptions.length > 0);
|
91
|
+
setHighlightedIndex(-1); // Her aramada highlight'ı resetliyoruz.
|
92
92
|
return [3 /*break*/, 4];
|
93
93
|
case 3:
|
94
94
|
error_1 = _a.sent();
|
@@ -105,30 +105,46 @@ var CustomAutocompleteInput = function (_a) {
|
|
105
105
|
}
|
106
106
|
});
|
107
107
|
}); };
|
108
|
-
//
|
108
|
+
// Bir seçenek tıklandığında
|
109
109
|
var handleOptionClick = function (option) {
|
110
|
-
setSelectedValue(option);
|
111
110
|
onSelect(option);
|
112
|
-
//setIsDropdownVisible(false);
|
113
|
-
//setInputValue(option);
|
114
111
|
};
|
115
112
|
var handleReset = function () {
|
116
113
|
setIsDropdownVisible(false);
|
117
114
|
setInputValue('');
|
118
|
-
setSelectedValue('');
|
119
115
|
};
|
120
|
-
//
|
116
|
+
// Klavyeden gelen tuşlara tepki veren handler
|
117
|
+
var handleKeyDown = function (e) {
|
118
|
+
if (!isDropdownVisible)
|
119
|
+
return;
|
120
|
+
if (e.key === 'ArrowDown') {
|
121
|
+
e.preventDefault();
|
122
|
+
setHighlightedIndex(function (prev) { return (prev < options.length - 1 ? prev + 1 : 0); });
|
123
|
+
}
|
124
|
+
else if (e.key === 'ArrowUp') {
|
125
|
+
e.preventDefault();
|
126
|
+
setHighlightedIndex(function (prev) { return (prev > 0 ? prev - 1 : options.length - 1); });
|
127
|
+
}
|
128
|
+
else if (e.key === 'Enter') {
|
129
|
+
e.preventDefault();
|
130
|
+
if (highlightedIndex >= 0 && highlightedIndex < options.length) {
|
131
|
+
handleOptionClick(options[highlightedIndex]);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
else if (e.key === 'Escape') {
|
135
|
+
setIsDropdownVisible(false);
|
136
|
+
}
|
137
|
+
};
|
138
|
+
// Vurgulanan öğenin görünür olmasını sağlamak için scrollIntoView kullanıyoruz.
|
121
139
|
(0, react_1.useEffect)(function () {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
// };
|
131
|
-
}, []);
|
140
|
+
if (dropdownRef.current) {
|
141
|
+
var highlightedItem = dropdownRef.current.querySelector('.autocomplete-option.highlighted');
|
142
|
+
if (highlightedItem) {
|
143
|
+
highlightedItem.scrollIntoView({ block: 'nearest' });
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}, [highlightedIndex]);
|
147
|
+
// Fonksiyon, eşleşen kısmı <mark> etiketiyle vurguluyor.
|
132
148
|
var highlightMatch = function (option, query) {
|
133
149
|
if (!query)
|
134
150
|
return option;
|
@@ -152,9 +168,9 @@ var CustomAutocompleteInput = function (_a) {
|
|
152
168
|
return (react_1.default.createElement("div", { className: "autocomplete-container ".concat(className), style: style },
|
153
169
|
react_1.default.createElement("div", { className: "form-group" },
|
154
170
|
react_1.default.createElement(react_bootstrap_1.OverlayTrigger, { placement: "bottom", overlay: tooltip ? react_1.default.createElement(react_bootstrap_1.Tooltip, { id: "tooltip-".concat(id) }, tooltip) : react_1.default.createElement(react_1.default.Fragment, null) },
|
155
|
-
react_1.default.createElement(CustomInput_1.default, { id: id, name: name, label: label, inputType: CustomInput_1.InputType.TEXT, value: inputValue, onChange: handleInputChange, placeholder: placeholder, buttonIcon: react_1.default.createElement(fa_1.FaTimes, null), buttonClass:
|
156
|
-
isDropdownVisible && (react_1.default.createElement("div", { className: "autocomplete-dropdown", ref: dropdownRef }, options.map(function (option, index) { return (react_1.default.createElement("div", { key: index, className: "autocomplete-option", onClick: function () { return handleOptionClick(option); }, dangerouslySetInnerHTML: {
|
157
|
-
__html: highlightMatch(option, inputValue),
|
171
|
+
react_1.default.createElement(CustomInput_1.default, { id: id, name: name, label: label, inputType: CustomInput_1.InputType.TEXT, value: inputValue, onChange: handleInputChange, onKeyDown: handleKeyDown, placeholder: placeholder, buttonIcon: react_1.default.createElement(fa_1.FaTimes, null), buttonClass: "btn btn-danger bg-soft-danger", buttonOnClick: handleReset, className: "form-control", required: required, disabled: disabled })),
|
172
|
+
isDropdownVisible && (react_1.default.createElement("div", { className: "autocomplete-dropdown", ref: dropdownRef }, options.map(function (option, index) { return (react_1.default.createElement("div", { key: index, className: "autocomplete-option ".concat(index === highlightedIndex ? 'highlighted' : ''), onClick: function () { return handleOptionClick(option); }, dangerouslySetInnerHTML: {
|
173
|
+
__html: highlightMatch(option, inputValue),
|
158
174
|
} })); }))),
|
159
175
|
errorMessage && (react_1.default.createElement("div", { className: "invalid-feedback text-danger mt-2" },
|
160
176
|
react_1.default.createElement(fa_1.FaExclamationTriangle, { className: "me-1" }),
|
@@ -156,7 +156,7 @@ interface AutoCompleteInputElement {
|
|
156
156
|
colId?: number;
|
157
157
|
innerRowId?: number;
|
158
158
|
colClass?: string;
|
159
|
-
fetchOptions: (query: string) => string[]
|
159
|
+
fetchOptions: (query: string) => Promise<string[]>;
|
160
160
|
onSelect: (value: string) => void;
|
161
161
|
}
|
162
162
|
interface FileUploaderElement {
|
@@ -30,6 +30,7 @@ interface CustomInputProps {
|
|
30
30
|
className?: string;
|
31
31
|
buttonOnClick?: () => void;
|
32
32
|
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
33
|
+
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
33
34
|
}
|
34
35
|
declare const CustomInput: React.FC<CustomInputProps>;
|
35
36
|
export { CustomInput, InputType };
|
@@ -42,7 +42,7 @@ var InputType;
|
|
42
42
|
})(InputType || (InputType = {}));
|
43
43
|
exports.InputType = InputType;
|
44
44
|
var CustomInput = function (_a) {
|
45
|
-
var id = _a.id, name = _a.name, label = _a.label, _b = _a.inputType, inputType = _b === void 0 ? InputType.TEXT : _b, value = _a.value, placeholder = _a.placeholder, _c = _a.required, required = _c === void 0 ? false : _c, errorMessage = _a.errorMessage, _d = _a.conditionalErrorVisible, conditionalErrorVisible = _d === void 0 ? false : _d, conditionalErrorMessage = _a.conditionalErrorMessage, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.readOnly, readOnly = _f === void 0 ? false : _f, buttonIcon = _a.buttonIcon, buttonClass = _a.buttonClass, buttonTooltip = _a.buttonTooltip, description = _a.description, tooltip = _a.tooltip, style = _a.style, mainClass = _a.mainClass, className = _a.className, buttonOnClick = _a.buttonOnClick, onChange = _a.onChange;
|
45
|
+
var id = _a.id, name = _a.name, label = _a.label, _b = _a.inputType, inputType = _b === void 0 ? InputType.TEXT : _b, value = _a.value, placeholder = _a.placeholder, _c = _a.required, required = _c === void 0 ? false : _c, errorMessage = _a.errorMessage, _d = _a.conditionalErrorVisible, conditionalErrorVisible = _d === void 0 ? false : _d, conditionalErrorMessage = _a.conditionalErrorMessage, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.readOnly, readOnly = _f === void 0 ? false : _f, buttonIcon = _a.buttonIcon, buttonClass = _a.buttonClass, buttonTooltip = _a.buttonTooltip, description = _a.description, tooltip = _a.tooltip, style = _a.style, mainClass = _a.mainClass, className = _a.className, buttonOnClick = _a.buttonOnClick, onChange = _a.onChange, onKeyDown = _a.onKeyDown;
|
46
46
|
var _g = (0, react_1.useState)(false), showPassword = _g[0], setShowPassword = _g[1];
|
47
47
|
var handleType = inputType === InputType.PASSWORD && showPassword
|
48
48
|
? InputType.TEXT
|
@@ -53,10 +53,10 @@ var CustomInput = function (_a) {
|
|
53
53
|
var renderInput = function () {
|
54
54
|
// If inputType is TEL, use ReactInputMask
|
55
55
|
if (inputType === InputType.TEL) {
|
56
|
-
return (react_1.default.createElement(react_input_mask_1.default, { mask: "0(999) 999 99 99", value: value, onChange: onChange, className: "form-control ".concat(className), style: style, required: required, disabled: disabled, readOnly: readOnly, autoComplete: "new-password" }));
|
56
|
+
return (react_1.default.createElement(react_input_mask_1.default, { mask: "0(999) 999 99 99", value: value, onChange: onChange, onKeyDown: onKeyDown, className: "form-control ".concat(className), style: style, required: required, disabled: disabled, readOnly: readOnly, autoComplete: "new-password" }));
|
57
57
|
}
|
58
58
|
// Otherwise, return a normal input element
|
59
|
-
return (react_1.default.createElement("input", { id: id, name: name, type: handleType, value: value, placeholder: placeholder, onChange: onChange, className: "form-control ".concat(className), style: style, required: required, disabled: disabled, readOnly: readOnly, autoComplete: "new-password" }));
|
59
|
+
return (react_1.default.createElement("input", { id: id, name: name, type: handleType, value: value, placeholder: placeholder, onChange: onChange, onKeyDown: onKeyDown, className: "form-control ".concat(className), style: style, required: required, disabled: disabled, readOnly: readOnly, autoComplete: "new-password" }));
|
60
60
|
};
|
61
61
|
return (react_1.default.createElement("div", { className: mainClass },
|
62
62
|
react_1.default.createElement("div", { className: "form-group" },
|