@sydsoft/base 1.47.0 → 1.49.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/README.md +8 -1
- package/{dist/esm → _dist}/_lib/baseFunctions.d.ts +0 -1
- package/{dist/esm → _dist}/_lib/baseFunctions.js +25 -38
- package/{dist/esm → _dist}/_lib/inputMask.js +66 -69
- package/{dist/esm → _dist}/_lib/listFunctions.js +12 -13
- package/_dist/_lib/storage/cookies.d.ts +4 -0
- package/_dist/_lib/storage/cookies.js +33 -0
- package/_dist/_lib/storage/encData.js +41 -0
- package/{dist/esm → _dist}/_lib/storage/localStorage.js +10 -10
- package/{dist/esm → _dist}/_lib/storage/sessionStorage.js +10 -10
- package/{dist/esm → _dist}/_lib/useInterval.js +5 -5
- package/{dist/esm → _dist}/alert/index.js +28 -30
- package/_dist/box/Box.js +14 -0
- package/_dist/box/BoxContent.js +5 -0
- package/_dist/box/BoxFooter.js +10 -0
- package/_dist/box/BoxHeader.js +10 -0
- package/_dist/countDown/index.js +92 -0
- package/{dist/esm → _dist}/dateTime/index.js +25 -31
- package/_dist/form/Button.js +82 -0
- package/_dist/form/Checkbox.js +22 -0
- package/_dist/form/Dialog.js +53 -0
- package/_dist/form/Form.js +10 -0
- package/_dist/form/FormOlustur.js +50 -0
- package/{dist/esm → _dist}/form/Input.js +57 -56
- package/_dist/form/Label.js +7 -0
- package/{dist/esm → _dist}/form/SearchableInput.d.ts +0 -1
- package/_dist/form/SearchableInput.js +260 -0
- package/_dist/form/UploadBase.js +84 -0
- package/_dist/grid/index.js +96 -0
- package/{dist/esm → _dist}/icon/icons.js +1 -1
- package/{dist/esm → _dist}/icon/index.d.ts +1 -1
- package/_dist/icon/index.js +34 -0
- package/_dist/menu/index.js +50 -0
- package/_dist/modal/index.js +64 -0
- package/{dist/esm → _dist}/popover/index.js +100 -100
- package/_dist/tooltip/index.js +202 -0
- package/_lib/baseFunctions.ts +94 -0
- package/_lib/inputMask.ts +257 -0
- package/_lib/listFunctions.ts +106 -0
- package/_lib/storage/cookies.ts +39 -0
- package/_lib/storage/encData.ts +41 -0
- package/_lib/storage/localStorage.ts +67 -0
- package/_lib/storage/sessionStorage.ts +67 -0
- package/_lib/useInterval.ts +30 -0
- package/alert/index.module.css +119 -0
- package/alert/index.tsx +131 -0
- package/box/Box.module.css +153 -0
- package/box/Box.tsx +33 -0
- package/box/BoxContent.tsx +18 -0
- package/box/BoxFooter.tsx +25 -0
- package/box/BoxHeader.tsx +46 -0
- package/box/index.ts +10 -0
- package/countDown/index.tsx +116 -0
- package/dateTime/index.ts +79 -0
- package/form/Button.tsx +143 -0
- package/form/Checkbox.tsx +48 -0
- package/form/Dialog.tsx +109 -0
- package/form/Form.tsx +19 -0
- package/form/FormOlustur.tsx +105 -0
- package/form/Input.tsx +364 -0
- package/form/Label.tsx +20 -0
- package/form/SearchableInput.tsx +406 -0
- package/form/UploadBase.tsx +133 -0
- package/form/index.ts +10 -0
- package/form/styles/Button.module.css +145 -0
- package/form/styles/Input.module.css +221 -0
- package/form/styles/Label.module.css +31 -0
- package/form/styles/SearchableInput.module.css +80 -0
- package/global.d.ts +9 -0
- package/grid/index.module.css +805 -0
- package/grid/index.tsx +171 -0
- package/icon/icons.tsx +33 -0
- package/icon/index.tsx +95 -0
- package/icon/mui.tsx +5932 -0
- package/index.ts +21 -0
- package/menu/index.module.css +92 -0
- package/menu/index.tsx +143 -0
- package/modal/index.module.css +77 -0
- package/modal/index.tsx +106 -0
- package/npm_recovery_codes.txt +5 -0
- package/package.json +18 -11
- package/popover/index.module.css +89 -0
- package/popover/index.tsx +392 -0
- package/tooltip/index.tsx +216 -0
- package/tsconfig.json +24 -0
- package/dist/esm/_lib/storage/cookies.d.ts +0 -4
- package/dist/esm/_lib/storage/cookies.js +0 -34
- package/dist/esm/_lib/storage/encData.js +0 -43
- package/dist/esm/box/Box.js +0 -15
- package/dist/esm/box/BoxContent.js +0 -7
- package/dist/esm/box/BoxFooter.js +0 -8
- package/dist/esm/box/BoxHeader.js +0 -9
- package/dist/esm/countDown/index.js +0 -97
- package/dist/esm/form/Button.js +0 -76
- package/dist/esm/form/Checkbox.js +0 -23
- package/dist/esm/form/Dialog.js +0 -40
- package/dist/esm/form/Form.js +0 -12
- package/dist/esm/form/FormOlustur.js +0 -52
- package/dist/esm/form/Label.js +0 -9
- package/dist/esm/form/SearchableInput.js +0 -272
- package/dist/esm/form/UploadBase.js +0 -86
- package/dist/esm/grid/index.js +0 -97
- package/dist/esm/icon/index.js +0 -26
- package/dist/esm/menu/index.js +0 -52
- package/dist/esm/modal/index.js +0 -66
- package/dist/esm/tooltip/index.js +0 -119
- /package/{dist/esm → _dist}/_lib/inputMask.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/listFunctions.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/storage/encData.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/storage/localStorage.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/storage/sessionStorage.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/useInterval.d.ts +0 -0
- /package/{dist/esm → _dist}/alert/index.d.ts +0 -0
- /package/{dist/esm → _dist}/alert/index.module.css +0 -0
- /package/{dist/esm → _dist}/box/Box.d.ts +0 -0
- /package/{dist/esm → _dist}/box/Box.module.css +0 -0
- /package/{dist/esm → _dist}/box/BoxContent.d.ts +0 -0
- /package/{dist/esm → _dist}/box/BoxFooter.d.ts +0 -0
- /package/{dist/esm → _dist}/box/BoxHeader.d.ts +0 -0
- /package/{dist/esm → _dist}/box/index.d.ts +0 -0
- /package/{dist/esm → _dist}/box/index.js +0 -0
- /package/{dist/esm → _dist}/countDown/index.d.ts +0 -0
- /package/{dist/esm → _dist}/dateTime/index.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Button.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Checkbox.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Dialog.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Form.d.ts +0 -0
- /package/{dist/esm → _dist}/form/FormOlustur.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Input.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Label.d.ts +0 -0
- /package/{dist/esm → _dist}/form/UploadBase.d.ts +0 -0
- /package/{dist/esm → _dist}/form/index.d.ts +0 -0
- /package/{dist/esm → _dist}/form/index.js +0 -0
- /package/{dist/esm → _dist}/form/styles/Button.module.css +0 -0
- /package/{dist/esm → _dist}/form/styles/Input.module.css +0 -0
- /package/{dist/esm → _dist}/form/styles/Label.module.css +0 -0
- /package/{dist/esm → _dist}/form/styles/SearchableInput.module.css +0 -0
- /package/{dist/esm → _dist}/grid/index.d.ts +0 -0
- /package/{dist/esm → _dist}/grid/index.module.css +0 -0
- /package/{dist/esm → _dist}/icon/icons.d.ts +0 -0
- /package/{dist/esm → _dist}/icon/mui.d.ts +0 -0
- /package/{dist/esm → _dist}/icon/mui.js +0 -0
- /package/{dist/esm → _dist}/index.d.ts +0 -0
- /package/{dist/esm → _dist}/index.js +0 -0
- /package/{dist/esm → _dist}/menu/index.d.ts +0 -0
- /package/{dist/esm → _dist}/menu/index.module.css +0 -0
- /package/{dist/esm → _dist}/modal/index.d.ts +0 -0
- /package/{dist/esm → _dist}/modal/index.module.css +0 -0
- /package/{dist/esm → _dist}/popover/index.d.ts +0 -0
- /package/{dist/esm → _dist}/popover/index.module.css +0 -0
- /package/{dist/esm → _dist}/tooltip/index.d.ts +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
2
|
/**
|
|
4
3
|
* @author : izzetseydaoglu
|
|
@@ -11,60 +10,62 @@ import { applyInputMask } from '../_lib/inputMask';
|
|
|
11
10
|
import { alert_add } from '../alert';
|
|
12
11
|
import { Dialog } from './Dialog';
|
|
13
12
|
import styles from './styles/Input.module.css';
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
useEffect(function () {
|
|
13
|
+
export const Input = ({ componentRef, inputRef, className, propsComponent, propsInput, id, name, value = '', type, label, startAdornment, endAdornment, placeholder, onChange, onFocus, onBlur, onClick, onKeyPress, onKeyUp, onKeyDown, disabled = false, required = false, loading = false, autoFocus = false, select, valueKey = 'value', labelKey = 'label', ilkSec = false, multiline = false, rows = 2, sadeceYazi, sadeceSayi, tumuBuyuk, tumuKucuk, seoCevir, dosyaNoGiris, fileNameGiris, dateGecmisKontrol, autoSelectText, mask = '', maskSettings = {
|
|
14
|
+
clearIfNotMatch: true,
|
|
15
|
+
reverse: false, //Tersten doldurmaya başla, fiyatlar için geçerli
|
|
16
|
+
selectOnFocus: false
|
|
17
|
+
} }) => {
|
|
18
|
+
const refMain = useRef(null);
|
|
19
|
+
const refInput = useRef(null);
|
|
20
|
+
const refLabel = useRef(null);
|
|
21
|
+
const [inputFilled, setInputFilled] = useState(value && value.toString().length > 0);
|
|
22
|
+
const [focus, setFocus] = useState(false);
|
|
23
|
+
useEffect(() => {
|
|
26
24
|
if (inputRef)
|
|
27
25
|
inputRef.current = refInput.current;
|
|
28
26
|
if (componentRef)
|
|
29
27
|
componentRef.current = refMain.current;
|
|
30
28
|
}, [componentRef, inputRef]);
|
|
31
|
-
useEffect(
|
|
29
|
+
useEffect(() => {
|
|
32
30
|
autoSelectText && !select && (refInput === null || refInput === void 0 ? void 0 : refInput.current) && refInput.current.select();
|
|
33
31
|
}, [autoSelectText, select]);
|
|
34
|
-
useEffect(
|
|
32
|
+
useEffect(() => {
|
|
35
33
|
var _a, _b;
|
|
36
|
-
|
|
34
|
+
const filled = String(value) && value.toString().length > 0 ? true : false;
|
|
37
35
|
setInputFilled(filled);
|
|
38
36
|
filled && ((_b = (_a = refMain === null || refMain === void 0 ? void 0 : refMain.current) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.remove(styles.error));
|
|
39
37
|
}, [value]);
|
|
40
|
-
useEffect(
|
|
38
|
+
useEffect(() => {
|
|
41
39
|
// if (type === "number") sadeceSayi = true; //TODO: sadeceSayi burada değiştirelemez ki!!!
|
|
42
40
|
if (select && ilkSec && (value === '' || value === null || value === undefined)) {
|
|
43
41
|
if (select.length) {
|
|
44
|
-
|
|
45
|
-
onChange && onChange({ target: { name
|
|
42
|
+
const ilkItem = select[0][valueKey] ? select[0][valueKey] : '';
|
|
43
|
+
onChange && onChange({ target: { name, value: ilkItem } });
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
}, [select]);
|
|
49
|
-
useEffect(
|
|
47
|
+
useEffect(() => {
|
|
50
48
|
var _a;
|
|
51
49
|
if (typeof window !== 'undefined' && (mask === null || mask === void 0 ? void 0 : mask.length) > 0 && (refInput === null || refInput === void 0 ? void 0 : refInput.current)) {
|
|
52
50
|
(_a = refInput.current) === null || _a === void 0 ? void 0 : _a.setAttribute('autocomplete', 'off');
|
|
53
51
|
}
|
|
54
52
|
if ((mask === null || mask === void 0 ? void 0 : mask.length) > 0 && (refInput === null || refInput === void 0 ? void 0 : refInput.current)) {
|
|
55
|
-
|
|
53
|
+
const maskInstance = applyInputMask(refInput.current, mask, {
|
|
54
|
+
...maskSettings,
|
|
55
|
+
onChange: (masked, clean, e) => {
|
|
56
56
|
if (onChange) {
|
|
57
|
-
onChange({ target: { name
|
|
57
|
+
onChange({ target: { name, value: masked } });
|
|
58
58
|
}
|
|
59
59
|
if (maskSettings && maskSettings.onChange) {
|
|
60
60
|
maskSettings.onChange(masked, clean, e);
|
|
61
61
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
maskInstance === null || maskInstance === void 0 ? void 0 : maskInstance.setValue(value ? value : null);
|
|
65
|
+
return () => maskInstance === null || maskInstance === void 0 ? void 0 : maskInstance.destroy();
|
|
65
66
|
}
|
|
66
67
|
}, [mask]);
|
|
67
|
-
|
|
68
|
+
const Change = useCallback((e) => {
|
|
68
69
|
if (tumuBuyuk)
|
|
69
70
|
inputTumuBuyukCevir(e);
|
|
70
71
|
if (tumuKucuk)
|
|
@@ -74,13 +75,13 @@ export var Input = function (_a) {
|
|
|
74
75
|
setInputFilled(e.target.value.length > 0);
|
|
75
76
|
onChange ? onChange(e) : null;
|
|
76
77
|
}, [onChange, seoCevir, tumuBuyuk, tumuKucuk]);
|
|
77
|
-
|
|
78
|
+
const Focus = useCallback((e) => {
|
|
78
79
|
var _a, _b;
|
|
79
80
|
onFocus ? onFocus(e) : null;
|
|
80
81
|
setFocus(true);
|
|
81
82
|
(_b = (_a = refMain === null || refMain === void 0 ? void 0 : refMain.current) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.remove(styles.error);
|
|
82
83
|
}, [onFocus]);
|
|
83
|
-
|
|
84
|
+
const Blur = useCallback((e) => {
|
|
84
85
|
var _a, _b, _c, _d;
|
|
85
86
|
if (fileNameGiris && e.target.value !== '' && /[/\\?%*:|"'<>]/g.test(e.target.value)) {
|
|
86
87
|
e.target.value = e.target.value.replace(/[/\\?%*:|"'<>]/g, '-');
|
|
@@ -95,11 +96,11 @@ export var Input = function (_a) {
|
|
|
95
96
|
alert_add({ type: 'error', message: 'Lütfen doğru bir dosya numarası giriniz. Örn: 2022/123' });
|
|
96
97
|
}
|
|
97
98
|
if (dateGecmisKontrol && e.target.value !== '') {
|
|
98
|
-
|
|
99
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
99
100
|
if (e.target.value < today) {
|
|
100
101
|
Dialog({
|
|
101
102
|
message: 'Geçmiş bir tarihi seçtiniz. Devam etmek istiyor musunuz?'
|
|
102
|
-
}).then(
|
|
103
|
+
}).then((r) => {
|
|
103
104
|
if (!r) {
|
|
104
105
|
e.target.value = '';
|
|
105
106
|
if (onChange)
|
|
@@ -118,15 +119,15 @@ export var Input = function (_a) {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
if (value !== e.target.value) {
|
|
121
|
-
onChange && onChange({ target: { name
|
|
122
|
+
onChange && onChange({ target: { name, value: e.target.value } });
|
|
122
123
|
}
|
|
123
124
|
onBlur ? onBlur(e) : null;
|
|
124
125
|
setFocus(false);
|
|
125
126
|
}, [fileNameGiris, dosyaNoGiris, dateGecmisKontrol, required, value, onBlur, onChange, name]);
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
const Click = useCallback((e) => (onClick ? onClick(e) : null), [onClick]);
|
|
128
|
+
const KeyPress = useCallback((e) => {
|
|
128
129
|
if (sadeceYazi) {
|
|
129
|
-
|
|
130
|
+
const turkishLetters = /[ğüşıöçĞÜŞİÖÇ]/;
|
|
130
131
|
if (!(/[A-Za-z\s.]/.test(e.key) || turkishLetters.test(e.key))) {
|
|
131
132
|
e.preventDefault();
|
|
132
133
|
return;
|
|
@@ -139,19 +140,19 @@ export var Input = function (_a) {
|
|
|
139
140
|
}
|
|
140
141
|
onKeyPress ? onKeyPress(e) : null;
|
|
141
142
|
}, [sadeceYazi, sadeceSayi, dosyaNoGiris, onKeyPress]);
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
const KeyUp = useCallback((e) => (onKeyUp ? onKeyUp(e) : null), [onKeyUp]);
|
|
144
|
+
const KeyDown = useCallback((e) => {
|
|
144
145
|
onKeyDown ? onKeyDown(e) : null;
|
|
145
146
|
}, [onKeyDown]);
|
|
146
|
-
|
|
147
|
+
const ortakProps = {
|
|
147
148
|
ref: refInput,
|
|
148
|
-
id
|
|
149
|
-
name
|
|
150
|
-
value
|
|
151
|
-
autoFocus
|
|
152
|
-
disabled
|
|
153
|
-
required
|
|
154
|
-
placeholder
|
|
149
|
+
id,
|
|
150
|
+
name,
|
|
151
|
+
value,
|
|
152
|
+
autoFocus,
|
|
153
|
+
disabled,
|
|
154
|
+
required,
|
|
155
|
+
placeholder,
|
|
155
156
|
onChange: Change,
|
|
156
157
|
onFocus: Focus,
|
|
157
158
|
onBlur: Blur,
|
|
@@ -160,22 +161,22 @@ export var Input = function (_a) {
|
|
|
160
161
|
onKeyUp: KeyUp,
|
|
161
162
|
onKeyDown: KeyDown
|
|
162
163
|
};
|
|
163
|
-
|
|
164
|
+
let component;
|
|
164
165
|
if (select) {
|
|
165
|
-
component = (_jsxs("select",
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
component = (_jsxs("select", { className: `${styles.input} ${styles.select}`, ...ortakProps, ...propsInput, children: [ilkSec === false && _jsx("option", { value: '' }), select.map((item) => {
|
|
167
|
+
const value = item[valueKey];
|
|
168
|
+
const label = item[labelKey];
|
|
168
169
|
return (_jsx("option", { value: value, children: label ? label : value }, value));
|
|
169
|
-
})] }))
|
|
170
|
+
})] }));
|
|
170
171
|
}
|
|
171
172
|
else if (multiline) {
|
|
172
|
-
component = _jsx("textarea",
|
|
173
|
+
component = _jsx("textarea", { className: `${styles.input} ${styles.textarea}`, rows: rows, ...ortakProps, ...propsInput });
|
|
173
174
|
}
|
|
174
175
|
else {
|
|
175
|
-
component = _jsx("input",
|
|
176
|
+
component = _jsx("input", { className: `${styles.input}`, type: type, ...ortakProps, ...propsInput });
|
|
176
177
|
}
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
const classList = () => {
|
|
179
|
+
const list = ['sInputComponent', styles.component];
|
|
179
180
|
if (className)
|
|
180
181
|
list.push(className);
|
|
181
182
|
if (label) {
|
|
@@ -184,13 +185,13 @@ export var Input = function (_a) {
|
|
|
184
185
|
// if (props.required && (value.length === 0 || !value)) list.push("error");
|
|
185
186
|
return list.join(' ');
|
|
186
187
|
};
|
|
187
|
-
useEffect(
|
|
188
|
+
useEffect(() => {
|
|
188
189
|
if (propsComponent && propsComponent.hasOwnProperty('style')) {
|
|
189
|
-
|
|
190
|
+
const background = propsComponent.style.background ? propsComponent.style.background : propsComponent.style.backgroundColor ? propsComponent.style.backgroundColor : null;
|
|
190
191
|
if (background && refLabel.current) {
|
|
191
192
|
refLabel.current.style.setProperty('--label-bg', background);
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
}, [propsComponent]);
|
|
195
|
-
return (_jsxs("div",
|
|
196
|
+
return (_jsxs("div", { ref: refMain, className: classList(), "data-disabled": disabled, ...propsComponent, children: [startAdornment && _jsx("div", { className: `adornment_start ${styles.adornment} ${styles.start}`, children: startAdornment }), _jsxs("div", { className: `${styles.inputBase} ${inputFilled || focus || type == 'date' ? styles.open : ''}`, children: [component, label && (_jsxs("div", { ref: refLabel, className: `label ${styles.label}`, children: [label, required && _jsx("span", { className: styles.required, children: "*" })] }))] }), (endAdornment || loading) && (_jsxs("div", { className: `adornment_end ${styles.adornment} ${styles.end}`, children: [endAdornment, loading && _jsx("div", { className: styles.loading })] }))] }));
|
|
196
197
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { Tooltip } from '../tooltip';
|
|
4
|
+
import styles from './styles/Label.module.css';
|
|
5
|
+
export const Label = memo(function FMemo({ required = false, children, ...other }) {
|
|
6
|
+
return (_jsxs("label", { className: styles.label, ...other, children: [children, _jsx(Tooltip, { title: 'Zorunlu Alan', children: _jsx("span", { className: styles.required, children: required && '*' }) })] }));
|
|
7
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Input } from './index';
|
|
3
|
+
import { convertForSearch, convertLowerCase } from '../_lib/baseFunctions';
|
|
4
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { onKeyboardSelection, setScrollListPosition } from '../_lib/listFunctions';
|
|
6
|
+
import { Icon } from '../icon';
|
|
7
|
+
import styles from './styles/SearchableInput.module.css';
|
|
8
|
+
export const SearchableInput = forwardRef(({ autoCompleteList = [], isDataFromApi, name, value, parentInputValue, disabled, itemComponent, valueKey = 'value', labelKey = 'label', onSelect, onChange, onText, onLoad, style, listPositionRelative = false, loadingMessage = 'Lütfen bekleyiniz...', notFoundMessage = 'Kayıt bulunamadı...', placeholder, endAdornment, ilkSec = false, newCreate = false, inputRef, ...other }, ref) => {
|
|
9
|
+
const refMain = useRef(null);
|
|
10
|
+
const refInput = useRef(null);
|
|
11
|
+
const refList = useRef(null);
|
|
12
|
+
const [data, setData] = useState(autoCompleteList !== null && autoCompleteList !== void 0 ? autoCompleteList : []);
|
|
13
|
+
const [selectedValue, setSelectedValue] = useState(value !== null && value !== void 0 ? value : undefined);
|
|
14
|
+
const [parentValue, setParentValue] = useState(parentInputValue !== null && parentInputValue !== void 0 ? parentInputValue : undefined);
|
|
15
|
+
const [text, setText] = useState(''); //Inputta görünen
|
|
16
|
+
const [filter, setFilter] = useState(''); // Filtrelemeye tabi tutulan
|
|
17
|
+
const [newItemCreate, setNewItemCreate] = useState({ created: false });
|
|
18
|
+
const [open, setOpen] = useState(false);
|
|
19
|
+
const [loading, setLoading] = useState(isDataFromApi && (!autoCompleteList || (autoCompleteList === null || autoCompleteList === void 0 ? void 0 : autoCompleteList.length) == 0));
|
|
20
|
+
useImperativeHandle(ref, () => ({
|
|
21
|
+
setAutoCompleteList: (list, value = undefined, callback) => {
|
|
22
|
+
if (autoCompleteList && (autoCompleteList === null || autoCompleteList === void 0 ? void 0 : autoCompleteList.length) > 0) {
|
|
23
|
+
alert('AutoCompleteList zaten tanımlı olduğundan dışardan data seti değiştirilemez.');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
setData(list);
|
|
27
|
+
value && sendChange(value);
|
|
28
|
+
setLoading(false);
|
|
29
|
+
if (!Array.isArray(list) || list.length == 0) {
|
|
30
|
+
clear(false);
|
|
31
|
+
}
|
|
32
|
+
callback && callback();
|
|
33
|
+
// isDev && console.log("setAutoCompleteList =>", name, value, list);
|
|
34
|
+
},
|
|
35
|
+
clear: (openList = false, focusInput = false) => clear(openList, focusInput),
|
|
36
|
+
open: () => {
|
|
37
|
+
setOpen(true);
|
|
38
|
+
refInput.current && refInput.current.focus();
|
|
39
|
+
},
|
|
40
|
+
close: () => setOpen(false),
|
|
41
|
+
checkByValue: (value, openList = false) => checkByValue(value, openList),
|
|
42
|
+
setLoading: (value) => setLoading(value)
|
|
43
|
+
}), [autoCompleteList, data, value]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (inputRef)
|
|
46
|
+
inputRef.current = refInput.current;
|
|
47
|
+
}, [refInput.current]);
|
|
48
|
+
useEffect(() => onLoad && onLoad(value), []);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (autoCompleteList && Array.isArray(autoCompleteList)) {
|
|
51
|
+
if (autoCompleteList.length > 0) {
|
|
52
|
+
// Sadece gerçekten farklıysa set et
|
|
53
|
+
if (JSON.stringify(autoCompleteList) !== JSON.stringify(data)) {
|
|
54
|
+
setData(autoCompleteList);
|
|
55
|
+
// isDev && console.log("autoCompleteList dolu =>", name, autoCompleteList);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// Boş array geldi VE data zaten boş değilse
|
|
60
|
+
if (data.length > 0) {
|
|
61
|
+
setData([]);
|
|
62
|
+
// isDev && console.log("autoCompleteList boşaltıldı =>", name);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, [autoCompleteList]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
// isDev && console.log('data =>', name, data, 'selectedValue =>', selectedValue, 'value =>', value);
|
|
69
|
+
if (!Array.isArray(data)) {
|
|
70
|
+
setData([]);
|
|
71
|
+
}
|
|
72
|
+
if (data.length > 0) {
|
|
73
|
+
setLoading(false);
|
|
74
|
+
checkByValue(selectedValue, open);
|
|
75
|
+
if (!value && ilkSec) {
|
|
76
|
+
checkByValue(data[0][valueKey], false);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
!isDataFromApi && clear(false);
|
|
81
|
+
}
|
|
82
|
+
}, [data]);
|
|
83
|
+
// Seçim değişikliğinde parent'ı bilgilendir
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
// isDev && console.log('selectedValue =>', name, selectedValue, 'value =>', value);
|
|
86
|
+
if ((value === null || value === void 0 ? void 0 : value.toString()) != (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.toString())) {
|
|
87
|
+
checkByValue(value, open);
|
|
88
|
+
// isDev && console.log('value Kontrol ediliyor', value, selectedValue);
|
|
89
|
+
}
|
|
90
|
+
}, [value]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (parentInputValue !== parentValue) {
|
|
93
|
+
setParentValue(parentInputValue);
|
|
94
|
+
clear(false);
|
|
95
|
+
// isDev && console.log(name, "parentInputValueDeğişti =>", parentInputValue);
|
|
96
|
+
}
|
|
97
|
+
}, [parentInputValue]);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const checkHideBackDrop = (e) => {
|
|
100
|
+
if (open && refMain.current && !refMain.current.contains(e.target)) {
|
|
101
|
+
checkByInput();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const checkESC = (e) => {
|
|
105
|
+
if (e.keyCode === 27 || e.key === 'Escape' || e.code === 'Escape')
|
|
106
|
+
checkByInput();
|
|
107
|
+
};
|
|
108
|
+
window.addEventListener('mousedown', checkHideBackDrop);
|
|
109
|
+
if (refMain.current)
|
|
110
|
+
refMain.current.addEventListener('keydown', checkESC);
|
|
111
|
+
if (open) {
|
|
112
|
+
setScrollListPosition(refList);
|
|
113
|
+
if (!listPositionRelative) {
|
|
114
|
+
window.addEventListener('scroll', handleUpdatePosition, true);
|
|
115
|
+
window.addEventListener('resize', handleUpdatePosition);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return () => {
|
|
119
|
+
window.removeEventListener('mousedown', checkHideBackDrop);
|
|
120
|
+
if (refMain.current)
|
|
121
|
+
refMain.current.removeEventListener('keydown', checkESC);
|
|
122
|
+
window.removeEventListener('scroll', handleUpdatePosition, true);
|
|
123
|
+
window.removeEventListener('resize', handleUpdatePosition);
|
|
124
|
+
};
|
|
125
|
+
}, [open]);
|
|
126
|
+
useLayoutEffect(() => handleUpdatePosition(), [open]);
|
|
127
|
+
const setValue = useCallback((item, openList) => {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
const newValue = (_a = item === null || item === void 0 ? void 0 : item[valueKey]) !== null && _a !== void 0 ? _a : '';
|
|
130
|
+
const newLabel = (_b = item === null || item === void 0 ? void 0 : item[labelKey]) !== null && _b !== void 0 ? _b : '';
|
|
131
|
+
setOpen(openList);
|
|
132
|
+
setText(newLabel);
|
|
133
|
+
// isDev && console.log(name, "setValue", newValue, "item", item, "value", value);
|
|
134
|
+
if (newValue === selectedValue)
|
|
135
|
+
return;
|
|
136
|
+
setFilter('');
|
|
137
|
+
setSelectedValue(newValue);
|
|
138
|
+
onChange && sendChange(newValue);
|
|
139
|
+
onSelect && onSelect(item);
|
|
140
|
+
}, [onChange, onSelect, name, selectedValue, valueKey, labelKey]);
|
|
141
|
+
const textInputOnChange = useCallback((e) => {
|
|
142
|
+
setSelectedValue(undefined);
|
|
143
|
+
setText(e.target.value);
|
|
144
|
+
setFilter(e.target.value.trim());
|
|
145
|
+
setOpen(true);
|
|
146
|
+
onText && onText(e.target.value);
|
|
147
|
+
}, [setValue, onText]);
|
|
148
|
+
const checkByValue = useCallback((value, openList = false, list = []) => {
|
|
149
|
+
const targetList = list.length > 0 ? list : data;
|
|
150
|
+
let find = Object.values(targetList).find((item) => convertLowerCase(item[valueKey]) === convertLowerCase(value));
|
|
151
|
+
if (!find && newCreate && newItemCreate.create) {
|
|
152
|
+
find = newItemCreate;
|
|
153
|
+
}
|
|
154
|
+
// isDev && console.log('find', find, 'value', value, data);
|
|
155
|
+
setValue(find, openList);
|
|
156
|
+
}, [data, valueKey, newCreate, newItemCreate, setValue]);
|
|
157
|
+
const checkByInput = useCallback(() => {
|
|
158
|
+
const findByLabel = data.find((item) => { var _a; return convertLowerCase(item[labelKey]) === convertLowerCase((_a = refInput.current) === null || _a === void 0 ? void 0 : _a.value); });
|
|
159
|
+
if (findByLabel && value == findByLabel[valueKey]) {
|
|
160
|
+
setOpen(false);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
setValue(findByLabel, false);
|
|
164
|
+
if (!findByLabel)
|
|
165
|
+
setText('');
|
|
166
|
+
if (isDataFromApi && !findByLabel && data.length === 0) {
|
|
167
|
+
if (onText)
|
|
168
|
+
onText('');
|
|
169
|
+
}
|
|
170
|
+
}, [data, labelKey, value, valueKey, isDataFromApi, onText, setValue, refInput.current]);
|
|
171
|
+
const clear = useCallback((openList = true, focusInput = false) => {
|
|
172
|
+
var _a;
|
|
173
|
+
setFilter('');
|
|
174
|
+
setText('');
|
|
175
|
+
setValue(undefined, openList);
|
|
176
|
+
onText && onText('');
|
|
177
|
+
focusInput && ((_a = refInput === null || refInput === void 0 ? void 0 : refInput.current) === null || _a === void 0 ? void 0 : _a.focus());
|
|
178
|
+
}, [setValue, onText]);
|
|
179
|
+
const sendChange = useCallback((value) => {
|
|
180
|
+
// isDev && console.log(name, "sendChange", value, "selectedValue", selectedValue);
|
|
181
|
+
if (onChange && value !== selectedValue) {
|
|
182
|
+
onChange({ target: { name, value } });
|
|
183
|
+
}
|
|
184
|
+
}, [onChange, name]);
|
|
185
|
+
const filteredData = useMemo(() => {
|
|
186
|
+
let list;
|
|
187
|
+
if (filter.length > 0) {
|
|
188
|
+
list = data.filter((item) => convertForSearch(item[labelKey]).includes(convertForSearch(filter)) || item[labelKey] == filter);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
list = data;
|
|
192
|
+
}
|
|
193
|
+
if (newCreate && text.length > 0) {
|
|
194
|
+
const filterText = data.find((item) => item[labelKey].toString().toLowerCase() === text.toString().toLowerCase());
|
|
195
|
+
if (!filterText) {
|
|
196
|
+
const newItem = { [labelKey]: text, [valueKey]: text, create: true };
|
|
197
|
+
list = [newItem, ...list];
|
|
198
|
+
setNewItemCreate(newItem);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
if (newItemCreate.create)
|
|
202
|
+
setNewItemCreate({ create: false });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return list;
|
|
206
|
+
}, [data, filter, newCreate, text, valueKey, labelKey]);
|
|
207
|
+
const handleUpdatePosition = () => {
|
|
208
|
+
if (open && !listPositionRelative && refMain) {
|
|
209
|
+
setFixedPosition(refMain);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
const onKeyDown = (e) => {
|
|
213
|
+
if (!open || !refList.current)
|
|
214
|
+
return null;
|
|
215
|
+
onKeyboardSelection({
|
|
216
|
+
e,
|
|
217
|
+
targetElement: refList,
|
|
218
|
+
checkByInput,
|
|
219
|
+
checkByValue,
|
|
220
|
+
clear,
|
|
221
|
+
itemClass: 'li.item',
|
|
222
|
+
selectedClass: 'selected'
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
return (_jsxs("div", { ref: refMain, className: styles.searchableInputComponent, onKeyDown: onKeyDown, style: style, children: [_jsx(Input, { ...other, inputRef: refInput, name: name, value: text, onFocus: () => !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: () => clear(true, true), onlyIcon: _jsx(Icon, { name: 'close', style: { color: '#444' } }) }), endAdornment, _jsx(Button, { tabIndex: -1, hidden: !data || !(data.length > 0), onClick: () => !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: {
|
|
226
|
+
...other === null || other === void 0 ? void 0 : other.propsInput,
|
|
227
|
+
autoComplete: 'off'
|
|
228
|
+
} }), open && (_jsx("div", { className: 'listDiv', "data-relative": listPositionRelative, children: _jsxs("ul", { ref: refList, className: `list ${open ? 'open' : ''}`, children: [(filteredData.length === 0 || loading) && _jsx("div", { className: `message ${loading ? 'loading' : ''}`, children: loading ? loadingMessage : notFoundMessage }), filteredData.map((item, key) => {
|
|
229
|
+
const itemValue = item[valueKey];
|
|
230
|
+
const itemLabel = item[labelKey];
|
|
231
|
+
return (_jsxs("li", { className: `item ${itemValue === selectedValue ? 'active' : ''}`, "data-value": itemValue, "data-label": itemLabel, onClick: () => setValue(item, false), children: [item.create && _jsx("span", { className: 'newCreate', children: "Yeni Olu\u015Ftur: " }), itemComponent ? itemComponent(item) : itemLabel] }, key));
|
|
232
|
+
})] }) }))] }));
|
|
233
|
+
});
|
|
234
|
+
const setFixedPosition = (refMain) => {
|
|
235
|
+
if (!refMain.current)
|
|
236
|
+
return;
|
|
237
|
+
const target = refMain.current;
|
|
238
|
+
const targetPosition = target.getBoundingClientRect();
|
|
239
|
+
const listDiv = target.querySelector('.listDiv');
|
|
240
|
+
if (listDiv) {
|
|
241
|
+
const listDivUL = target.querySelector('ul');
|
|
242
|
+
if (!listDiv)
|
|
243
|
+
return;
|
|
244
|
+
const listHeight = listDivUL.getBoundingClientRect().height;
|
|
245
|
+
const style = [];
|
|
246
|
+
style.push(`position:fixed`);
|
|
247
|
+
style.push(`z-index:111111111111 !important`);
|
|
248
|
+
style.push(`width:${targetPosition.width}px`);
|
|
249
|
+
const spaceBelow = window.innerHeight - (targetPosition.top + targetPosition.height);
|
|
250
|
+
const spaceAbove = targetPosition.top;
|
|
251
|
+
if (spaceBelow < listHeight && spaceAbove > listHeight) {
|
|
252
|
+
style.push(`top:${targetPosition.top - listHeight}px`);
|
|
253
|
+
style.push(`margin-top:-1px`);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
style.push(`top:${targetPosition.top + targetPosition.height}px`);
|
|
257
|
+
}
|
|
258
|
+
listDiv.setAttribute('style', style.join(';'));
|
|
259
|
+
}
|
|
260
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024
|
|
4
|
+
* @author: izzetseydaoglu
|
|
5
|
+
* @last-modified: 11.06.2024 02:39
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect, useRef } from "react";
|
|
8
|
+
import { alert_add } from "../alert";
|
|
9
|
+
const upload_ext_ok = ["pdf", "doc", "docx", "xls", "xlsx", "jpg", "jpeg", "png", "bmp", "tiff", "tif", "udf", "txt", "rtf", "csv", "xml", "zip", "rar"];
|
|
10
|
+
const upload_maxsize = 30;
|
|
11
|
+
const upload_maxfile = 50;
|
|
12
|
+
export const UploadBase = ({ component = "div", children, targetForm, onChange, name = "file__", required = true, multiple = false, maxSize = upload_maxsize, maxFile = upload_maxfile, ext_ok = upload_ext_ok, style, className, refUploadInput = null, label }) => {
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (refUploadInput)
|
|
16
|
+
refUploadInput.current = ref.current;
|
|
17
|
+
}, [ref.current]);
|
|
18
|
+
const fileSelected = (e) => {
|
|
19
|
+
if (!(e.target.files.length > 0)) {
|
|
20
|
+
e.target.value = null;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (e.target.files.length > maxFile) {
|
|
24
|
+
alert_add({ type: "error", message: "En fazla " + maxFile + " dosya seçebilirsiniz." });
|
|
25
|
+
e.target.value = null;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const fileList = [];
|
|
29
|
+
Object.values(e.target.files).map((file) => {
|
|
30
|
+
const size = file.size;
|
|
31
|
+
const ext = file.name.replace(/^.*\./, "").toLowerCase();
|
|
32
|
+
if (ext_ok.indexOf(ext) === -1) {
|
|
33
|
+
alert_add({ type: "error", message: "Yüklemeye çalıştığınız dosya türü desteklenmiyor. Desteklenen dosya türleri: " + ext_ok.join(", ") });
|
|
34
|
+
}
|
|
35
|
+
else if (size > maxSize * 1000000) {
|
|
36
|
+
alert_add({ type: "error", message: "En fazla " + maxSize + "MB büyüklüğündeki dosyaları seçebilirsiniz." });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
fileList.push(file);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (onChange)
|
|
43
|
+
onChange(fileList);
|
|
44
|
+
if (targetForm) {
|
|
45
|
+
const nameList = [];
|
|
46
|
+
let newform = {};
|
|
47
|
+
let uniqueID = new Date().getTime();
|
|
48
|
+
fileList.map((file) => {
|
|
49
|
+
uniqueID = uniqueID + 1;
|
|
50
|
+
newform = { ...newform, [name + uniqueID]: file };
|
|
51
|
+
nameList.push(file.name);
|
|
52
|
+
});
|
|
53
|
+
targetForm((prev) => ({
|
|
54
|
+
...prev,
|
|
55
|
+
uploadBaseList: { ...newform },
|
|
56
|
+
uploadBaseListName: nameList.join(", ")
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const defaultStyle = {
|
|
61
|
+
position: "relative",
|
|
62
|
+
cursor: "pointer"
|
|
63
|
+
};
|
|
64
|
+
const Component = component.toLowerCase();
|
|
65
|
+
return (_jsxs(Component, { className: className, style: { ...defaultStyle, ...style }, "data-label": label !== null && label !== void 0 ? label : "", children: [children, _jsx("input", { ref: ref, type: "file", required: required, onChange: fileSelected, multiple: multiple, accept: ext_ok.map((i) => "." + i).join(","), style: {
|
|
66
|
+
position: "absolute",
|
|
67
|
+
top: 0,
|
|
68
|
+
left: 0,
|
|
69
|
+
opacity: 0,
|
|
70
|
+
width: "100%",
|
|
71
|
+
height: "100%",
|
|
72
|
+
cursor: "pointer",
|
|
73
|
+
zIndex: 1
|
|
74
|
+
} })] }));
|
|
75
|
+
};
|
|
76
|
+
export const uploadBase_CreateForm = (formData) => {
|
|
77
|
+
var _a;
|
|
78
|
+
let newform = { ...formData };
|
|
79
|
+
const list = (_a = formData["uploadBaseList"]) !== null && _a !== void 0 ? _a : {};
|
|
80
|
+
Object.keys(list).map((fileKey) => (newform = { ...newform, [fileKey]: list[fileKey] }));
|
|
81
|
+
delete newform["uploadBaseList"];
|
|
82
|
+
delete newform["uploadBaseListName"];
|
|
83
|
+
return newform;
|
|
84
|
+
};
|