@sydsoft/base 1.42.0 → 1.44.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.
- package/dist/esm/_lib/baseFunctions.d.ts +8 -3
- package/dist/esm/_lib/baseFunctions.js +39 -5
- package/dist/esm/_lib/listFunctions.d.ts +2 -0
- package/dist/esm/_lib/listFunctions.js +114 -0
- package/dist/esm/_lib/storage/encData.d.ts +2 -2
- package/dist/esm/_lib/storage/encData.js +15 -10
- package/dist/esm/_lib/storage/localStorage.js +7 -7
- package/dist/esm/form/Input.js +6 -6
- package/dist/esm/form/SearchableInput.d.ts +18 -17
- package/dist/esm/form/SearchableInput.js +140 -226
- package/dist/esm/form/styles/Input.module.css +9 -9
- package/dist/esm/form/styles/SearchableInput.module.css +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare const isDev: boolean;
|
|
3
3
|
export declare const isServerReq: (context: any) => boolean;
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare function
|
|
4
|
+
export declare const sleep: (ms?: number) => Promise<unknown>;
|
|
5
|
+
export declare const padNumber: (num: number, padLength?: number, padString?: string) => string;
|
|
6
|
+
export declare function inputTumuBuyukCevir(e: React.ChangeEvent<HTMLInputElement>): void;
|
|
7
|
+
export declare function inputTumuKucukCevir(e: React.ChangeEvent<HTMLInputElement>): void;
|
|
8
|
+
export declare const convertLowerCase: (text?: any) => any;
|
|
9
|
+
export declare const convertForSearch: (value: string) => string;
|
|
10
|
+
export declare function convertForSEO(e: React.ChangeEvent<HTMLInputElement>): void;
|
|
7
11
|
export declare function getDomain(context?: any): string;
|
|
12
|
+
export declare const uniqueID: (key?: string, length?: number) => string;
|
|
@@ -1,24 +1,49 @@
|
|
|
1
1
|
export var isDev = !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
|
|
2
2
|
export var isServerReq = function (context) { var _a, _b; return !((_b = (_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.url) === null || _b === void 0 ? void 0 : _b.startsWith('/_next')); };
|
|
3
|
-
export function
|
|
3
|
+
export var sleep = function (ms) {
|
|
4
|
+
if (ms === void 0) { ms = 1000; }
|
|
5
|
+
return new Promise(function (resolve) { return setTimeout(resolve, ms); });
|
|
6
|
+
};
|
|
7
|
+
export var padNumber = function (num, padLength, padString) {
|
|
8
|
+
if (padLength === void 0) { padLength = 2; }
|
|
9
|
+
if (padString === void 0) { padString = '0'; }
|
|
10
|
+
return String(num).padStart(padLength, padString);
|
|
11
|
+
};
|
|
12
|
+
export function inputTumuBuyukCevir(e) {
|
|
4
13
|
var _a;
|
|
5
14
|
if ((e === null || e === void 0 ? void 0 : e.target) && ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.setSelectionRange)) {
|
|
6
15
|
var start = e.target.selectionStart;
|
|
7
16
|
var end = e.target.selectionEnd;
|
|
8
|
-
e.target.value = e.target.value.toString().toLocaleUpperCase('tr');
|
|
17
|
+
e.target.value = e.target.value.toString().toLocaleUpperCase('tr-TR');
|
|
9
18
|
e.target.setSelectionRange(start, end);
|
|
10
19
|
}
|
|
11
20
|
}
|
|
12
|
-
export function
|
|
21
|
+
export function inputTumuKucukCevir(e) {
|
|
13
22
|
var _a;
|
|
14
23
|
if ((e === null || e === void 0 ? void 0 : e.target) && ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.setSelectionRange)) {
|
|
15
24
|
var start = e.target.selectionStart;
|
|
16
25
|
var end = e.target.selectionEnd;
|
|
17
|
-
e.target.value = e.target.value.toString().toLocaleLowerCase('tr');
|
|
26
|
+
e.target.value = e.target.value.toString().toLocaleLowerCase('tr-TR');
|
|
18
27
|
e.target.setSelectionRange(start, end);
|
|
19
28
|
}
|
|
20
29
|
}
|
|
21
|
-
export function
|
|
30
|
+
export var convertLowerCase = function (text) {
|
|
31
|
+
if (text === void 0) { text = ''; }
|
|
32
|
+
return text.toString().toLocaleLowerCase('tr-TR');
|
|
33
|
+
};
|
|
34
|
+
export var convertForSearch = function (value) {
|
|
35
|
+
var data = value === null || value === void 0 ? void 0 : value.toString().toLocaleLowerCase('tr-TR');
|
|
36
|
+
data = data.replace(/ö/g, 'o');
|
|
37
|
+
data = data.replace(/ç/g, 'c');
|
|
38
|
+
data = data.replace(/ş/g, 's');
|
|
39
|
+
data = data.replace(/ı/g, 'i');
|
|
40
|
+
data = data.replace(/ğ/g, 'g');
|
|
41
|
+
data = data.replace(/ü/g, 'u');
|
|
42
|
+
data = data.replace(/[^a-z\d]/g, ''); // %_- are allowed
|
|
43
|
+
data = data.replace(/^\s+|\s+$/g, '');
|
|
44
|
+
return data;
|
|
45
|
+
};
|
|
46
|
+
export function convertForSEO(e) {
|
|
22
47
|
var _a;
|
|
23
48
|
if ((e === null || e === void 0 ? void 0 : e.target) && ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.setSelectionRange)) {
|
|
24
49
|
var start = e.target.selectionStart;
|
|
@@ -61,3 +86,12 @@ export function getDomain(context) {
|
|
|
61
86
|
}
|
|
62
87
|
return url;
|
|
63
88
|
}
|
|
89
|
+
export var uniqueID = function (key, length) {
|
|
90
|
+
if (key === void 0) { key = ''; }
|
|
91
|
+
if (length === void 0) { length = 16; }
|
|
92
|
+
return (key +
|
|
93
|
+
parseInt(Math.ceil(Math.random() * Date.now())
|
|
94
|
+
.toPrecision(length)
|
|
95
|
+
.toString()
|
|
96
|
+
.replace('.', '')));
|
|
97
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export var onKeyboardSelection = function (_a) {
|
|
2
|
+
var e = _a.e, targetElement = _a.targetElement, _b = _a.itemClass, itemClass = _b === void 0 ? "item" : _b, _c = _a.selectedClass, selectedClass = _c === void 0 ? "selected" : _c, checkByValue = _a.checkByValue, checkByInput = _a.checkByInput, clear = _a.clear;
|
|
3
|
+
if (!targetElement.current)
|
|
4
|
+
return null;
|
|
5
|
+
var config = {
|
|
6
|
+
e: e,
|
|
7
|
+
itemClass: itemClass,
|
|
8
|
+
selectedClass: selectedClass,
|
|
9
|
+
};
|
|
10
|
+
function selectEnter() {
|
|
11
|
+
if (!targetElement.current)
|
|
12
|
+
return null;
|
|
13
|
+
var text = targetElement.current.querySelector("".concat(config.itemClass, ".").concat(config.selectedClass));
|
|
14
|
+
if (text) {
|
|
15
|
+
checkByValue(text.dataset.value);
|
|
16
|
+
}
|
|
17
|
+
else if (targetElement.current.querySelectorAll("".concat(config.itemClass)).length > 0) {
|
|
18
|
+
var target = targetElement.current.querySelectorAll("".concat(config.itemClass, ".").concat(config.selectedClass))[0];
|
|
19
|
+
checkByValue(target.dataset.value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
clear(true, true);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function selectFirst() {
|
|
26
|
+
if (!targetElement.current)
|
|
27
|
+
return null;
|
|
28
|
+
var showList = targetElement.current.querySelectorAll("".concat(config.itemClass));
|
|
29
|
+
if (showList.length > 0) {
|
|
30
|
+
showList[0].classList.add(config.selectedClass);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function selectLast() {
|
|
34
|
+
if (!targetElement.current)
|
|
35
|
+
return null;
|
|
36
|
+
var showList = targetElement.current.querySelectorAll("".concat(config.itemClass));
|
|
37
|
+
if (showList.length > 0) {
|
|
38
|
+
showList[showList.length - 1].classList.add(config.selectedClass);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function selectNext(element) {
|
|
42
|
+
element.classList.remove(config.selectedClass);
|
|
43
|
+
var next = element.nextElementSibling;
|
|
44
|
+
if (next && next.nodeType !== -1) {
|
|
45
|
+
if (next.classList.contains("item")) {
|
|
46
|
+
next.classList.add(config.selectedClass);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
selectNext(next);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
selectFirst();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function selectPrev(element) {
|
|
57
|
+
element.classList.remove(config.selectedClass);
|
|
58
|
+
var next = element.previousElementSibling;
|
|
59
|
+
if (next && next.nodeType !== -1) {
|
|
60
|
+
if (next.classList.contains("item")) {
|
|
61
|
+
next.classList.add(config.selectedClass);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
selectPrev(next);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
selectLast();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
var selected = targetElement.current.querySelector("".concat(config.itemClass, ".").concat(config.selectedClass));
|
|
72
|
+
if (e.which == 40) {
|
|
73
|
+
if (selected) {
|
|
74
|
+
selectNext(selected);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
selectFirst();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (e.which == 38) {
|
|
81
|
+
if (selected) {
|
|
82
|
+
selectPrev(selected);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
selectLast();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (e.which == 35) {
|
|
89
|
+
selectLast();
|
|
90
|
+
}
|
|
91
|
+
else if (e.which == 36) {
|
|
92
|
+
selectFirst();
|
|
93
|
+
}
|
|
94
|
+
else if (e.which == 13) {
|
|
95
|
+
selectEnter();
|
|
96
|
+
}
|
|
97
|
+
else if (e.which == 9) {
|
|
98
|
+
checkByInput();
|
|
99
|
+
}
|
|
100
|
+
setScrollListPosition(targetElement);
|
|
101
|
+
};
|
|
102
|
+
export function setScrollListPosition(targetElement) {
|
|
103
|
+
if (targetElement.current) {
|
|
104
|
+
var position = 0;
|
|
105
|
+
var text = targetElement.current.querySelector(".selected");
|
|
106
|
+
if (text) {
|
|
107
|
+
position = text.offsetTop - 35;
|
|
108
|
+
}
|
|
109
|
+
else if (targetElement.current.querySelector(".active")) {
|
|
110
|
+
position = targetElement.current.querySelector(".active").offsetTop - 35;
|
|
111
|
+
}
|
|
112
|
+
targetElement.current.scrollTop = position;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const encData: (data:
|
|
2
|
-
export declare const decData: (data: string) => any;
|
|
1
|
+
export declare const encData: (data: object | string | number, keys?: number[]) => string;
|
|
2
|
+
export declare const decData: (data: string, keys?: number[]) => any;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { isDev } from
|
|
2
|
-
var
|
|
3
|
-
export var encData = function (data) {
|
|
1
|
+
import { isDev } from "@sydsoft/base";
|
|
2
|
+
var encDecDataKeys = [3, 5, 8, 11, 15, 22];
|
|
3
|
+
export var encData = function (data, keys) {
|
|
4
|
+
if (keys === void 0) { keys = encDecDataKeys; }
|
|
4
5
|
try {
|
|
5
|
-
var
|
|
6
|
+
var newJSON = { data: data };
|
|
7
|
+
var utf8Data = unescape(encodeURIComponent(JSON.stringify(newJSON))); // Dizeyi UTF-8'e dönüştür
|
|
6
8
|
var newData_1 = btoa(utf8Data);
|
|
7
9
|
keys.map(function (value) {
|
|
8
10
|
var randomChar = String.fromCharCode(Math.floor(Math.random() * (122 - 97 + 1)) + 97);
|
|
@@ -11,11 +13,13 @@ export var encData = function (data) {
|
|
|
11
13
|
return newData_1;
|
|
12
14
|
}
|
|
13
15
|
catch (e) {
|
|
14
|
-
isDev && console.log(
|
|
15
|
-
return
|
|
16
|
+
isDev && console.log("ERROR => encData =>", e);
|
|
17
|
+
return "";
|
|
16
18
|
}
|
|
17
19
|
};
|
|
18
|
-
export var decData = function (data) {
|
|
20
|
+
export var decData = function (data, keys) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (keys === void 0) { keys = encDecDataKeys; }
|
|
19
23
|
try {
|
|
20
24
|
var decode_1 = data;
|
|
21
25
|
keys.map(function (value, index) {
|
|
@@ -29,10 +33,11 @@ export var decData = function (data) {
|
|
|
29
33
|
});
|
|
30
34
|
var decodedString = atob(decode_1);
|
|
31
35
|
var utf8DecodedString = decodeURIComponent(escape(decodedString));
|
|
32
|
-
|
|
36
|
+
var parse = JSON.parse(utf8DecodedString);
|
|
37
|
+
return (_a = parse === null || parse === void 0 ? void 0 : parse.data) !== null && _a !== void 0 ? _a : "";
|
|
33
38
|
}
|
|
34
39
|
catch (e) {
|
|
35
|
-
isDev && console.log(
|
|
36
|
-
return
|
|
40
|
+
isDev && console.log("ERROR => decData =>", e);
|
|
41
|
+
return "";
|
|
37
42
|
}
|
|
38
43
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { decData, encData } from
|
|
2
|
-
import { isDev } from
|
|
3
|
-
var storageAvailable = typeof Storage ===
|
|
1
|
+
import { decData, encData } from './encData';
|
|
2
|
+
import { isDev } from '../baseFunctions';
|
|
3
|
+
var storageAvailable = typeof Storage === 'undefined' || !window.localStorage ? false : true;
|
|
4
4
|
export var setLocalStorage = function (key, value) {
|
|
5
5
|
if (!storageAvailable)
|
|
6
6
|
return false;
|
|
@@ -9,7 +9,7 @@ export var setLocalStorage = function (key, value) {
|
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
11
11
|
catch (e) {
|
|
12
|
-
isDev && console.log(
|
|
12
|
+
isDev && console.log('ERROR => localStorage =>', e);
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
@@ -21,7 +21,7 @@ export var getLocalStorage = function (key) {
|
|
|
21
21
|
return saved ? decData(saved) : null;
|
|
22
22
|
}
|
|
23
23
|
catch (e) {
|
|
24
|
-
isDev && console.log(
|
|
24
|
+
isDev && console.log('ERROR => localStorage =>', e);
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -33,7 +33,7 @@ export var removeLocalStorage = function (key) {
|
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
35
|
catch (e) {
|
|
36
|
-
isDev && console.log(
|
|
36
|
+
isDev && console.log('ERROR => localStorage =>', e);
|
|
37
37
|
return false;
|
|
38
38
|
}
|
|
39
39
|
};
|
|
@@ -45,7 +45,7 @@ export var clearLocalStorage = function () {
|
|
|
45
45
|
return true;
|
|
46
46
|
}
|
|
47
47
|
catch (e) {
|
|
48
|
-
isDev && console.log(
|
|
48
|
+
isDev && console.log('ERROR => localStorage =>', e);
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
51
|
};
|
package/dist/esm/form/Input.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import { applyInputMask } from '../_lib/inputMask';
|
|
6
|
-
import { alert_add } from '../alert';
|
|
4
|
+
import { convertForSEO, inputTumuBuyukCevir, inputTumuKucukCevir } from '../_lib/baseFunctions';
|
|
7
5
|
import { Dialog } from './Dialog';
|
|
6
|
+
import { alert_add } from '../alert';
|
|
7
|
+
import { applyInputMask } from '../_lib/inputMask';
|
|
8
8
|
import styles from './styles/Input.module.css';
|
|
9
9
|
export var Input = function (_a) {
|
|
10
10
|
var componentRef = _a.componentRef, inputRef = _a.inputRef, className = _a.className, propsComponent = _a.propsComponent, propsInput = _a.propsInput, id = _a.id, name = _a.name, value = _a.value, type = _a.type, label = _a.label, startAdornment = _a.startAdornment, endAdornment = _a.endAdornment, placeholder = _a.placeholder, onChange = _a.onChange, onFocus = _a.onFocus, onBlur = _a.onBlur, onClick = _a.onClick, onKeyPress = _a.onKeyPress, onKeyUp = _a.onKeyUp, onKeyDown = _a.onKeyDown, disabled = _a.disabled, required = _a.required, loading = _a.loading, autoFocus = _a.autoFocus, select = _a.select, _b = _a.valueKey, valueKey = _b === void 0 ? 'value' : _b, _c = _a.labelKey, labelKey = _c === void 0 ? 'label' : _c, ilkSec = _a.ilkSec, multiline = _a.multiline, rows = _a.rows, sadeceYazi = _a.sadeceYazi, sadeceSayi = _a.sadeceSayi, tumuBuyuk = _a.tumuBuyuk, tumuKucuk = _a.tumuKucuk, seoCevir = _a.seoCevir, dosyaNoGiris = _a.dosyaNoGiris, fileNameGiris = _a.fileNameGiris, dateGecmisKontrol = _a.dateGecmisKontrol, autoSelectText = _a.autoSelectText, _d = _a.mask, mask = _d === void 0 ? '' : _d, _e = _a.maskSettings, maskSettings = _e === void 0 ? {
|
|
@@ -66,11 +66,11 @@ export var Input = function (_a) {
|
|
|
66
66
|
}, [mask]);
|
|
67
67
|
var Change = useCallback(function (e) {
|
|
68
68
|
if (tumuBuyuk)
|
|
69
|
-
|
|
69
|
+
inputTumuBuyukCevir(e);
|
|
70
70
|
if (tumuKucuk)
|
|
71
|
-
|
|
71
|
+
inputTumuKucukCevir(e);
|
|
72
72
|
if (seoCevir)
|
|
73
|
-
|
|
73
|
+
convertForSEO(e);
|
|
74
74
|
setInputFilled(e.target.value.length > 0);
|
|
75
75
|
onChange ? onChange(e) : null;
|
|
76
76
|
}, [onChange, seoCevir, tumuBuyuk, tumuKucuk]);
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
import { PropsInput } from './
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PropsInput } from './index';
|
|
3
3
|
type typeList = {
|
|
4
4
|
value?: string;
|
|
5
5
|
label?: string;
|
|
6
|
-
[key: string
|
|
7
|
-
}
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
type typeValue = string | number | undefined;
|
|
8
9
|
interface Props extends PropsInput {
|
|
9
|
-
autoCompleteList?: typeList;
|
|
10
|
-
|
|
11
|
-
value:
|
|
10
|
+
autoCompleteList?: typeList[];
|
|
11
|
+
isDataFromApi: boolean;
|
|
12
|
+
value: typeValue;
|
|
12
13
|
valueKey?: string;
|
|
13
14
|
labelKey?: string;
|
|
14
|
-
itemComponent?:
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
itemComponent?: (option: typeList) => React.ReactNode;
|
|
16
|
+
parentInputValue?: typeValue;
|
|
17
|
+
onChange?: (e: any) => void;
|
|
17
18
|
onText?: (text: string) => void;
|
|
18
19
|
onSelect?: (item: any) => void;
|
|
19
|
-
onLoad?: (value:
|
|
20
|
+
onLoad?: (value: typeValue) => void;
|
|
20
21
|
ilkSec?: boolean;
|
|
21
22
|
newCreate?: boolean;
|
|
22
23
|
style?: React.CSSProperties;
|
|
@@ -25,13 +26,13 @@ interface Props extends PropsInput {
|
|
|
25
26
|
loadingMessage?: string;
|
|
26
27
|
notFoundMessage?: string;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
export interface SearchableInputRef {
|
|
30
|
+
setAutoCompleteList: (list: typeList[], value?: typeValue, callback?: () => void) => void;
|
|
31
|
+
clear: (openList?: boolean, focusInput?: boolean) => void;
|
|
29
32
|
open: () => void;
|
|
30
33
|
close: () => void;
|
|
31
|
-
checkByValue: (value:
|
|
34
|
+
checkByValue: (value: typeValue, openList?: boolean) => void;
|
|
32
35
|
setLoading: (loading: boolean) => void;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
export declare const SearchableInput: React.ForwardRefExoticComponent<Props & React.RefAttributes<handle>>;
|
|
36
|
+
}
|
|
37
|
+
export declare const SearchableInput: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<SearchableInputRef>>;
|
|
37
38
|
export {};
|
|
@@ -1,24 +1,45 @@
|
|
|
1
1
|
import { __assign, __rest, __spreadArray } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { Button, Input } from './index';
|
|
4
|
+
import { convertForSearch, convertLowerCase } from '../_lib/baseFunctions';
|
|
5
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { onKeyboardSelection, setScrollListPosition } from '../_lib/listFunctions';
|
|
6
7
|
import { Icon } from '../icon';
|
|
7
|
-
import { Button } from './Button';
|
|
8
8
|
import styles from './styles/SearchableInput.module.css';
|
|
9
|
-
var
|
|
10
|
-
var _b = _a.autoCompleteList, autoCompleteList = _b === void 0 ? [] : _b,
|
|
9
|
+
export var SearchableInput = forwardRef(function (_a, ref) {
|
|
10
|
+
var _b = _a.autoCompleteList, autoCompleteList = _b === void 0 ? [] : _b, isDataFromApi = _a.isDataFromApi, name = _a.name, value = _a.value, parentInputValue = _a.parentInputValue, disabled = _a.disabled, itemComponent = _a.itemComponent, _c = _a.valueKey, valueKey = _c === void 0 ? 'value' : _c, _d = _a.labelKey, labelKey = _d === void 0 ? 'label' : _d, onSelect = _a.onSelect, onChange = _a.onChange, onText = _a.onText, onLoad = _a.onLoad, style = _a.style, _e = _a.listPositionRelative, listPositionRelative = _e === void 0 ? false : _e, _f = _a.loadingMessage, loadingMessage = _f === void 0 ? 'Lütfen bekleyiniz...' : _f, _g = _a.notFoundMessage, notFoundMessage = _g === void 0 ? 'Kayıt bulunamadı...' : _g, placeholder = _a.placeholder, endAdornment = _a.endAdornment, _h = _a.ilkSec, ilkSec = _h === void 0 ? false : _h, _j = _a.newCreate, newCreate = _j === void 0 ? false : _j, inputRef = _a.inputRef, other = __rest(_a, ["autoCompleteList", "isDataFromApi", "name", "value", "parentInputValue", "disabled", "itemComponent", "valueKey", "labelKey", "onSelect", "onChange", "onText", "onLoad", "style", "listPositionRelative", "loadingMessage", "notFoundMessage", "placeholder", "endAdornment", "ilkSec", "newCreate", "inputRef"]);
|
|
11
11
|
var refMain = useRef(null);
|
|
12
12
|
var refInput = useRef(null);
|
|
13
|
-
var refComponentInput = useRef(null);
|
|
14
13
|
var refList = useRef(null);
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
|
|
14
|
+
var _k = useState(autoCompleteList !== null && autoCompleteList !== void 0 ? autoCompleteList : []), data = _k[0], setData = _k[1];
|
|
15
|
+
var _l = useState(value !== null && value !== void 0 ? value : undefined), selectedValue = _l[0], setSelectedValue = _l[1];
|
|
16
|
+
var _m = useState(parentInputValue !== null && parentInputValue !== void 0 ? parentInputValue : undefined), parentValue = _m[0], setParentValue = _m[1];
|
|
17
|
+
var _o = useState(''), text = _o[0], setText = _o[1]; //Inputta görünen
|
|
18
|
+
var _p = useState(''), filter = _p[0], setFilter = _p[1]; // Filtrelemeye tabi tutulan
|
|
19
|
+
var _q = useState({ created: false }), newItemCreate = _q[0], setNewItemCreate = _q[1];
|
|
20
|
+
var _r = useState(false), open = _r[0], setOpen = _r[1];
|
|
21
|
+
var _s = useState(isDataFromApi && (!autoCompleteList || (autoCompleteList === null || autoCompleteList === void 0 ? void 0 : autoCompleteList.length) == 0)), loading = _s[0], setLoading = _s[1];
|
|
22
|
+
useImperativeHandle(ref, function () { return ({
|
|
23
|
+
setAutoCompleteList: function (list, value, callback) {
|
|
24
|
+
if (value === void 0) { value = undefined; }
|
|
25
|
+
if (autoCompleteList && (autoCompleteList === null || autoCompleteList === void 0 ? void 0 : autoCompleteList.length) > 0) {
|
|
26
|
+
alert('AutoCompleteList zaten tanımlı olduğundan dışardan data seti değiştirilemez.');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
setData(list);
|
|
30
|
+
value && sendChange(value);
|
|
31
|
+
setLoading(false);
|
|
32
|
+
if (!Array.isArray(list) || list.length == 0) {
|
|
33
|
+
clear(false);
|
|
34
|
+
}
|
|
35
|
+
callback && callback();
|
|
36
|
+
// isDev && console.log("setAutoCompleteList =>", name, value, list);
|
|
37
|
+
},
|
|
38
|
+
clear: function (openList, focusInput) {
|
|
39
|
+
if (openList === void 0) { openList = false; }
|
|
40
|
+
if (focusInput === void 0) { focusInput = false; }
|
|
41
|
+
return clear(openList, focusInput);
|
|
42
|
+
},
|
|
22
43
|
open: function () {
|
|
23
44
|
setOpen(true);
|
|
24
45
|
refInput.current && refInput.current.focus();
|
|
@@ -28,68 +49,62 @@ var Component = function (_a, forwardedRef) {
|
|
|
28
49
|
if (openList === void 0) { openList = false; }
|
|
29
50
|
return checkByValue(value, openList);
|
|
30
51
|
},
|
|
31
|
-
setLoading: function (value) { return setLoading(value); }
|
|
32
|
-
|
|
33
|
-
if (value === void 0) { value = null; }
|
|
34
|
-
setData(list);
|
|
35
|
-
if (value)
|
|
36
|
-
checkByValue(value, false, list);
|
|
37
|
-
setLoading(false);
|
|
38
|
-
},
|
|
39
|
-
clear: function (openList, focusInput) {
|
|
40
|
-
if (openList === void 0) { openList = false; }
|
|
41
|
-
if (focusInput === void 0) { focusInput = false; }
|
|
42
|
-
return clear(openList, focusInput);
|
|
43
|
-
}
|
|
44
|
-
}); });
|
|
45
|
-
var handleUpdatePosition = function () {
|
|
46
|
-
if (open && !listPositionRelative && refMain) {
|
|
47
|
-
setFixedPosition(refMain);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
useEffect(function () {
|
|
51
|
-
if (onLoad)
|
|
52
|
-
onLoad(value !== null && value !== void 0 ? value : '');
|
|
53
|
-
}, []);
|
|
52
|
+
setLoading: function (value) { return setLoading(value); }
|
|
53
|
+
}); }, [autoCompleteList, data, value]);
|
|
54
54
|
useEffect(function () {
|
|
55
55
|
if (inputRef)
|
|
56
56
|
inputRef.current = refInput.current;
|
|
57
57
|
}, [refInput.current]);
|
|
58
|
+
useEffect(function () { return onLoad && onLoad(value); }, []);
|
|
58
59
|
useEffect(function () {
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
if (autoCompleteList && Array.isArray(autoCompleteList)) {
|
|
61
|
+
if (autoCompleteList.length > 0) {
|
|
62
|
+
// Sadece gerçekten farklıysa set et
|
|
63
|
+
if (JSON.stringify(autoCompleteList) !== JSON.stringify(data)) {
|
|
64
|
+
setData(autoCompleteList);
|
|
65
|
+
// isDev && console.log("autoCompleteList dolu =>", name, autoCompleteList);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Boş array geldi VE data zaten boş değilse
|
|
70
|
+
if (data.length > 0) {
|
|
71
|
+
setData([]);
|
|
72
|
+
// isDev && console.log("autoCompleteList boşaltıldı =>", name);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
}, [autoCompleteList]);
|
|
70
77
|
useEffect(function () {
|
|
78
|
+
// isDev && console.log('data =>', name, data, 'selectedValue =>', selectedValue, 'value =>', value);
|
|
79
|
+
if (!Array.isArray(data)) {
|
|
80
|
+
setData([]);
|
|
81
|
+
}
|
|
71
82
|
if (data.length > 0) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
else {
|
|
77
|
-
if (ilkSec)
|
|
78
|
-
checkByValue(data[0][valueKey], false);
|
|
83
|
+
setLoading(false);
|
|
84
|
+
checkByValue(selectedValue, open);
|
|
85
|
+
if (!value && ilkSec) {
|
|
86
|
+
checkByValue(data[0][valueKey], false);
|
|
79
87
|
}
|
|
80
88
|
}
|
|
89
|
+
else {
|
|
90
|
+
!isDataFromApi && clear(false);
|
|
91
|
+
}
|
|
81
92
|
}, [data]);
|
|
93
|
+
// Seçim değişikliğinde parent'ı bilgilendir
|
|
82
94
|
useEffect(function () {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
else {
|
|
88
|
-
if (!isDataFromApi)
|
|
89
|
-
clear(false);
|
|
90
|
-
}
|
|
95
|
+
// isDev && console.log('selectedValue =>', name, selectedValue, 'value =>', value);
|
|
96
|
+
if ((value === null || value === void 0 ? void 0 : value.toString()) != (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.toString())) {
|
|
97
|
+
checkByValue(value, open);
|
|
98
|
+
// isDev && console.log('value Kontrol ediliyor', value, selectedValue);
|
|
91
99
|
}
|
|
92
100
|
}, [value]);
|
|
101
|
+
useEffect(function () {
|
|
102
|
+
if (parentInputValue !== parentValue) {
|
|
103
|
+
setParentValue(parentInputValue);
|
|
104
|
+
clear(false);
|
|
105
|
+
// isDev && console.log(name, "parentInputValueDeğişti =>", parentInputValue);
|
|
106
|
+
}
|
|
107
|
+
}, [parentInputValue]);
|
|
93
108
|
useEffect(function () {
|
|
94
109
|
var checkHideBackDrop = function (e) {
|
|
95
110
|
if (open && refMain.current && !refMain.current.contains(e.target)) {
|
|
@@ -104,7 +119,7 @@ var Component = function (_a, forwardedRef) {
|
|
|
104
119
|
if (refMain.current)
|
|
105
120
|
refMain.current.addEventListener('keydown', checkESC);
|
|
106
121
|
if (open) {
|
|
107
|
-
|
|
122
|
+
setScrollListPosition(refList);
|
|
108
123
|
if (!listPositionRelative) {
|
|
109
124
|
window.addEventListener('scroll', handleUpdatePosition, true);
|
|
110
125
|
window.addEventListener('resize', handleUpdatePosition);
|
|
@@ -119,84 +134,40 @@ var Component = function (_a, forwardedRef) {
|
|
|
119
134
|
};
|
|
120
135
|
}, [open]);
|
|
121
136
|
useLayoutEffect(function () { return handleUpdatePosition(); }, [open]);
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var convertForSearch = useCallback(function (value) {
|
|
127
|
-
var data = cevirTumuKucuk(value);
|
|
128
|
-
data = data.replace(/ö/g, 'o');
|
|
129
|
-
data = data.replace(/ç/g, 'c');
|
|
130
|
-
data = data.replace(/ş/g, 's');
|
|
131
|
-
data = data.replace(/ı/g, 'i');
|
|
132
|
-
data = data.replace(/ğ/g, 'g');
|
|
133
|
-
data = data.replace(/ü/g, 'u');
|
|
134
|
-
data = data.replace(/[^a-z\d]/g, ''); // %_- are allowed
|
|
135
|
-
data = data.replace(/^\s+|\s+$/g, '');
|
|
136
|
-
return data;
|
|
137
|
-
}, [cevirTumuKucuk]);
|
|
138
|
-
var filteredData = useMemo(function () {
|
|
139
|
-
var _a;
|
|
140
|
-
var list;
|
|
141
|
-
if (filter.length > 0) {
|
|
142
|
-
list = data.filter(function (item) { return convertForSearch(item[labelKey]).includes(convertForSearch(filter)) || item[labelKey] == filter; });
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
list = data;
|
|
146
|
-
}
|
|
147
|
-
if (newCreate && text.length > 0) {
|
|
148
|
-
var filterText = data.find(function (item) { return item[labelKey].toString().toLowerCase() === text.toString().toLowerCase(); });
|
|
149
|
-
if (!filterText) {
|
|
150
|
-
var newItem = (_a = {}, _a[labelKey] = text, _a[valueKey] = text, _a.create = true, _a);
|
|
151
|
-
list = __spreadArray([newItem], list, true);
|
|
152
|
-
setNewItemCreate(newItem);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
if (newItemCreate.create)
|
|
156
|
-
setNewItemCreate({ create: false });
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return list;
|
|
160
|
-
}, [data, filter, newCreate, text, valueKey, labelKey]);
|
|
161
|
-
var setValue = useCallback(function (result, openList) {
|
|
137
|
+
var setValue = useCallback(function (item, openList) {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
var newValue = (_a = item === null || item === void 0 ? void 0 : item[valueKey]) !== null && _a !== void 0 ? _a : '';
|
|
140
|
+
var newLabel = (_b = item === null || item === void 0 ? void 0 : item[labelKey]) !== null && _b !== void 0 ? _b : '';
|
|
162
141
|
setOpen(openList);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
142
|
+
setText(newLabel);
|
|
143
|
+
// isDev && console.log(name, "setValue", newValue, "item", item, "value", value);
|
|
144
|
+
if (newValue === selectedValue)
|
|
145
|
+
return;
|
|
168
146
|
setFilter('');
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
if (onSelect)
|
|
178
|
-
onSelect(result);
|
|
179
|
-
}, [onChange, onSelect, name, value, valueKey, labelKey]);
|
|
180
|
-
var Change = useCallback(function (e) {
|
|
181
|
-
setValue(false, true);
|
|
147
|
+
setSelectedValue(newValue);
|
|
148
|
+
onChange && sendChange(newValue);
|
|
149
|
+
onSelect && onSelect(item);
|
|
150
|
+
}, [onChange, onSelect, name, selectedValue, valueKey, labelKey]);
|
|
151
|
+
var textInputOnChange = useCallback(function (e) {
|
|
152
|
+
setSelectedValue(undefined);
|
|
182
153
|
setText(e.target.value);
|
|
183
154
|
setFilter(e.target.value.trim());
|
|
184
155
|
setOpen(true);
|
|
185
|
-
|
|
186
|
-
onText(e.target.value);
|
|
156
|
+
onText && onText(e.target.value);
|
|
187
157
|
}, [setValue, onText]);
|
|
188
158
|
var checkByValue = useCallback(function (value, openList, list) {
|
|
189
159
|
if (openList === void 0) { openList = false; }
|
|
190
160
|
if (list === void 0) { list = []; }
|
|
191
161
|
var targetList = list.length > 0 ? list : data;
|
|
192
|
-
var find = Object.values(targetList).find(function (item) { return
|
|
162
|
+
var find = Object.values(targetList).find(function (item) { return convertLowerCase(item[valueKey]) === convertLowerCase(value); });
|
|
193
163
|
if (!find && newCreate && newItemCreate.create) {
|
|
194
164
|
find = newItemCreate;
|
|
195
165
|
}
|
|
166
|
+
// isDev && console.log('find', find, 'value', value, data);
|
|
196
167
|
setValue(find, openList);
|
|
197
168
|
}, [data, valueKey, newCreate, newItemCreate, setValue]);
|
|
198
169
|
var checkByInput = useCallback(function () {
|
|
199
|
-
var findByLabel = data.find(function (item) { return
|
|
170
|
+
var findByLabel = data.find(function (item) { var _a; return convertLowerCase(item[labelKey]) === convertLowerCase((_a = refInput.current) === null || _a === void 0 ? void 0 : _a.value); });
|
|
200
171
|
if (findByLabel && value == findByLabel[valueKey]) {
|
|
201
172
|
setOpen(false);
|
|
202
173
|
return;
|
|
@@ -208,127 +179,70 @@ var Component = function (_a, forwardedRef) {
|
|
|
208
179
|
if (onText)
|
|
209
180
|
onText('');
|
|
210
181
|
}
|
|
211
|
-
}, [data, labelKey, value, valueKey, isDataFromApi, onText, setValue]);
|
|
182
|
+
}, [data, labelKey, value, valueKey, isDataFromApi, onText, setValue, refInput.current]);
|
|
212
183
|
var clear = useCallback(function (openList, focusInput) {
|
|
213
184
|
var _a;
|
|
214
185
|
if (openList === void 0) { openList = true; }
|
|
215
186
|
if (focusInput === void 0) { focusInput = false; }
|
|
216
187
|
setFilter('');
|
|
217
188
|
setText('');
|
|
218
|
-
setValue(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (focusInput)
|
|
222
|
-
(_a = refInput === null || refInput === void 0 ? void 0 : refInput.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
189
|
+
setValue(undefined, openList);
|
|
190
|
+
onText && onText('');
|
|
191
|
+
focusInput && ((_a = refInput === null || refInput === void 0 ? void 0 : refInput.current) === null || _a === void 0 ? void 0 : _a.focus());
|
|
223
192
|
}, [setValue, onText]);
|
|
224
|
-
function
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (text_1) {
|
|
229
|
-
position = text_1.offsetTop - 35;
|
|
230
|
-
}
|
|
231
|
-
else if (refList.current.querySelector('li.item.active')) {
|
|
232
|
-
position = refList.current.querySelector('li.item.active').offsetTop - 35;
|
|
233
|
-
}
|
|
234
|
-
refList.current.scrollTop = position;
|
|
193
|
+
var sendChange = useCallback(function (value) {
|
|
194
|
+
// isDev && console.log(name, "sendChange", value, "selectedValue", selectedValue);
|
|
195
|
+
if (onChange && value !== selectedValue) {
|
|
196
|
+
onChange({ target: { name: name, value: value } });
|
|
235
197
|
}
|
|
236
|
-
}
|
|
237
|
-
var
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (text) {
|
|
243
|
-
checkByValue(text.dataset.value);
|
|
244
|
-
}
|
|
245
|
-
else if (refList.current.querySelectorAll('li.item').length > 0) {
|
|
246
|
-
checkByValue(refList.current.querySelectorAll('li.item')[0].dataset.value);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
clear(true, true);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
function selectFirst() {
|
|
253
|
-
var showList = refList.current.querySelectorAll('li.item');
|
|
254
|
-
if (showList.length > 0) {
|
|
255
|
-
showList[0].classList.add('selected');
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
function selectLast() {
|
|
259
|
-
var showList = refList.current.querySelectorAll('li.item');
|
|
260
|
-
if (showList.length > 0) {
|
|
261
|
-
showList[showList.length - 1].classList.add('selected');
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
function selectNext(element) {
|
|
265
|
-
element.classList.remove('selected');
|
|
266
|
-
var next = element.nextElementSibling;
|
|
267
|
-
if (next && next.nodeType !== -1) {
|
|
268
|
-
if (next.classList.contains('item')) {
|
|
269
|
-
next.classList.add('selected');
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
selectNext(next);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
selectFirst();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
function selectPrev(element) {
|
|
280
|
-
element.classList.remove('selected');
|
|
281
|
-
var next = element.previousElementSibling;
|
|
282
|
-
if (next && next.nodeType !== -1) {
|
|
283
|
-
if (next.classList.contains('item')) {
|
|
284
|
-
next.classList.add('selected');
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
selectPrev(next);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
selectLast();
|
|
292
|
-
}
|
|
198
|
+
}, [onChange, name]);
|
|
199
|
+
var filteredData = useMemo(function () {
|
|
200
|
+
var _a;
|
|
201
|
+
var list;
|
|
202
|
+
if (filter.length > 0) {
|
|
203
|
+
list = data.filter(function (item) { return convertForSearch(item[labelKey]).includes(convertForSearch(filter)) || item[labelKey] == filter; });
|
|
293
204
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (selected) {
|
|
297
|
-
selectNext(selected);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
selectFirst();
|
|
301
|
-
}
|
|
205
|
+
else {
|
|
206
|
+
list = data;
|
|
302
207
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
208
|
+
if (newCreate && text.length > 0) {
|
|
209
|
+
var filterText = data.find(function (item) { return item[labelKey].toString().toLowerCase() === text.toString().toLowerCase(); });
|
|
210
|
+
if (!filterText) {
|
|
211
|
+
var newItem = (_a = {}, _a[labelKey] = text, _a[valueKey] = text, _a.create = true, _a);
|
|
212
|
+
list = __spreadArray([newItem], list, true);
|
|
213
|
+
setNewItemCreate(newItem);
|
|
306
214
|
}
|
|
307
215
|
else {
|
|
308
|
-
|
|
216
|
+
if (newItemCreate.create)
|
|
217
|
+
setNewItemCreate({ create: false });
|
|
309
218
|
}
|
|
310
219
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
else if (e.which == 13) {
|
|
318
|
-
selectEnter();
|
|
319
|
-
}
|
|
320
|
-
else if (e.which == 9) {
|
|
321
|
-
checkByInput();
|
|
220
|
+
return list;
|
|
221
|
+
}, [data, filter, newCreate, text, valueKey, labelKey]);
|
|
222
|
+
var handleUpdatePosition = function () {
|
|
223
|
+
if (open && !listPositionRelative && refMain) {
|
|
224
|
+
setFixedPosition(refMain);
|
|
322
225
|
}
|
|
323
|
-
setScrollPosition();
|
|
324
226
|
};
|
|
325
|
-
|
|
227
|
+
var onKeyDown = function (e) {
|
|
228
|
+
if (!open || !refList.current)
|
|
229
|
+
return null;
|
|
230
|
+
onKeyboardSelection({
|
|
231
|
+
e: e,
|
|
232
|
+
targetElement: refList,
|
|
233
|
+
checkByInput: checkByInput,
|
|
234
|
+
checkByValue: checkByValue,
|
|
235
|
+
clear: clear,
|
|
236
|
+
itemClass: 'li.item',
|
|
237
|
+
selectedClass: 'selected'
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
return (_jsxs("div", { ref: refMain, className: styles.searchableInputComponent, onKeyDown: onKeyDown, style: style, children: [_jsx(Input, __assign({}, other, { inputRef: refInput, name: name, value: text, onFocus: function () { return !disabled && setOpen(true); }, onChange: textInputOnChange, 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 || !(data.length > 0), onClick: function () { return !disabled && 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) {
|
|
326
241
|
var itemValue = item[valueKey];
|
|
327
242
|
var itemLabel = item[labelKey];
|
|
328
|
-
return (_jsxs("li", { className: "item ".concat(itemValue ===
|
|
243
|
+
return (_jsxs("li", { className: "item ".concat(itemValue === selectedValue ? '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));
|
|
329
244
|
})] }) }))] }));
|
|
330
|
-
};
|
|
331
|
-
export var SearchableInput = React.forwardRef(Component);
|
|
245
|
+
});
|
|
332
246
|
var setFixedPosition = function (refMain) {
|
|
333
247
|
if (!refMain.current)
|
|
334
248
|
return;
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
border-radius: 6px;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
.component[data-disabled=
|
|
17
|
+
.component[data-disabled='true'] {
|
|
18
18
|
background: #ebebeb;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
.component[data-disabled=
|
|
22
|
-
.component[data-disabled=
|
|
21
|
+
.component[data-disabled='true'],
|
|
22
|
+
.component[data-disabled='true'] * {
|
|
23
23
|
pointer-events: none;
|
|
24
24
|
cursor: not-allowed;
|
|
25
25
|
}
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
color: transparent;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
.component[data-disabled=
|
|
44
|
+
.component[data-disabled='true'] .loading:before {
|
|
45
45
|
background: #ebebeb;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -125,15 +125,15 @@
|
|
|
125
125
|
display: block;
|
|
126
126
|
min-width: 0;
|
|
127
127
|
width: 100%;
|
|
128
|
-
padding:
|
|
128
|
+
padding: 9px 14px;
|
|
129
129
|
border: none;
|
|
130
130
|
outline: none;
|
|
131
131
|
z-index: 1;
|
|
132
132
|
text-overflow: ellipsis;
|
|
133
133
|
border-radius: 6px;
|
|
134
134
|
}
|
|
135
|
-
.input[type=
|
|
136
|
-
.input[type=
|
|
135
|
+
.input[type='number']::-webkit-outer-spin-button,
|
|
136
|
+
.input[type='number']::-webkit-inner-spin-button {
|
|
137
137
|
appearance: none;
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
.loading:before {
|
|
170
170
|
position: absolute;
|
|
171
171
|
display: block;
|
|
172
|
-
content:
|
|
172
|
+
content: '';
|
|
173
173
|
z-index: 12;
|
|
174
174
|
top: 2px;
|
|
175
175
|
left: 2px;
|
|
@@ -182,7 +182,7 @@
|
|
|
182
182
|
.loading:after {
|
|
183
183
|
position: absolute;
|
|
184
184
|
display: block;
|
|
185
|
-
content:
|
|
185
|
+
content: '';
|
|
186
186
|
z-index: 11;
|
|
187
187
|
width: 12px;
|
|
188
188
|
height: 12px;
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED