@sydsoft/base 1.39.0 → 1.41.0
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.
|
@@ -17,10 +17,13 @@ interface Props extends PropsInput {
|
|
|
17
17
|
onText?: (text: string) => void;
|
|
18
18
|
onSelect?: (item: any) => void;
|
|
19
19
|
onLoad?: (value: string | number) => void;
|
|
20
|
+
ilkSec?: boolean;
|
|
20
21
|
newCreate?: boolean;
|
|
21
22
|
style?: React.CSSProperties;
|
|
22
23
|
disabled?: boolean;
|
|
23
24
|
listPositionRelative?: boolean;
|
|
25
|
+
loadingMessage?: string;
|
|
26
|
+
notFoundMessage?: string;
|
|
24
27
|
}
|
|
25
28
|
type handle = {
|
|
26
29
|
open: () => void;
|
|
@@ -7,17 +7,17 @@ import { Icon } from '../icon';
|
|
|
7
7
|
import { Button } from './Button';
|
|
8
8
|
import styles from './styles/SearchableInput.module.css';
|
|
9
9
|
var Component = function (_a, forwardedRef) {
|
|
10
|
-
var _b = _a.autoCompleteList, autoCompleteList = _b === void 0 ? [] : _b, _c = _a.isDataFromApi, isDataFromApi = _c === void 0 ? false : _c, onText = _a.onText, onSelect = _a.onSelect, onLoad = _a.onLoad, onChange = _a.onChange, _d = _a.newCreate, newCreate = _d === void 0 ? false : _d, name = _a.name, value = _a.value, itemComponent = _a.itemComponent, inputRef = _a.inputRef, _e = _a.valueKey, valueKey = _e === void 0 ? 'value' : _e, _f = _a.labelKey, labelKey = _f === void 0 ? 'label' : _f, placeholder = _a.placeholder, endAdornment = _a.endAdornment, style = _a.style, disabled = _a.disabled, parentInputValue = _a.parentInputValue, _g = _a.listPositionRelative, listPositionRelative = _g === void 0 ? false : _g, other = __rest(_a, ["autoCompleteList", "isDataFromApi", "onText", "onSelect", "onLoad", "onChange", "newCreate", "name", "value", "itemComponent", "inputRef", "valueKey", "labelKey", "placeholder", "endAdornment", "style", "disabled", "parentInputValue", "listPositionRelative"]);
|
|
10
|
+
var _b = _a.autoCompleteList, autoCompleteList = _b === void 0 ? [] : _b, _c = _a.isDataFromApi, isDataFromApi = _c === void 0 ? false : _c, onText = _a.onText, onSelect = _a.onSelect, onLoad = _a.onLoad, onChange = _a.onChange, _d = _a.newCreate, newCreate = _d === void 0 ? false : _d, name = _a.name, value = _a.value, itemComponent = _a.itemComponent, inputRef = _a.inputRef, _e = _a.valueKey, valueKey = _e === void 0 ? 'value' : _e, _f = _a.labelKey, labelKey = _f === void 0 ? 'label' : _f, placeholder = _a.placeholder, endAdornment = _a.endAdornment, style = _a.style, disabled = _a.disabled, parentInputValue = _a.parentInputValue, _g = _a.listPositionRelative, listPositionRelative = _g === void 0 ? false : _g, _h = _a.loadingMessage, loadingMessage = _h === void 0 ? 'Lütfen bekleyiniz...' : _h, _j = _a.notFoundMessage, notFoundMessage = _j === void 0 ? 'Kayıt bulunamadı...' : _j, _k = _a.ilkSec, ilkSec = _k === void 0 ? false : _k, other = __rest(_a, ["autoCompleteList", "isDataFromApi", "onText", "onSelect", "onLoad", "onChange", "newCreate", "name", "value", "itemComponent", "inputRef", "valueKey", "labelKey", "placeholder", "endAdornment", "style", "disabled", "parentInputValue", "listPositionRelative", "loadingMessage", "notFoundMessage", "ilkSec"]);
|
|
11
11
|
var refMain = useRef(null);
|
|
12
12
|
var refInput = useRef(null);
|
|
13
13
|
var refComponentInput = useRef(null);
|
|
14
14
|
var refList = useRef(null);
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
15
|
+
var _l = useState([]), data = _l[0], setData = _l[1];
|
|
16
|
+
var _m = useState(''), text = _m[0], setText = _m[1]; //Inputta görünen
|
|
17
|
+
var _o = useState(''), filter = _o[0], setFilter = _o[1]; // Filtrelemeye tabi tutulan
|
|
18
|
+
var _p = useState(false), open = _p[0], setOpen = _p[1];
|
|
19
|
+
var _q = useState(isDataFromApi && autoCompleteList.length === 0), loading = _q[0], setLoading = _q[1];
|
|
20
|
+
var _r = useState({ created: false }), newItemCreate = _r[0], setNewItemCreate = _r[1];
|
|
21
21
|
useImperativeHandle(forwardedRef, function () { return ({
|
|
22
22
|
open: function () {
|
|
23
23
|
setOpen(true);
|
|
@@ -68,8 +68,16 @@ var Component = function (_a, forwardedRef) {
|
|
|
68
68
|
}
|
|
69
69
|
}, [autoCompleteList]);
|
|
70
70
|
useEffect(function () {
|
|
71
|
-
if (
|
|
72
|
-
|
|
71
|
+
if (data.length > 0) {
|
|
72
|
+
if (value && value.toString().length > 0) {
|
|
73
|
+
if (!isDataFromApi)
|
|
74
|
+
checkByValue(value, open);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (ilkSec)
|
|
78
|
+
checkByValue(data[0][valueKey], false);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
73
81
|
}, [data]);
|
|
74
82
|
useEffect(function () {
|
|
75
83
|
if (data.length > 0) {
|
|
@@ -314,7 +322,7 @@ var Component = function (_a, forwardedRef) {
|
|
|
314
322
|
}
|
|
315
323
|
setScrollPosition();
|
|
316
324
|
};
|
|
317
|
-
return (_jsxs("div", { ref: refMain, className: styles.searchableInputComponent, onKeyDown: onKeyDown, style: style, children: [_jsx(Input, __assign({}, other, { name: name, value: text, inputRef: refInput, componentRef: refComponentInput, onFocus: function () { return setOpen(true); }, onChange: Change, endAdornment: !disabled && (_jsxs("div", { style: { marginRight: 5 }, tabIndex: -1, children: [_jsx(Button, { title: 'Temizle', tabIndex: -1, hidden: !(text && text.length > 0), onClick: function () { return clear(true, true); }, onlyIcon: _jsx(Icon, { name: 'close', style: { color: '#444' } }) }), endAdornment, _jsx(Button, { tabIndex: -1, hidden: !(data.length > 0), onClick: function () { return setOpen(!open); }, onlyIcon: _jsx(Icon, { name: open ? 'keyboard_arrow_up' : 'keyboard_arrow_down', style: { color: '#444' } }) })] })), placeholder: loading ? 'Lütfen bekleyiniz...' : placeholder, loading: loading, disabled: disabled, propsInput: __assign(__assign({}, other === null || other === void 0 ? void 0 : other.propsInput), { autoComplete: 'off' }) })), open && (_jsx("div", { className: 'listDiv', "data-relative": listPositionRelative, children: _jsxs("ul", { ref: refList, className: "list ".concat(open ? 'open' : ''), children: [(filteredData.length === 0 || loading) && _jsx("div", { className: "message ".concat(loading ? 'loading' : ''), children: loading ?
|
|
325
|
+
return (_jsxs("div", { ref: refMain, className: styles.searchableInputComponent, onKeyDown: onKeyDown, style: style, children: [_jsx(Input, __assign({}, other, { name: name, value: text, inputRef: refInput, componentRef: refComponentInput, onFocus: function () { return setOpen(true); }, onChange: Change, endAdornment: !disabled && (_jsxs("div", { style: { marginRight: 5 }, tabIndex: -1, children: [_jsx(Button, { title: 'Temizle', tabIndex: -1, hidden: !(text && text.length > 0), onClick: function () { return clear(true, true); }, onlyIcon: _jsx(Icon, { name: 'close', style: { color: '#444' } }) }), endAdornment, _jsx(Button, { tabIndex: -1, hidden: !(data.length > 0), onClick: function () { return setOpen(!open); }, onlyIcon: _jsx(Icon, { name: open ? 'keyboard_arrow_up' : 'keyboard_arrow_down', style: { color: '#444' } }) })] })), placeholder: loading ? 'Lütfen bekleyiniz...' : placeholder, loading: loading, disabled: disabled, propsInput: __assign(__assign({}, other === null || other === void 0 ? void 0 : other.propsInput), { autoComplete: 'off' }) })), open && (_jsx("div", { className: 'listDiv', "data-relative": listPositionRelative, children: _jsxs("ul", { ref: refList, className: "list ".concat(open ? 'open' : ''), children: [(filteredData.length === 0 || loading) && _jsx("div", { className: "message ".concat(loading ? 'loading' : ''), children: loading ? loadingMessage : notFoundMessage }), filteredData.map(function (item, key) {
|
|
318
326
|
var itemValue = item[valueKey];
|
|
319
327
|
var itemLabel = item[labelKey];
|
|
320
328
|
return (_jsxs("li", { className: "item ".concat(itemValue === value ? 'active' : ''), "data-value": itemValue, "data-label": itemLabel, onClick: function () { return setValue(item, false); }, children: [item.create && _jsx("span", { className: 'newCreate', children: "Yeni Olu\u015Ftur: " }), itemComponent ? itemComponent(item) : itemLabel] }, key));
|