funda-ui 4.7.565 → 4.7.570
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/Chatbox/index.js +14 -12
- package/Checkbox/index.d.ts +1 -1
- package/Checkbox/index.js +3 -3
- package/Date/index.js +73 -50
- package/Input/index.d.ts +23 -23
- package/Input/index.js +71 -45
- package/NumberInput/index.d.ts +1 -1
- package/Radio/index.d.ts +1 -1
- package/Radio/index.js +12 -6
- package/RangeSlider/index.js +71 -45
- package/Select/index.d.ts +1 -1
- package/Select/index.js +22 -0
- package/TagInput/index.d.ts +1 -1
- package/Textarea/index.d.ts +17 -17
- package/Textarea/index.js +14 -12
- package/lib/cjs/Chatbox/index.js +14 -12
- package/lib/cjs/Checkbox/index.d.ts +1 -1
- package/lib/cjs/Checkbox/index.js +3 -3
- package/lib/cjs/Date/index.js +73 -50
- package/lib/cjs/Input/index.d.ts +23 -23
- package/lib/cjs/Input/index.js +71 -45
- package/lib/cjs/NumberInput/index.d.ts +1 -1
- package/lib/cjs/Radio/index.d.ts +1 -1
- package/lib/cjs/Radio/index.js +12 -6
- package/lib/cjs/RangeSlider/index.js +71 -45
- package/lib/cjs/Select/index.d.ts +1 -1
- package/lib/cjs/Select/index.js +22 -0
- package/lib/cjs/TagInput/index.d.ts +1 -1
- package/lib/cjs/Textarea/index.d.ts +17 -17
- package/lib/cjs/Textarea/index.js +14 -12
- package/lib/esm/Chatbox/index.tsx +1 -1
- package/lib/esm/Checkbox/index.tsx +4 -4
- package/lib/esm/Date/index.tsx +2 -4
- package/lib/esm/Input/index.tsx +101 -83
- package/lib/esm/NumberInput/index.tsx +1 -1
- package/lib/esm/Radio/index.tsx +16 -8
- package/lib/esm/Select/index.tsx +34 -1
- package/lib/esm/TagInput/index.tsx +1 -1
- package/lib/esm/Textarea/index.tsx +75 -70
- package/package.json +1 -1
package/lib/esm/Radio/index.tsx
CHANGED
|
@@ -15,8 +15,14 @@ export interface OptionConfig {
|
|
|
15
15
|
[propName: string]: string | number | React.ReactNode | boolean;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
export type RadioOptionChangeFnType = (
|
|
18
|
+
//
|
|
19
|
+
export type RadioOptionChangeFnType = (
|
|
20
|
+
e: React.ChangeEvent<HTMLInputElement> | null,
|
|
21
|
+
val: string,
|
|
22
|
+
currentData: OptionConfig | null,
|
|
23
|
+
currentIndex: string | number | null,
|
|
24
|
+
element: HTMLElement
|
|
25
|
+
) => void;
|
|
20
26
|
|
|
21
27
|
|
|
22
28
|
export type RadioProps = {
|
|
@@ -165,25 +171,27 @@ const Radio = forwardRef((props: RadioProps, externalRef: any) => {
|
|
|
165
171
|
getLatestVal: () => {
|
|
166
172
|
return controlValue || '';
|
|
167
173
|
},
|
|
168
|
-
clear: (cb?:
|
|
174
|
+
clear: (cb?: () => void) => {
|
|
169
175
|
setControlValue('');
|
|
170
176
|
cb?.();
|
|
171
177
|
|
|
172
178
|
if (typeof (onChange) === 'function') {
|
|
173
179
|
const curData: Record<string, unknown> = optionsFlat(dataInit).find((v: any) => v.value == value);
|
|
174
180
|
const currentIndex: number = optionsFlat(dataInit).findIndex((v: any) => v.value == value);
|
|
175
|
-
|
|
181
|
+
const targetInput = getAllControls().find((input: HTMLInputElement) => input.checked);
|
|
182
|
+
onChange(null, '', null, null, typeof targetInput !== 'undefined' ? targetInput : getAllControls()[0]);
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
},
|
|
179
|
-
set: (value: string, cb?:
|
|
186
|
+
set: (value: string, cb?: () => void) => {
|
|
180
187
|
setControlValue(`${value}`);
|
|
181
188
|
cb?.();
|
|
182
189
|
|
|
183
190
|
if (typeof (onChange) === 'function') {
|
|
184
191
|
const curData: Record<string, unknown> = optionsFlat(dataInit).find((v: any) => v.value == value);
|
|
185
192
|
const currentIndex: number = optionsFlat(dataInit).findIndex((v: any) => v.value == value);
|
|
186
|
-
|
|
193
|
+
const targetInput = getAllControls().find((input: HTMLInputElement) => input.value === value);
|
|
194
|
+
onChange(null, `${value}`, curData as OptionConfig, currentIndex, typeof targetInput !== 'undefined' ? targetInput : getAllControls()[0]);
|
|
187
195
|
}
|
|
188
196
|
}
|
|
189
197
|
}),
|
|
@@ -371,10 +379,10 @@ const Radio = forwardRef((props: RadioProps, externalRef: any) => {
|
|
|
371
379
|
|
|
372
380
|
//
|
|
373
381
|
if (typeof (onChange) === 'function') {
|
|
374
|
-
onChange(event, val, curData, currentIndex);
|
|
382
|
+
onChange(event, val, curData as OptionConfig, currentIndex, event.target);
|
|
375
383
|
}
|
|
376
384
|
if (typeof (onClick) === 'function') {
|
|
377
|
-
onClick(event, val, curData, currentIndex);
|
|
385
|
+
onClick(event, val, curData as OptionConfig, currentIndex, event.target);
|
|
378
386
|
}
|
|
379
387
|
}
|
|
380
388
|
|
package/lib/esm/Select/index.tsx
CHANGED
|
@@ -56,8 +56,8 @@ export interface MultiSelectValue {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export type SelectOptionChangeFnType = (
|
|
59
|
-
event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,
|
|
60
59
|
element: HTMLElement,
|
|
60
|
+
valueElement: HTMLElement,
|
|
61
61
|
value: OptionConfig | MultiSelectValue
|
|
62
62
|
) => void | Promise<void>;
|
|
63
63
|
|
|
@@ -409,6 +409,15 @@ const Select = forwardRef((props: SelectProps, externalRef: any) => {
|
|
|
409
409
|
|
|
410
410
|
if (MULTI_SEL_VALID) {
|
|
411
411
|
updateOptionCheckboxes('remove');
|
|
412
|
+
|
|
413
|
+
//
|
|
414
|
+
if (typeof onChange === 'function') {
|
|
415
|
+
onChange(
|
|
416
|
+
selectInputRef.current,
|
|
417
|
+
valueInputRef.current,
|
|
418
|
+
multipleSelectionCallback([], [])
|
|
419
|
+
);
|
|
420
|
+
}
|
|
412
421
|
} else {
|
|
413
422
|
handleClearValue();
|
|
414
423
|
}
|
|
@@ -427,9 +436,30 @@ const Select = forwardRef((props: SelectProps, externalRef: any) => {
|
|
|
427
436
|
labels: value.map((v: any) => v.label),
|
|
428
437
|
values: value.map((v: any) => v.value)
|
|
429
438
|
});
|
|
439
|
+
|
|
440
|
+
//
|
|
441
|
+
if (typeof onChange === 'function') {
|
|
442
|
+
onChange(
|
|
443
|
+
selectInputRef.current,
|
|
444
|
+
valueInputRef.current,
|
|
445
|
+
multipleSelectionCallback(
|
|
446
|
+
value.map((v: any) => v.value),
|
|
447
|
+
value.map((v: any) => v.label)
|
|
448
|
+
)
|
|
449
|
+
);
|
|
450
|
+
}
|
|
430
451
|
} else {
|
|
431
452
|
const _val = value[0];
|
|
432
453
|
handleSelect(null, (typeof _val === 'object' ? JSON.stringify(_val) : _val), [`${_val.value}`], [`${_val.label}`]);
|
|
454
|
+
|
|
455
|
+
//
|
|
456
|
+
if (typeof onChange === 'function') {
|
|
457
|
+
onChange(
|
|
458
|
+
selectInputRef.current,
|
|
459
|
+
valueInputRef.current,
|
|
460
|
+
_val
|
|
461
|
+
);
|
|
462
|
+
}
|
|
433
463
|
}
|
|
434
464
|
|
|
435
465
|
|
|
@@ -2329,6 +2359,9 @@ const Select = forwardRef((props: SelectProps, externalRef: any) => {
|
|
|
2329
2359
|
<button
|
|
2330
2360
|
tabIndex={-1}
|
|
2331
2361
|
type="button"
|
|
2362
|
+
style={disabled ? {
|
|
2363
|
+
display: 'none'
|
|
2364
|
+
} : undefined}
|
|
2332
2365
|
onClick={async (e: React.MouseEvent) => {
|
|
2333
2366
|
e.preventDefault();
|
|
2334
2367
|
e.stopPropagation();
|
|
@@ -44,7 +44,7 @@ export type TagInputProps = {
|
|
|
44
44
|
style?: React.CSSProperties;
|
|
45
45
|
tabIndex?: number;
|
|
46
46
|
[key: `data-${string}`]: string | undefined;
|
|
47
|
-
onChange?: (
|
|
47
|
+
onChange?: (el: HTMLElement, data: any, dataStr: any) => void;
|
|
48
48
|
onBlur?: (e: any) => void;
|
|
49
49
|
onFocus?: (e: any) => void;
|
|
50
50
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef, forwardRef, ChangeEvent, KeyboardEvent, useImperativeHandle } from 'react';
|
|
1
|
+
import React, { useState, useEffect, useRef, forwardRef, ChangeEvent, KeyboardEvent, useImperativeHandle, FocusEvent } from 'react';
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
import useComId from 'funda-utils/dist/cjs/useComId';
|
|
@@ -20,13 +20,13 @@ export type TextareaProps = {
|
|
|
20
20
|
requiredLabel?: React.ReactNode | string;
|
|
21
21
|
label?: React.ReactNode | string;
|
|
22
22
|
name?: string;
|
|
23
|
-
minLength?:
|
|
24
|
-
maxLength?:
|
|
23
|
+
minLength?: number;
|
|
24
|
+
maxLength?: number;
|
|
25
25
|
cols?: number;
|
|
26
26
|
rows?: number;
|
|
27
|
-
disabled?:
|
|
28
|
-
required?:
|
|
29
|
-
readOnly?:
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
readOnly?: boolean;
|
|
30
30
|
placeholder?: string;
|
|
31
31
|
autoSize?: boolean;
|
|
32
32
|
autoSizeMaxHeight?: number;
|
|
@@ -37,23 +37,23 @@ export type TextareaProps = {
|
|
|
37
37
|
aiPredictConfirmKey?: Array<string[]>;
|
|
38
38
|
aiPredictFetchFuncAsync?: any;
|
|
39
39
|
aiPredictFetchFuncMethod?: string;
|
|
40
|
-
aiPredictFetchFuncMethodParams?:
|
|
40
|
+
aiPredictFetchFuncMethodParams?: unknown[];
|
|
41
41
|
aiPredictFetchCallback?: (data: any) => void;
|
|
42
42
|
/** -- */
|
|
43
43
|
id?: string;
|
|
44
44
|
style?: React.CSSProperties;
|
|
45
45
|
tabIndex?: number;
|
|
46
46
|
[key: `data-${string}`]: string | undefined;
|
|
47
|
-
onChangeCallback?: (e:
|
|
48
|
-
onInputCallback?: (e:
|
|
49
|
-
onKeyPressedCallback?: (e:
|
|
50
|
-
onChange?: (e:
|
|
51
|
-
onBlur?: (e:
|
|
52
|
-
onFocus?: (e:
|
|
53
|
-
onPressEnter?: (e:
|
|
54
|
-
onKeyDown?: (e:
|
|
55
|
-
onKeyUp?: (e:
|
|
56
|
-
onResize?: (el:
|
|
47
|
+
onChangeCallback?: (e: ChangeEvent<HTMLTextAreaElement> | FocusEvent, el: HTMLTextAreaElement) => string | void;
|
|
48
|
+
onInputCallback?: (e: ChangeEvent<HTMLTextAreaElement> | KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => string | void;
|
|
49
|
+
onKeyPressedCallback?: (e: KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => string | void;
|
|
50
|
+
onChange?: (e: ChangeEvent<HTMLTextAreaElement> | KeyboardEvent<HTMLTextAreaElement> | null, el: HTMLTextAreaElement, value: string) => void;
|
|
51
|
+
onBlur?: (e: FocusEvent, el: HTMLTextAreaElement) => void;
|
|
52
|
+
onFocus?: (e: FocusEvent, el: HTMLTextAreaElement) => void;
|
|
53
|
+
onPressEnter?: (e: KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => void;
|
|
54
|
+
onKeyDown?: (e: KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => void;
|
|
55
|
+
onKeyUp?: (e: KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => void;
|
|
56
|
+
onResize?: (el: HTMLTextAreaElement, params: number[]) => void;
|
|
57
57
|
|
|
58
58
|
};
|
|
59
59
|
|
|
@@ -109,8 +109,8 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
109
109
|
|
|
110
110
|
const uniqueID = useComId();
|
|
111
111
|
const idRes = id || uniqueID;
|
|
112
|
-
const rootRef = useRef<
|
|
113
|
-
const valRef = useRef<
|
|
112
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
113
|
+
const valRef = useRef<HTMLTextAreaElement | null>(null);
|
|
114
114
|
const [changedVal, setChangedVal] = useState<string>(value || '');
|
|
115
115
|
|
|
116
116
|
|
|
@@ -120,7 +120,7 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
120
120
|
const [currentSuggestion, setCurrentSuggestion] = useState<string>('');
|
|
121
121
|
const [tempMatchedSuggestion, setTempMatchedSuggestion] = useState<string[]>([]);
|
|
122
122
|
const [textWidth, setTextWidth] = useState<number>(0);
|
|
123
|
-
const aiInputRef = useRef<
|
|
123
|
+
const aiInputRef = useRef<HTMLDivElement>(null);
|
|
124
124
|
const originInputComputedStyle = useRef<Record<string, any>>({
|
|
125
125
|
fontSize: 16,
|
|
126
126
|
fontFamily: 'inherit',
|
|
@@ -137,7 +137,7 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
137
137
|
const [suggestions, setSuggestions] = useState<string[]>([]);
|
|
138
138
|
|
|
139
139
|
//performance
|
|
140
|
-
const handleChangeSuggestionsFetchSafe = useDebounce((e:
|
|
140
|
+
const handleChangeSuggestionsFetchSafe = useDebounce((e: ChangeEvent<HTMLTextAreaElement>, curVal: string) => {
|
|
141
141
|
const _oparams: any[] = aiPredictFetchFuncMethodParams || [];
|
|
142
142
|
const _params: any[] = _oparams.map((item: any) => item !== '$QUERY_STRING' ? item : curVal);
|
|
143
143
|
fetchSuggestionsData((_params).join(',')).then((resSuggestions: string[]) => {
|
|
@@ -145,9 +145,9 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
145
145
|
});
|
|
146
146
|
}, 350, []);
|
|
147
147
|
|
|
148
|
-
async function fetchSuggestionsData(params:
|
|
148
|
+
async function fetchSuggestionsData(params: string): Promise<string[]> {
|
|
149
149
|
|
|
150
|
-
if (typeof aiPredictFetchFuncAsync === 'object') {
|
|
150
|
+
if (typeof aiPredictFetchFuncAsync === 'object' && aiPredictFetchFuncMethod) {
|
|
151
151
|
|
|
152
152
|
const response: any = await aiPredictFetchFuncAsync[`${aiPredictFetchFuncMethod}`](...params.split(','));
|
|
153
153
|
let _ORGIN_DATA = response.data;
|
|
@@ -179,12 +179,14 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
179
179
|
|
|
180
180
|
// Calculates the width of the input text
|
|
181
181
|
//----------------
|
|
182
|
-
const calculateTextWidth = (text: string) => {
|
|
182
|
+
const calculateTextWidth = (text: string): number => {
|
|
183
183
|
if (valRef.current) {
|
|
184
184
|
const canvas = document.createElement('canvas');
|
|
185
|
-
const context
|
|
186
|
-
context
|
|
187
|
-
|
|
185
|
+
const context = canvas.getContext('2d');
|
|
186
|
+
if (context) {
|
|
187
|
+
context.font = `${originInputComputedStyle.current.fontSize}px ${originInputComputedStyle.current.fontFamily}`;
|
|
188
|
+
return context.measureText(text).width;
|
|
189
|
+
}
|
|
188
190
|
}
|
|
189
191
|
return 0;
|
|
190
192
|
};
|
|
@@ -193,7 +195,7 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
193
195
|
|
|
194
196
|
// Get the rest of the suggested text
|
|
195
197
|
//----------------
|
|
196
|
-
const getRemainingText = (fullSuggestion: string) => {
|
|
198
|
+
const getRemainingText = (fullSuggestion: string): string => {
|
|
197
199
|
if (!changedVal || !fullSuggestion) return '';
|
|
198
200
|
|
|
199
201
|
|
|
@@ -206,8 +208,8 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
206
208
|
|
|
207
209
|
// Match exactly from the start
|
|
208
210
|
//----------------
|
|
209
|
-
const preciseMatch = (input:
|
|
210
|
-
if (!input) return
|
|
211
|
+
const preciseMatch = (input: string, suggestions: string[]): string[] => {
|
|
212
|
+
if (!input) return [];
|
|
211
213
|
|
|
212
214
|
const filtered = suggestions.filter(s =>
|
|
213
215
|
s.toLowerCase().startsWith(input.toLowerCase())
|
|
@@ -220,8 +222,8 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
220
222
|
|
|
221
223
|
// Fuzzy matching
|
|
222
224
|
//----------------
|
|
223
|
-
const fuzzyMatch = (input:
|
|
224
|
-
if (!input) return
|
|
225
|
+
const fuzzyMatch = (input: string, suggestions: string[]): string[] => {
|
|
226
|
+
if (!input) return [];
|
|
225
227
|
|
|
226
228
|
// Convert input to a regular expression pattern with support for arbitrary position matching
|
|
227
229
|
const pattern = input.split('').map((char: string) =>
|
|
@@ -237,7 +239,7 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
237
239
|
|
|
238
240
|
// Handle input variations
|
|
239
241
|
//----------------
|
|
240
|
-
const handleInputAiPredictChange = (newValue: string, curSuggestions: string[]) => {
|
|
242
|
+
const handleInputAiPredictChange = (newValue: string, curSuggestions: string[]): void => {
|
|
241
243
|
setTextWidth(calculateTextWidth(newValue));
|
|
242
244
|
|
|
243
245
|
// Match results
|
|
@@ -251,7 +253,7 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
251
253
|
|
|
252
254
|
// Calculate the color shade of the prompt text
|
|
253
255
|
//----------------
|
|
254
|
-
const calculateOpacity = () => {
|
|
256
|
+
const calculateOpacity = (): number => {
|
|
255
257
|
// Transparency is calculated based on the input length
|
|
256
258
|
const baseOpacity = 0.5;
|
|
257
259
|
const inputLength = changedVal.length;
|
|
@@ -261,7 +263,7 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
261
263
|
|
|
262
264
|
// Confirm
|
|
263
265
|
//----------------
|
|
264
|
-
const handleAiPredictKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
266
|
+
const handleAiPredictKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>): void => {
|
|
265
267
|
// Prevents the default behavior of the enter key
|
|
266
268
|
e.preventDefault();
|
|
267
269
|
|
|
@@ -282,8 +284,8 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
282
284
|
el: autoSize ? valRef.current : null,
|
|
283
285
|
value: autoSize ? changedVal : '',
|
|
284
286
|
maxHeight: autoSizeMaxHeight,
|
|
285
|
-
cb: (res:
|
|
286
|
-
onResize?.(valRef.current, res);
|
|
287
|
+
cb: (res: number[]) => {
|
|
288
|
+
onResize?.(valRef.current as HTMLTextAreaElement, res);
|
|
287
289
|
}
|
|
288
290
|
});
|
|
289
291
|
|
|
@@ -300,17 +302,17 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
300
302
|
getLatestVal: () => {
|
|
301
303
|
return changedVal || '';
|
|
302
304
|
},
|
|
303
|
-
clear: (cb?:
|
|
305
|
+
clear: (cb?: () => void) => {
|
|
304
306
|
setChangedVal('');
|
|
305
307
|
cb?.();
|
|
306
308
|
|
|
307
|
-
onChange?.(null, valRef.current, '');
|
|
309
|
+
onChange?.(null, valRef.current as HTMLTextAreaElement, '');
|
|
308
310
|
},
|
|
309
|
-
set: (value: string, cb?:
|
|
311
|
+
set: (value: string, cb?: () => void) => {
|
|
310
312
|
setChangedVal(`${value}`);
|
|
311
313
|
cb?.();
|
|
312
314
|
|
|
313
|
-
onChange?.(null, valRef.current, `${value}`);
|
|
315
|
+
onChange?.(null, valRef.current as HTMLTextAreaElement, `${value}`);
|
|
314
316
|
},
|
|
315
317
|
resetHeight: () => {
|
|
316
318
|
reset();
|
|
@@ -324,22 +326,22 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
324
326
|
[contentRef, reset, changedVal]
|
|
325
327
|
);
|
|
326
328
|
|
|
327
|
-
const propExist = (p:
|
|
329
|
+
const propExist = (p: unknown): boolean => {
|
|
328
330
|
return typeof p !== 'undefined' && p !== null && p !== '';
|
|
329
331
|
};
|
|
330
332
|
|
|
331
333
|
|
|
332
334
|
|
|
333
|
-
function handleFocus(event:
|
|
335
|
+
function handleFocus(event: FocusEvent<HTMLTextAreaElement>): void {
|
|
334
336
|
const el = event.target;
|
|
335
337
|
rootRef.current?.classList.add('focus');
|
|
336
338
|
|
|
337
339
|
//
|
|
338
|
-
onFocus?.(event, valRef.current);
|
|
340
|
+
onFocus?.(event, valRef.current as HTMLTextAreaElement);
|
|
339
341
|
}
|
|
340
342
|
|
|
341
343
|
|
|
342
|
-
function handleChange(event: ChangeEvent<HTMLTextAreaElement> | KeyboardEvent<HTMLTextAreaElement> | null, curVal: string) {
|
|
344
|
+
function handleChange(event: ChangeEvent<HTMLTextAreaElement> | KeyboardEvent<HTMLTextAreaElement> | null, curVal: string): void {
|
|
343
345
|
|
|
344
346
|
setChangedVal(curVal);
|
|
345
347
|
|
|
@@ -350,19 +352,19 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
350
352
|
}
|
|
351
353
|
|
|
352
354
|
//
|
|
353
|
-
onChange?.(event, valRef.current, curVal);
|
|
355
|
+
onChange?.(event, valRef.current as HTMLTextAreaElement, curVal);
|
|
354
356
|
|
|
355
357
|
// It fires in real time as the user enters
|
|
356
|
-
if (typeof (onInputCallback) === 'function') {
|
|
357
|
-
const newData
|
|
358
|
+
if (typeof (onInputCallback) === 'function' && event) {
|
|
359
|
+
const newData = onInputCallback(event, valRef.current as HTMLTextAreaElement);
|
|
358
360
|
if (newData) setChangedVal(newData); // Avoid the error "react checkbox changing an uncontrolled input to be controlled"
|
|
359
361
|
}
|
|
360
362
|
|
|
361
363
|
}
|
|
362
364
|
|
|
363
|
-
function handleBlur(event:
|
|
364
|
-
const el = event.target;
|
|
365
|
-
const val =
|
|
365
|
+
function handleBlur(event: FocusEvent<HTMLTextAreaElement>): void {
|
|
366
|
+
const el = event.target as HTMLTextAreaElement;
|
|
367
|
+
const val = el.value;
|
|
366
368
|
|
|
367
369
|
|
|
368
370
|
//----
|
|
@@ -372,30 +374,30 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
372
374
|
}
|
|
373
375
|
|
|
374
376
|
//
|
|
375
|
-
onBlur?.(event, valRef.current);
|
|
377
|
+
onBlur?.(event, valRef.current as HTMLTextAreaElement);
|
|
376
378
|
|
|
377
379
|
|
|
378
380
|
// It fires when focus is lost
|
|
379
381
|
if (typeof (onChangeCallback) === 'function') {
|
|
380
|
-
const newData
|
|
382
|
+
const newData = onChangeCallback(event, valRef.current as HTMLTextAreaElement);
|
|
381
383
|
if (newData) setChangedVal(newData); // Avoid the error "react checkbox changing an uncontrolled input to be controlled"
|
|
382
384
|
}
|
|
383
385
|
|
|
384
386
|
}
|
|
385
387
|
|
|
386
|
-
function handleKeyPressed(event: KeyboardEvent<HTMLTextAreaElement>) {
|
|
388
|
+
function handleKeyPressed(event: KeyboardEvent<HTMLTextAreaElement>): void {
|
|
387
389
|
|
|
388
|
-
onKeyDown?.(event, valRef.current);
|
|
390
|
+
onKeyDown?.(event, valRef.current as HTMLTextAreaElement);
|
|
389
391
|
|
|
390
392
|
|
|
391
393
|
if (typeof (onKeyPressedCallback) === 'function') {
|
|
392
|
-
const newData
|
|
394
|
+
const newData = onKeyPressedCallback(event, valRef.current as HTMLTextAreaElement);
|
|
393
395
|
if (newData) setChangedVal(newData); // Avoid the error "react checkbox changing an uncontrolled input to be controlled"
|
|
394
396
|
}
|
|
395
397
|
|
|
396
398
|
if (event.key === 'Enter' || event.key === 'NumpadEnter') {
|
|
397
399
|
// DO NOT USE "preventDefault()"
|
|
398
|
-
onPressEnter?.(event, valRef.current);
|
|
400
|
+
onPressEnter?.(event, valRef.current as HTMLTextAreaElement);
|
|
399
401
|
}
|
|
400
402
|
|
|
401
403
|
// AI Predict
|
|
@@ -404,7 +406,10 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
404
406
|
const keyBindings: Array<string[]> = aiPredictConfirmKey;
|
|
405
407
|
// The parameter 'registerKeyEvents' is an array, and each element is an object
|
|
406
408
|
// eg. { keys: ["Control", "S"], action: () => { console.log("Ctrl+S"); } }
|
|
407
|
-
const registerKeyEvents:
|
|
409
|
+
const registerKeyEvents: Array<{
|
|
410
|
+
keys: string[];
|
|
411
|
+
action: () => void;
|
|
412
|
+
}> = keyBindings.map((s: string[]) => {
|
|
408
413
|
return {
|
|
409
414
|
keys: s,
|
|
410
415
|
action: () => {
|
|
@@ -413,7 +418,7 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
413
418
|
};
|
|
414
419
|
});
|
|
415
420
|
|
|
416
|
-
registerKeyEvents.forEach((binding
|
|
421
|
+
registerKeyEvents.forEach((binding) => {
|
|
417
422
|
const keysPressed = binding.keys.every((key: string) =>
|
|
418
423
|
key === "Shift" ? event.shiftKey :
|
|
419
424
|
key === "Control" ? event.ctrlKey :
|
|
@@ -443,8 +448,8 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
443
448
|
|
|
444
449
|
}
|
|
445
450
|
|
|
446
|
-
function handleKeyUp(event: KeyboardEvent<HTMLTextAreaElement>) {
|
|
447
|
-
onKeyUp?.(event, valRef.current);
|
|
451
|
+
function handleKeyUp(event: KeyboardEvent<HTMLTextAreaElement>): void {
|
|
452
|
+
onKeyUp?.(event, valRef.current as HTMLTextAreaElement);
|
|
448
453
|
}
|
|
449
454
|
|
|
450
455
|
useEffect(() => {
|
|
@@ -496,9 +501,9 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
496
501
|
//--------------
|
|
497
502
|
if (aiPredict && valRef.current !== null) {
|
|
498
503
|
originInputComputedStyle.current = {
|
|
499
|
-
fontSize: actualPropertyValue(valRef.current as HTMLInputElement, 'fontSize'),
|
|
500
|
-
fontFamily: actualPropertyValue(valRef.current as HTMLInputElement, 'fontFamily'),
|
|
501
|
-
letterSpacing: actualPropertyValue(valRef.current as HTMLInputElement, 'letterSpacing'),
|
|
504
|
+
fontSize: actualPropertyValue(valRef.current as unknown as HTMLInputElement, 'fontSize'),
|
|
505
|
+
fontFamily: actualPropertyValue(valRef.current as unknown as HTMLInputElement, 'fontFamily'),
|
|
506
|
+
letterSpacing: actualPropertyValue(valRef.current as unknown as HTMLInputElement, 'letterSpacing'),
|
|
502
507
|
textTop: getTextTop(valRef.current)
|
|
503
508
|
};
|
|
504
509
|
}
|
|
@@ -549,11 +554,11 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
549
554
|
placeholder={placeholder || ''}
|
|
550
555
|
defaultValue={defaultValue}
|
|
551
556
|
value={changedVal}
|
|
552
|
-
minLength={minLength ||
|
|
553
|
-
maxLength={maxLength ||
|
|
557
|
+
minLength={minLength || undefined}
|
|
558
|
+
maxLength={maxLength || undefined}
|
|
554
559
|
onFocus={handleFocus}
|
|
555
560
|
onBlur={handleBlur}
|
|
556
|
-
onChange={(e:
|
|
561
|
+
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {
|
|
557
562
|
handleChange(e, e.target.value);
|
|
558
563
|
|
|
559
564
|
// AI Predict
|
|
@@ -563,9 +568,9 @@ const Textarea = forwardRef((props: TextareaProps, externalRef: any) => {
|
|
|
563
568
|
}}
|
|
564
569
|
onKeyDown={handleKeyPressed}
|
|
565
570
|
onKeyUp={handleKeyUp}
|
|
566
|
-
disabled={disabled ||
|
|
567
|
-
required={required ||
|
|
568
|
-
readOnly={readOnly ||
|
|
571
|
+
disabled={disabled || undefined}
|
|
572
|
+
required={required || undefined}
|
|
573
|
+
readOnly={readOnly || undefined}
|
|
569
574
|
cols={cols || 20}
|
|
570
575
|
rows={rows || 2}
|
|
571
576
|
style={style}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "UIUX Lab",
|
|
3
3
|
"email": "uiuxlab@gmail.com",
|
|
4
4
|
"name": "funda-ui",
|
|
5
|
-
"version": "4.7.
|
|
5
|
+
"version": "4.7.570",
|
|
6
6
|
"description": "React components using pure Bootstrap 5+ which does not contain any external style and script libraries.",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|