@pdg/react-form 1.0.17 → 1.0.18
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/index.js
CHANGED
|
@@ -7404,7 +7404,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7404
7404
|
// ID --------------------------------------------------------------------------------------------------------------
|
|
7405
7405
|
var initVariant = _a.variant, initSize = _a.size, initColor = _a.color, initFocused = _a.focused, initLabelShrink = _a.labelShrink, initFullWidth = _a.fullWidth,
|
|
7406
7406
|
//----------------------------------------------------------------------------------------------------------------
|
|
7407
|
-
name = _a.name, labelIcon = _a.labelIcon, label = _a.label, initLoading = _a.loading, initItems = _a.items, initValue = _a.value, initError = _a.error, initHelperText = _a.helperText, initDisabled = _a.disabled, readOnly = _a.readOnly, required = _a.required, exceptValue = _a.exceptValue, width = _a.width, placeholder = _a.placeholder, multiple = _a.multiple, formValueSeparator = _a.formValueSeparator, formValueSort = _a.formValueSort, disablePortal = _a.disablePortal, noOptionsText = _a.noOptionsText, loadingText = _a.loadingText, limitTags = _a.limitTags, openOnFocus = _a.openOnFocus, disableClearable = _a.disableClearable, onLoadItems = _a.onLoadItems, onRenderItem = _a.onRenderItem, onRenderTag = _a.onRenderTag, onAddItem = _a.onAddItem,
|
|
7407
|
+
name = _a.name, labelIcon = _a.labelIcon, label = _a.label, initLoading = _a.loading, initItems = _a.items, initValue = _a.value, initError = _a.error, initHelperText = _a.helperText, initDisabled = _a.disabled, readOnly = _a.readOnly, required = _a.required, exceptValue = _a.exceptValue, width = _a.width, placeholder = _a.placeholder, multiple = _a.multiple, formValueSeparator = _a.formValueSeparator, formValueSort = _a.formValueSort, disablePortal = _a.disablePortal, noOptionsText = _a.noOptionsText, loadingText = _a.loadingText, limitTags = _a.limitTags, openOnFocus = _a.openOnFocus, disableClearable = _a.disableClearable, async = _a.async, onLoadItems = _a.onLoadItems, onRenderItem = _a.onRenderItem, onRenderTag = _a.onRenderTag, onAddItem = _a.onAddItem,
|
|
7408
7408
|
//----------------------------------------------------------------------------------------------------------------
|
|
7409
7409
|
onChange = _a.onChange, onValue = _a.onValue, onValidate = _a.onValidate,
|
|
7410
7410
|
//----------------------------------------------------------------------------------------------------------------
|
|
@@ -7412,6 +7412,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7412
7412
|
var id = React.useId();
|
|
7413
7413
|
// Ref -------------------------------------------------------------------------------------------------------------
|
|
7414
7414
|
var textFieldRef = React.useRef(null);
|
|
7415
|
+
var asyncTimerRef = React.useRef(null);
|
|
7415
7416
|
// FormState -------------------------------------------------------------------------------------------------------
|
|
7416
7417
|
var _b = useFormState(), formVariant = _b.variant, formSize = _b.size, formColor = _b.color, formFocused = _b.focused, formLabelShrink = _b.labelShrink, formFullWidth = _b.fullWidth, onAddValueItem = _b.onAddValueItem, onRemoveValueItem = _b.onRemoveValueItem, onValueChange = _b.onValueChange, onValueChangeByUser = _b.onValueChangeByUser, onRequestSearchSubmit = _b.onRequestSearchSubmit;
|
|
7417
7418
|
// Memo - FormState ------------------------------------------------------------------------------------------------
|
|
@@ -7428,6 +7429,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7428
7429
|
var _f = useAutoUpdateLayoutState(initHelperText), helperText = _f[0], setHelperText = _f[1];
|
|
7429
7430
|
var _g = useAutoUpdateLayoutState(initLoading), loading = _g[0], setLoading = _g[1];
|
|
7430
7431
|
var _h = useAutoUpdateLayoutState(initDisabled), disabled = _h[0], setDisabled = _h[1];
|
|
7432
|
+
var _j = React.useState(undefined), inputValue = _j[0], setInputValue = _j[1];
|
|
7431
7433
|
// Memo --------------------------------------------------------------------------------------------------------------
|
|
7432
7434
|
var itemsValues = React.useMemo(function () {
|
|
7433
7435
|
if (items) {
|
|
@@ -7497,7 +7499,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7497
7499
|
return onValue ? onValue(finalValue) : finalValue;
|
|
7498
7500
|
}, [multiple, formValueSeparator, itemsValues, onValue]);
|
|
7499
7501
|
// State - value ---------------------------------------------------------------------------------------------------
|
|
7500
|
-
var
|
|
7502
|
+
var _k = useAutoUpdateLayoutState(initValue, getFinalValue), value = _k[0], setValue = _k[1];
|
|
7501
7503
|
var componentValue = React.useMemo(function () {
|
|
7502
7504
|
var finalValue = value;
|
|
7503
7505
|
if (finalValue != null) {
|
|
@@ -7534,7 +7536,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7534
7536
|
onChange(value);
|
|
7535
7537
|
onValueChange(name, value);
|
|
7536
7538
|
}
|
|
7537
|
-
if (onLoadItems) {
|
|
7539
|
+
if (!async && onLoadItems) {
|
|
7538
7540
|
setIsOnGetItemLoading(true);
|
|
7539
7541
|
onLoadItems().then(function (items) {
|
|
7540
7542
|
setItems(items);
|
|
@@ -7550,6 +7552,23 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7550
7552
|
onChange(value);
|
|
7551
7553
|
onValueChange(name, value);
|
|
7552
7554
|
}, [value]);
|
|
7555
|
+
React.useEffect(function () {
|
|
7556
|
+
if (asyncTimerRef.current) {
|
|
7557
|
+
clearTimeout(asyncTimerRef.current);
|
|
7558
|
+
asyncTimerRef.current = null;
|
|
7559
|
+
}
|
|
7560
|
+
if (async && onLoadItems && inputValue != null) {
|
|
7561
|
+
asyncTimerRef.current = setTimeout(function () {
|
|
7562
|
+
asyncTimerRef.current = null;
|
|
7563
|
+
setIsOnGetItemLoading(true);
|
|
7564
|
+
onLoadItems(inputValue).then(function (items) {
|
|
7565
|
+
setItems(items);
|
|
7566
|
+
setIsOnGetItemLoading(false);
|
|
7567
|
+
});
|
|
7568
|
+
}, 300);
|
|
7569
|
+
}
|
|
7570
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
7571
|
+
}, [async, inputValue]);
|
|
7553
7572
|
// Function - focus ------------------------------------------------------------------------------------------------
|
|
7554
7573
|
var focus = React.useCallback(function () {
|
|
7555
7574
|
var _a;
|
|
@@ -7715,7 +7734,11 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7715
7734
|
}
|
|
7716
7735
|
}, [multiple, getFinalValue, value, setValue, onValueChangeByUser, name, onRequestSearchSubmit, onAddItem]);
|
|
7717
7736
|
// Render ----------------------------------------------------------------------------------------------------------
|
|
7718
|
-
return (React__default["default"].createElement(material.Autocomplete, { options: items || [], className: classNames$1(className, 'FormValueItem', 'FormAutocomplete'), sx: sx, multiple: multiple, fullWidth: !width && fullWidth, openOnFocus: openOnFocus, disableClearable: disableClearable, disablePortal: disablePortal, noOptionsText: noOptionsText, value: componentValue, style: style, isOptionEqualToValue: function (option, value) { return option.value === value.value; }, disabled: disabled, readOnly: readOnly, loading: loading || isOnGetItemLoading, loadingText: loadingText, limitTags: limitTags, onChange: function (e, value, reason, details) { return handleChange(value, reason, details); }, renderOption: function (props, option) { return (React__default["default"].createElement("li", __assign$4({}, props, { key: option.value }), onRenderItem ? onRenderItem(option) : option.label)); },
|
|
7737
|
+
return (React__default["default"].createElement(material.Autocomplete, { options: items || [], className: classNames$1(className, 'FormValueItem', 'FormAutocomplete'), sx: sx, multiple: multiple, fullWidth: !width && fullWidth, openOnFocus: openOnFocus, disableClearable: disableClearable, disablePortal: disablePortal, noOptionsText: noOptionsText, value: componentValue, style: style, isOptionEqualToValue: function (option, value) { return option.value === value.value; }, disabled: disabled, readOnly: readOnly, loading: loading || isOnGetItemLoading, loadingText: loadingText, limitTags: limitTags, onChange: function (e, value, reason, details) { return handleChange(value, reason, details); }, renderOption: function (props, option) { return (React__default["default"].createElement("li", __assign$4({}, props, { key: option.value }), onRenderItem ? onRenderItem(option) : option.label)); }, onInputChange: function (event, newInputValue, reason) {
|
|
7738
|
+
if (reason === 'input') {
|
|
7739
|
+
setInputValue(newInputValue);
|
|
7740
|
+
}
|
|
7741
|
+
}, renderTags: function (value, getTagProps) {
|
|
7719
7742
|
return value.map(function (option, index) { return (React__default["default"].createElement(material.Chip, __assign$4({ size: 'small', label: onRenderTag ? onRenderTag(option) : option.label }, getTagProps({ index: index })))); });
|
|
7720
7743
|
}, renderInput: function (params) { return (React__default["default"].createElement(FormTextField, __assign$4({}, params, { ref: textFieldRef, name: name, variant: variant, size: size, color: color, labelIcon: labelIcon, label: label, labelShrink: labelShrink, required: required, focused: focused, error: error, helperText: helperText, placeholder: placeholder, noFormValueItem: true, InputProps: __assign$4(__assign$4({}, params.InputProps), { endAdornment: (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
7721
7744
|
loading || isOnGetItemLoading ? React__default["default"].createElement(CircularProgress__default["default"], { color: 'inherit', size: 20 }) : null,
|