px-react-ui-components 1.0.26 → 1.0.28
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/components/MyInput/MyInput.js +172 -56
- package/package.json +1 -1
|
@@ -88,6 +88,9 @@ function MyInput({
|
|
|
88
88
|
const [isError, setIsError] = (0, _react.useState)(false);
|
|
89
89
|
const [isTyping, setIsTyping] = (0, _react.useState)(false);
|
|
90
90
|
const typingTimeoutRef = (0, _react.useRef)(null);
|
|
91
|
+
|
|
92
|
+
// MONEY input için display value (formatlanmış hali)
|
|
93
|
+
const [displayValue, setDisplayValue] = (0, _react.useState)(null);
|
|
91
94
|
const toBase64 = file => new Promise((resolve, reject) => {
|
|
92
95
|
const reader = new FileReader();
|
|
93
96
|
reader.readAsDataURL(file);
|
|
@@ -105,52 +108,34 @@ function MyInput({
|
|
|
105
108
|
return `${size.toFixed(2)} ${units[unitIndex]}`;
|
|
106
109
|
};
|
|
107
110
|
const moneyFormat = _value => {
|
|
108
|
-
|
|
109
|
-
let inputValue = _value;
|
|
110
|
-
if (inputValue == null || inputValue == undefined || inputValue == '') return money;
|
|
111
|
+
if (_value == null || _value == undefined || _value == '') return '';
|
|
111
112
|
try {
|
|
112
|
-
inputValue =
|
|
113
|
-
// Tüm virgülleri kaldır ve son girilen karakteri kontrol et
|
|
114
|
-
money = inputValue.replace(/,/g, '');
|
|
115
|
-
const lastChar = inputValue.slice(-1);
|
|
116
|
-
if (lastChar === ',') {
|
|
117
|
-
money = money + '.';
|
|
118
|
-
}
|
|
113
|
+
let inputValue = _value.toString();
|
|
119
114
|
|
|
120
|
-
// Sadece sayılar ve
|
|
121
|
-
|
|
115
|
+
// Sadece sayılar ve nokta
|
|
116
|
+
inputValue = inputValue.replace(/[^0-9.]/g, '');
|
|
122
117
|
|
|
123
118
|
// Birden fazla nokta varsa ilkini koru
|
|
124
|
-
const parts =
|
|
119
|
+
const parts = inputValue.split('.');
|
|
125
120
|
if (parts.length > 2) {
|
|
126
|
-
|
|
121
|
+
inputValue = parts[0] + '.' + parts.slice(1).join('');
|
|
127
122
|
}
|
|
128
123
|
|
|
129
|
-
// Noktadan sonra
|
|
124
|
+
// Noktadan sonra maksimum decimal count
|
|
130
125
|
if (parts.length === 2 && parts[1].length > decimalCount) {
|
|
131
|
-
|
|
126
|
+
inputValue = parts[0] + '.' + parts[1].substring(0, decimalCount);
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
// Binlik
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// Sayıyı önce tam sayıya çevir, sonra binlik ayracı ekle
|
|
139
|
-
numParts[0] = parseInt(numParts[0], 10).toLocaleString('en-US');
|
|
140
|
-
}
|
|
141
|
-
money = numParts.join('.');
|
|
142
|
-
}
|
|
143
|
-
const numParts = money.split('.');
|
|
144
|
-
if (numParts[0]) {
|
|
145
|
-
numParts[0] = numParts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
129
|
+
// Binlik ayıracı ekle (sadece tam sayı kısmına)
|
|
130
|
+
const finalParts = inputValue.split('.');
|
|
131
|
+
if (finalParts[0]) {
|
|
132
|
+
finalParts[0] = finalParts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
146
133
|
}
|
|
147
|
-
|
|
134
|
+
return finalParts.join('.');
|
|
148
135
|
} catch (error) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
console.error(error);
|
|
136
|
+
console.error('Money format error:', error);
|
|
137
|
+
return '';
|
|
152
138
|
}
|
|
153
|
-
return money;
|
|
154
139
|
};
|
|
155
140
|
const onMyBlur = e => {
|
|
156
141
|
setIsError(false);
|
|
@@ -170,48 +155,116 @@ function MyInput({
|
|
|
170
155
|
break;
|
|
171
156
|
}
|
|
172
157
|
}
|
|
173
|
-
|
|
174
|
-
|
|
158
|
+
|
|
159
|
+
// MONEY input için formatlanmış değeri kullan
|
|
160
|
+
if (type === MyInputType.MONEY) {
|
|
161
|
+
// Çıkışta decimal kısmını düzenle (sadece görsel)
|
|
162
|
+
let formattedValue = myValue;
|
|
163
|
+
if (formattedValue && formattedValue !== '') {
|
|
164
|
+
const numValue = parseFloat(formattedValue);
|
|
165
|
+
if (!isNaN(numValue)) {
|
|
166
|
+
formattedValue = numValue.toFixed(decimalCount);
|
|
167
|
+
// Sadece display value'yu güncelle, myValue'yu değiştirme
|
|
168
|
+
setDisplayValue(formattedValue);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const finalFormattedValue = moneyFormat(formattedValue);
|
|
172
|
+
e.target.value = finalFormattedValue;
|
|
173
|
+
e.value = finalFormattedValue;
|
|
174
|
+
} else {
|
|
175
|
+
e.target.value = myValue;
|
|
176
|
+
e.value = myValue;
|
|
177
|
+
}
|
|
175
178
|
if (onBlur != null) onBlur(e);
|
|
176
179
|
};
|
|
177
180
|
const onMyFocus = e => {
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
// MONEY input için formatlanmış değeri kullan
|
|
182
|
+
if (type === MyInputType.MONEY) {
|
|
183
|
+
// Focus'ta displayValue'yu temizle, orijinal değere dön
|
|
184
|
+
setDisplayValue(null);
|
|
185
|
+
e.target.value = moneyFormat(myValue);
|
|
186
|
+
e.value = moneyFormat(myValue);
|
|
187
|
+
} else {
|
|
188
|
+
e.target.value = myValue;
|
|
189
|
+
e.value = myValue;
|
|
190
|
+
}
|
|
180
191
|
if (onFocus != null) onFocus(e);
|
|
181
192
|
};
|
|
182
193
|
const onMyKeyDown = e => {
|
|
183
|
-
|
|
184
|
-
|
|
194
|
+
// MONEY input için formatlanmış değeri kullan
|
|
195
|
+
if (type === MyInputType.MONEY) {
|
|
196
|
+
e.target.value = moneyFormat(myValue);
|
|
197
|
+
e.value = moneyFormat(myValue);
|
|
198
|
+
} else {
|
|
199
|
+
e.target.value = myValue;
|
|
200
|
+
e.value = myValue;
|
|
201
|
+
}
|
|
185
202
|
if (onKeyDown != null) onKeyDown(e);
|
|
186
203
|
};
|
|
187
204
|
const onMyKeyUp = e => {
|
|
188
|
-
|
|
189
|
-
|
|
205
|
+
// MONEY input için formatlanmış değeri kullan
|
|
206
|
+
if (type === MyInputType.MONEY) {
|
|
207
|
+
e.target.value = moneyFormat(myValue);
|
|
208
|
+
e.value = moneyFormat(myValue);
|
|
209
|
+
} else {
|
|
210
|
+
e.target.value = myValue;
|
|
211
|
+
e.value = myValue;
|
|
212
|
+
}
|
|
190
213
|
if (onKeyUp != null) onKeyUp(e);
|
|
191
214
|
};
|
|
192
215
|
const onMyKeyPress = e => {
|
|
193
|
-
|
|
194
|
-
|
|
216
|
+
// MONEY input için formatlanmış değeri kullan
|
|
217
|
+
if (type === MyInputType.MONEY) {
|
|
218
|
+
e.target.value = moneyFormat(myValue);
|
|
219
|
+
e.value = moneyFormat(myValue);
|
|
220
|
+
} else {
|
|
221
|
+
e.target.value = myValue;
|
|
222
|
+
e.value = myValue;
|
|
223
|
+
}
|
|
195
224
|
if (onKeyPress != null) onKeyPress(e);
|
|
196
225
|
};
|
|
197
226
|
const onMyMouseDown = e => {
|
|
198
|
-
|
|
199
|
-
|
|
227
|
+
// MONEY input için formatlanmış değeri kullan
|
|
228
|
+
if (type === MyInputType.MONEY) {
|
|
229
|
+
e.target.value = moneyFormat(myValue);
|
|
230
|
+
e.value = moneyFormat(myValue);
|
|
231
|
+
} else {
|
|
232
|
+
e.target.value = myValue;
|
|
233
|
+
e.value = myValue;
|
|
234
|
+
}
|
|
200
235
|
if (onMouseDown != null) onMouseDown(e);
|
|
201
236
|
};
|
|
202
237
|
const onMyMouseUp = e => {
|
|
203
|
-
|
|
204
|
-
|
|
238
|
+
// MONEY input için formatlanmış değeri kullan
|
|
239
|
+
if (type === MyInputType.MONEY) {
|
|
240
|
+
e.target.value = moneyFormat(myValue);
|
|
241
|
+
e.value = moneyFormat(myValue);
|
|
242
|
+
} else {
|
|
243
|
+
e.target.value = myValue;
|
|
244
|
+
e.value = myValue;
|
|
245
|
+
}
|
|
205
246
|
if (onMouseUp != null) onMouseUp(e);
|
|
206
247
|
};
|
|
207
248
|
const onMyMouseEnter = e => {
|
|
208
|
-
|
|
209
|
-
|
|
249
|
+
// MONEY input için formatlanmış değeri kullan
|
|
250
|
+
if (type === MyInputType.MONEY) {
|
|
251
|
+
e.target.value = moneyFormat(myValue);
|
|
252
|
+
e.value = moneyFormat(myValue);
|
|
253
|
+
} else {
|
|
254
|
+
e.target.value = myValue;
|
|
255
|
+
e.value = myValue;
|
|
256
|
+
}
|
|
210
257
|
if (onMouseEnter != null) onMouseEnter(e);
|
|
211
258
|
};
|
|
212
259
|
const onMyMouseLeave = e => {
|
|
213
|
-
|
|
214
|
-
|
|
260
|
+
// MONEY input için formatlanmış değeri kullan
|
|
261
|
+
if (type === MyInputType.MONEY) {
|
|
262
|
+
e.target.value = moneyFormat(myValue);
|
|
263
|
+
e.value = moneyFormat(myValue);
|
|
264
|
+
} else {
|
|
265
|
+
e.target.value = myValue;
|
|
266
|
+
e.value = myValue;
|
|
267
|
+
}
|
|
215
268
|
if (onMouseLeave != null) onMouseLeave(e);
|
|
216
269
|
};
|
|
217
270
|
const onRemoveImageClick = e => {
|
|
@@ -229,9 +282,6 @@ function MyInput({
|
|
|
229
282
|
// min ve max kontrolü
|
|
230
283
|
if (min && newValue < min) newValue = min;else if (max && newValue > max) newValue = max;
|
|
231
284
|
}
|
|
232
|
-
if (type === MyInputType.MONEY && newValue) {
|
|
233
|
-
newValue = newValue.replace(/[^0-9.]/g, '');
|
|
234
|
-
}
|
|
235
285
|
if (type === MyInputType.TEXT || type === MyInputType.TEXTAREA) {
|
|
236
286
|
newValue = newValue.trim();
|
|
237
287
|
if (uppercase) newValue = newValue.toLocaleUpperCase("TR");else if (lowercase) newValue = newValue.toLocaleLowerCase("TR");else if (firstUppercase) newValue = newValue.split(' ').map(word => word.charAt(0).toLocaleUpperCase("TR") + word.slice(1).toLocaleLowerCase("TR")).join(' ');
|
|
@@ -261,6 +311,72 @@ function MyInput({
|
|
|
261
311
|
// State'i güncelle
|
|
262
312
|
setMyValue(newValue);
|
|
263
313
|
}, [myValue, onChange]);
|
|
314
|
+
|
|
315
|
+
// MONEY input için özel change handler
|
|
316
|
+
const handleMoneyChange = (0, _react.useCallback)(e => {
|
|
317
|
+
const input = e.target;
|
|
318
|
+
const cursorPos = input.selectionStart;
|
|
319
|
+
const oldValue = input.value;
|
|
320
|
+
let newValue = e.target.value;
|
|
321
|
+
|
|
322
|
+
// Yazarken displayValue'yu temizle
|
|
323
|
+
setDisplayValue(null);
|
|
324
|
+
|
|
325
|
+
// Virgülleri kaldır
|
|
326
|
+
newValue = newValue.replace(/,/g, '');
|
|
327
|
+
|
|
328
|
+
// Sadece sayılar ve tek nokta
|
|
329
|
+
newValue = newValue.replace(/[^0-9.]/g, '');
|
|
330
|
+
|
|
331
|
+
// Birden fazla nokta varsa sadece ilkini koru
|
|
332
|
+
const parts = newValue.split('.');
|
|
333
|
+
if (parts.length > 2) {
|
|
334
|
+
newValue = parts[0] + '.' + parts.slice(1).join('');
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Noktadan sonra maksimum decimal count
|
|
338
|
+
if (parts.length === 2 && parts[1].length > decimalCount) {
|
|
339
|
+
newValue = parts[0] + '.' + parts[1].substring(0, decimalCount);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// State'i güncelle
|
|
343
|
+
setMyValue(newValue);
|
|
344
|
+
|
|
345
|
+
// Cursor pozisyonunu koru
|
|
346
|
+
setTimeout(() => {
|
|
347
|
+
if (input && input.setSelectionRange) {
|
|
348
|
+
// Yeni formatlanmış değerdeki virgül sayısını hesapla
|
|
349
|
+
const newFormattedValue = moneyFormat(newValue);
|
|
350
|
+
const oldCommaCount = (oldValue.match(/,/g) || []).length;
|
|
351
|
+
const newCommaCount = (newFormattedValue.match(/,/g) || []).length;
|
|
352
|
+
const commaChange = newCommaCount - oldCommaCount;
|
|
353
|
+
let newCursorPos = cursorPos + commaChange;
|
|
354
|
+
newCursorPos = Math.max(0, Math.min(newCursorPos, newFormattedValue.length));
|
|
355
|
+
input.setSelectionRange(newCursorPos, newCursorPos);
|
|
356
|
+
}
|
|
357
|
+
}, 0);
|
|
358
|
+
|
|
359
|
+
// Typing durumunu güncelle
|
|
360
|
+
setIsTyping(true);
|
|
361
|
+
|
|
362
|
+
// Önceki timeout'u temizle
|
|
363
|
+
if (typingTimeoutRef.current) {
|
|
364
|
+
clearTimeout(typingTimeoutRef.current);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Yeni timeout ayarla
|
|
368
|
+
typingTimeoutRef.current = setTimeout(() => {
|
|
369
|
+
setIsTyping(false);
|
|
370
|
+
if (onChange) {
|
|
371
|
+
onChange({
|
|
372
|
+
value: newValue,
|
|
373
|
+
target: {
|
|
374
|
+
value: newValue
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}, 300);
|
|
379
|
+
}, [onChange, decimalCount]);
|
|
264
380
|
const onMyChange = async e => {
|
|
265
381
|
if (type === MyInputType.FILE || type === MyInputType.IMAGE) {
|
|
266
382
|
let files = [];
|
|
@@ -504,8 +620,8 @@ function MyInput({
|
|
|
504
620
|
ref: ref,
|
|
505
621
|
id: id,
|
|
506
622
|
type: "text",
|
|
507
|
-
value: moneyFormat(myValue),
|
|
508
|
-
onChange:
|
|
623
|
+
value: moneyFormat(displayValue || myValue),
|
|
624
|
+
onChange: handleMoneyChange,
|
|
509
625
|
placeholder: placeholder,
|
|
510
626
|
autoComplete: "off",
|
|
511
627
|
style: style,
|