@pdg/react-form 1.0.160 → 1.0.162

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.
@@ -5,8 +5,10 @@ declare const FormTag: React.ForwardRefExoticComponent<Omit<FormTextFieldProps<F
5
5
  formValueSeparator?: string;
6
6
  formValueSort?: boolean;
7
7
  limitTags?: number;
8
+ allowSpace?: boolean;
8
9
  getLimitTagsText?: (more: number) => ReactNode;
9
10
  onAppendTag?: (tag: string) => boolean;
10
11
  onRemoveTag?: (tag: string) => boolean;
12
+ onTagClick?: (tag: string) => void;
11
13
  } & React.RefAttributes<FormTagCommands>>;
12
14
  export default FormTag;
@@ -8,7 +8,9 @@ export type FormTagProps = Omit<FormTextFieldProps<FormTagValue, false>, 'type'>
8
8
  formValueSeparator?: string;
9
9
  formValueSort?: boolean;
10
10
  limitTags?: number;
11
+ allowSpace?: boolean;
11
12
  getLimitTagsText?: (more: number) => ReactNode;
12
13
  onAppendTag?: (tag: string) => boolean;
13
14
  onRemoveTag?: (tag: string) => boolean;
15
+ onTagClick?: (tag: string) => void;
14
16
  };
@@ -1,4 +1,5 @@
1
1
  import { FormTextProps } from '../../FormText';
2
2
  export interface FormTagTextProps extends Omit<FormTextProps, 'value' | 'onChange'> {
3
+ allowSpace?: boolean;
3
4
  onAppendTag(tag: string): void;
4
5
  }
package/dist/index.esm.js CHANGED
@@ -1539,7 +1539,7 @@ FormText.displayName = 'FormText';var FormTagText = React.forwardRef(function (_
1539
1539
  /********************************************************************************************************************
1540
1540
  * Use
1541
1541
  * ******************************************************************************************************************/
1542
- var onKeyDown = _a.onKeyDown, onBlur = _a.onBlur, onAppendTag = _a.onAppendTag, props = __rest(_a, ["onKeyDown", "onBlur", "onAppendTag"]);
1542
+ var allowSpace = _a.allowSpace, onKeyDown = _a.onKeyDown, onBlur = _a.onBlur, onAppendTag = _a.onAppendTag, props = __rest(_a, ["allowSpace", "onKeyDown", "onBlur", "onAppendTag"]);
1543
1543
  var forceUpdate = useForceUpdate();
1544
1544
  /********************************************************************************************************************
1545
1545
  * Ref
@@ -1561,7 +1561,8 @@ FormText.displayName = 'FormText';var FormTagText = React.forwardRef(function (_
1561
1561
  * Event Handler
1562
1562
  * ******************************************************************************************************************/
1563
1563
  var handleKeyDown = useCallback(function (e) {
1564
- if ([' ', ',', 'Enter'].includes(e.key)) {
1564
+ var appendKeys = allowSpace ? [',', 'Enter'] : [' ', ',', 'Enter'];
1565
+ if (appendKeys.includes(e.key)) {
1565
1566
  e.preventDefault();
1566
1567
  e.stopPropagation();
1567
1568
  if (notEmpty(valueRef.current)) {
@@ -1572,10 +1573,10 @@ FormText.displayName = 'FormText';var FormTagText = React.forwardRef(function (_
1572
1573
  if (onKeyDown)
1573
1574
  onKeyDown(e);
1574
1575
  }
1575
- }, [appendTag, onKeyDown]);
1576
+ }, [allowSpace, appendTag, onKeyDown]);
1576
1577
  var handleChange = useCallback(function (value) {
1577
- valueRef.current = value.replace(/ /g, '').replace(/,/g, '');
1578
- }, []);
1578
+ valueRef.current = allowSpace ? value.replace(/,/g, '') : value.replace(/ /g, '').replace(/,/g, '');
1579
+ }, [allowSpace]);
1579
1580
  var handleBlur = useCallback(function (e) {
1580
1581
  if (notEmpty(valueRef.current)) {
1581
1582
  appendTag();
@@ -1599,7 +1600,7 @@ var FormTag = React.forwardRef(function (_a, ref) {
1599
1600
  * ******************************************************************************************************************/
1600
1601
  var initVariant = _a.variant, initSize = _a.size,
1601
1602
  //----------------------------------------------------------------------------------------------------------------
1602
- className = _a.className, name = _a.name, _b = _a.value, initValue = _b === void 0 ? _emptyValue : _b, exceptValue = _a.exceptValue, _c = _a.clear, clear = _c === void 0 ? true : _c, required = _a.required, readOnly = _a.readOnly, maxLength = _a.maxLength, initDisabled = _a.disabled, initFullWidth = _a.fullWidth, initError = _a.error, helperText = _a.helperText, _d = _a.formValueSeparator, formValueSeparator = _d === void 0 ? ',' : _d, formValueSort = _a.formValueSort, limitTags = _a.limitTags, getLimitTagsText = _a.getLimitTagsText, slotProps = _a.slotProps, onAppendTag = _a.onAppendTag, onRemoveTag = _a.onRemoveTag, onValidate = _a.onValidate, onChange = _a.onChange, onValue = _a.onValue, props = __rest(_a, ["variant", "size", "className", "name", "value", "exceptValue", "clear", "required", "readOnly", "maxLength", "disabled", "fullWidth", "error", "helperText", "formValueSeparator", "formValueSort", "limitTags", "getLimitTagsText", "slotProps", "onAppendTag", "onRemoveTag", "onValidate", "onChange", "onValue"]);
1603
+ className = _a.className, name = _a.name, _b = _a.value, initValue = _b === void 0 ? _emptyValue : _b, exceptValue = _a.exceptValue, _c = _a.clear, clear = _c === void 0 ? true : _c, required = _a.required, readOnly = _a.readOnly, maxLength = _a.maxLength, initDisabled = _a.disabled, initFullWidth = _a.fullWidth, initError = _a.error, helperText = _a.helperText, _d = _a.formValueSeparator, formValueSeparator = _d === void 0 ? ',' : _d, formValueSort = _a.formValueSort, limitTags = _a.limitTags, getLimitTagsText = _a.getLimitTagsText, allowSpace = _a.allowSpace, slotProps = _a.slotProps, onAppendTag = _a.onAppendTag, onRemoveTag = _a.onRemoveTag, onTagClick = _a.onTagClick, onValidate = _a.onValidate, onChange = _a.onChange, onValue = _a.onValue, props = __rest(_a, ["variant", "size", "className", "name", "value", "exceptValue", "clear", "required", "readOnly", "maxLength", "disabled", "fullWidth", "error", "helperText", "formValueSeparator", "formValueSort", "limitTags", "getLimitTagsText", "allowSpace", "slotProps", "onAppendTag", "onRemoveTag", "onTagClick", "onValidate", "onChange", "onValue"]);
1603
1604
  var _e = useFormState(), formVariant = _e.variant, formSize = _e.size, formFullWidth = _e.fullWidth, formDisabled = _e.disabled, onAddValueItem = _e.onAddValueItem, onValueChange = _e.onValueChange, onValueChangeByUser = _e.onValueChangeByUser, onRequestSearchSubmit = _e.onRequestSearchSubmit, otherFormState = __rest(_e, ["variant", "size", "fullWidth", "disabled", "onAddValueItem", "onValueChange", "onValueChangeByUser", "onRequestSearchSubmit"]);
1604
1605
  /********************************************************************************************************************
1605
1606
  * FormState - Variables
@@ -1691,10 +1692,11 @@ var FormTag = React.forwardRef(function (_a, ref) {
1691
1692
  * Function - appendTag, removeTag
1692
1693
  * ******************************************************************************************************************/
1693
1694
  var appendTag = useCallback(function (tag) {
1694
- if (!valueSet.has(tag)) {
1695
- if (onAppendTag && !onAppendTag(tag))
1695
+ var finalTag = tag.trim();
1696
+ if (notEmpty(finalTag) && !valueSet.has(finalTag)) {
1697
+ if (onAppendTag && !onAppendTag(finalTag))
1696
1698
  return;
1697
- valueSet.add(tag);
1699
+ valueSet.add(finalTag);
1698
1700
  var finalValue_1 = updateValue(valueSet);
1699
1701
  nextTick(function () {
1700
1702
  onValueChangeByUser(name, finalValue_1);
@@ -1732,8 +1734,8 @@ var FormTag = React.forwardRef(function (_a, ref) {
1732
1734
  }
1733
1735
  }, [ref, getCommands]);
1734
1736
  var handleRenderValue = useCallback(function (tags) {
1735
- return tags.map(function (tag) { return (React.createElement(Chip, { className: 'MuiAutocomplete-tag', key: tag, label: tag, size: 'small', style: variant === 'outlined' && size === 'small' ? { marginTop: 2, marginBottom: 0 } : undefined, disabled: readOnly || disabled, onDelete: readOnly || disabled ? undefined : function () { return removeTag(tag); } })); });
1736
- }, [disabled, readOnly, removeTag, size, variant]);
1737
+ return tags.map(function (tag) { return (React.createElement(Chip, { className: 'MuiAutocomplete-tag', key: tag, label: tag, size: 'small', style: variant === 'outlined' && size === 'small' ? { marginTop: 2, marginBottom: 0 } : undefined, disabled: readOnly || disabled, onDelete: readOnly || disabled ? undefined : function () { return removeTag(tag); }, onClick: function () { return onTagClick === null || onTagClick === void 0 ? void 0 : onTagClick(tag); } })); });
1738
+ }, [disabled, onTagClick, readOnly, removeTag, size, variant]);
1737
1739
  /********************************************************************************************************************
1738
1740
  * Render
1739
1741
  * ******************************************************************************************************************/
@@ -1744,9 +1746,10 @@ var FormTag = React.forwardRef(function (_a, ref) {
1744
1746
  delete htmlInputProps.value;
1745
1747
  var renderProps = __assign({ name: name, clear: clear, className: classNames(className, 'FormValueItem', 'FormTag'), error: error, disabled: disabled, fullWidth: fullWidth, required: required, exceptValue: exceptValue, slotProps: __assign(__assign({}, slotProps), { inputLabel: __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.inputLabel), { htmlFor: params.InputLabelProps.htmlFor, id: params.InputLabelProps.id }), input: __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.input), { style: __assign(__assign({}, (_a = slotProps === null || slotProps === void 0 ? void 0 : slotProps.input) === null || _a === void 0 ? void 0 : _a.style), (variant === 'outlined' && size === 'small'
1746
1748
  ? { paddingTop: 7, paddingBottom: 6, marginTop: -2 }
1747
- : undefined)), className: params.InputProps.className, ref: params.InputProps.ref, startAdornment: params.InputProps.startAdornment }), htmlInput: __assign(__assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.htmlInput), htmlInputProps), { style: __assign(__assign(__assign({}, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.htmlInput) === null || _b === void 0 ? void 0 : _b.style), htmlInputProps.style), (variant === 'outlined' && size === 'small' ? { marginTop: 4, paddingBottom: 2 } : undefined)) }) }), helperText: error ? errorHelperText : helperText, onAppendTag: appendTag }, props);
1749
+ : undefined)), className: params.InputProps.className, ref: params.InputProps.ref, startAdornment: params.InputProps.startAdornment }), htmlInput: __assign(__assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.htmlInput), htmlInputProps), { style: __assign(__assign(__assign({}, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.htmlInput) === null || _b === void 0 ? void 0 : _b.style), htmlInputProps.style), (variant === 'outlined' && size === 'small' ? { marginTop: 4, paddingBottom: 2 } : undefined)) }) }), helperText: error ? errorHelperText : helperText, allowSpace: allowSpace, onAppendTag: appendTag }, props);
1748
1750
  return React.createElement(FormTagText, __assign({ ref: handleRef }, renderProps));
1749
1751
  }, [
1752
+ allowSpace,
1750
1753
  appendTag,
1751
1754
  className,
1752
1755
  clear,
package/dist/index.js CHANGED
@@ -1539,7 +1539,7 @@ FormText.displayName = 'FormText';var FormTagText = React.forwardRef(function (_
1539
1539
  /********************************************************************************************************************
1540
1540
  * Use
1541
1541
  * ******************************************************************************************************************/
1542
- var onKeyDown = _a.onKeyDown, onBlur = _a.onBlur, onAppendTag = _a.onAppendTag, props = __rest(_a, ["onKeyDown", "onBlur", "onAppendTag"]);
1542
+ var allowSpace = _a.allowSpace, onKeyDown = _a.onKeyDown, onBlur = _a.onBlur, onAppendTag = _a.onAppendTag, props = __rest(_a, ["allowSpace", "onKeyDown", "onBlur", "onAppendTag"]);
1543
1543
  var forceUpdate = reactHook.useForceUpdate();
1544
1544
  /********************************************************************************************************************
1545
1545
  * Ref
@@ -1561,7 +1561,8 @@ FormText.displayName = 'FormText';var FormTagText = React.forwardRef(function (_
1561
1561
  * Event Handler
1562
1562
  * ******************************************************************************************************************/
1563
1563
  var handleKeyDown = React.useCallback(function (e) {
1564
- if ([' ', ',', 'Enter'].includes(e.key)) {
1564
+ var appendKeys = allowSpace ? [',', 'Enter'] : [' ', ',', 'Enter'];
1565
+ if (appendKeys.includes(e.key)) {
1565
1566
  e.preventDefault();
1566
1567
  e.stopPropagation();
1567
1568
  if (notEmpty(valueRef.current)) {
@@ -1572,10 +1573,10 @@ FormText.displayName = 'FormText';var FormTagText = React.forwardRef(function (_
1572
1573
  if (onKeyDown)
1573
1574
  onKeyDown(e);
1574
1575
  }
1575
- }, [appendTag, onKeyDown]);
1576
+ }, [allowSpace, appendTag, onKeyDown]);
1576
1577
  var handleChange = React.useCallback(function (value) {
1577
- valueRef.current = value.replace(/ /g, '').replace(/,/g, '');
1578
- }, []);
1578
+ valueRef.current = allowSpace ? value.replace(/,/g, '') : value.replace(/ /g, '').replace(/,/g, '');
1579
+ }, [allowSpace]);
1579
1580
  var handleBlur = React.useCallback(function (e) {
1580
1581
  if (notEmpty(valueRef.current)) {
1581
1582
  appendTag();
@@ -1599,7 +1600,7 @@ var FormTag = React.forwardRef(function (_a, ref) {
1599
1600
  * ******************************************************************************************************************/
1600
1601
  var initVariant = _a.variant, initSize = _a.size,
1601
1602
  //----------------------------------------------------------------------------------------------------------------
1602
- className = _a.className, name = _a.name, _b = _a.value, initValue = _b === void 0 ? _emptyValue : _b, exceptValue = _a.exceptValue, _c = _a.clear, clear = _c === void 0 ? true : _c, required = _a.required, readOnly = _a.readOnly, maxLength = _a.maxLength, initDisabled = _a.disabled, initFullWidth = _a.fullWidth, initError = _a.error, helperText = _a.helperText, _d = _a.formValueSeparator, formValueSeparator = _d === void 0 ? ',' : _d, formValueSort = _a.formValueSort, limitTags = _a.limitTags, getLimitTagsText = _a.getLimitTagsText, slotProps = _a.slotProps, onAppendTag = _a.onAppendTag, onRemoveTag = _a.onRemoveTag, onValidate = _a.onValidate, onChange = _a.onChange, onValue = _a.onValue, props = __rest(_a, ["variant", "size", "className", "name", "value", "exceptValue", "clear", "required", "readOnly", "maxLength", "disabled", "fullWidth", "error", "helperText", "formValueSeparator", "formValueSort", "limitTags", "getLimitTagsText", "slotProps", "onAppendTag", "onRemoveTag", "onValidate", "onChange", "onValue"]);
1603
+ className = _a.className, name = _a.name, _b = _a.value, initValue = _b === void 0 ? _emptyValue : _b, exceptValue = _a.exceptValue, _c = _a.clear, clear = _c === void 0 ? true : _c, required = _a.required, readOnly = _a.readOnly, maxLength = _a.maxLength, initDisabled = _a.disabled, initFullWidth = _a.fullWidth, initError = _a.error, helperText = _a.helperText, _d = _a.formValueSeparator, formValueSeparator = _d === void 0 ? ',' : _d, formValueSort = _a.formValueSort, limitTags = _a.limitTags, getLimitTagsText = _a.getLimitTagsText, allowSpace = _a.allowSpace, slotProps = _a.slotProps, onAppendTag = _a.onAppendTag, onRemoveTag = _a.onRemoveTag, onTagClick = _a.onTagClick, onValidate = _a.onValidate, onChange = _a.onChange, onValue = _a.onValue, props = __rest(_a, ["variant", "size", "className", "name", "value", "exceptValue", "clear", "required", "readOnly", "maxLength", "disabled", "fullWidth", "error", "helperText", "formValueSeparator", "formValueSort", "limitTags", "getLimitTagsText", "allowSpace", "slotProps", "onAppendTag", "onRemoveTag", "onTagClick", "onValidate", "onChange", "onValue"]);
1603
1604
  var _e = useFormState(), formVariant = _e.variant, formSize = _e.size, formFullWidth = _e.fullWidth, formDisabled = _e.disabled, onAddValueItem = _e.onAddValueItem, onValueChange = _e.onValueChange, onValueChangeByUser = _e.onValueChangeByUser, onRequestSearchSubmit = _e.onRequestSearchSubmit, otherFormState = __rest(_e, ["variant", "size", "fullWidth", "disabled", "onAddValueItem", "onValueChange", "onValueChangeByUser", "onRequestSearchSubmit"]);
1604
1605
  /********************************************************************************************************************
1605
1606
  * FormState - Variables
@@ -1691,10 +1692,11 @@ var FormTag = React.forwardRef(function (_a, ref) {
1691
1692
  * Function - appendTag, removeTag
1692
1693
  * ******************************************************************************************************************/
1693
1694
  var appendTag = React.useCallback(function (tag) {
1694
- if (!valueSet.has(tag)) {
1695
- if (onAppendTag && !onAppendTag(tag))
1695
+ var finalTag = tag.trim();
1696
+ if (notEmpty(finalTag) && !valueSet.has(finalTag)) {
1697
+ if (onAppendTag && !onAppendTag(finalTag))
1696
1698
  return;
1697
- valueSet.add(tag);
1699
+ valueSet.add(finalTag);
1698
1700
  var finalValue_1 = updateValue(valueSet);
1699
1701
  nextTick(function () {
1700
1702
  onValueChangeByUser(name, finalValue_1);
@@ -1732,8 +1734,8 @@ var FormTag = React.forwardRef(function (_a, ref) {
1732
1734
  }
1733
1735
  }, [ref, getCommands]);
1734
1736
  var handleRenderValue = React.useCallback(function (tags) {
1735
- return tags.map(function (tag) { return (React.createElement(material.Chip, { className: 'MuiAutocomplete-tag', key: tag, label: tag, size: 'small', style: variant === 'outlined' && size === 'small' ? { marginTop: 2, marginBottom: 0 } : undefined, disabled: readOnly || disabled, onDelete: readOnly || disabled ? undefined : function () { return removeTag(tag); } })); });
1736
- }, [disabled, readOnly, removeTag, size, variant]);
1737
+ return tags.map(function (tag) { return (React.createElement(material.Chip, { className: 'MuiAutocomplete-tag', key: tag, label: tag, size: 'small', style: variant === 'outlined' && size === 'small' ? { marginTop: 2, marginBottom: 0 } : undefined, disabled: readOnly || disabled, onDelete: readOnly || disabled ? undefined : function () { return removeTag(tag); }, onClick: function () { return onTagClick === null || onTagClick === void 0 ? void 0 : onTagClick(tag); } })); });
1738
+ }, [disabled, onTagClick, readOnly, removeTag, size, variant]);
1737
1739
  /********************************************************************************************************************
1738
1740
  * Render
1739
1741
  * ******************************************************************************************************************/
@@ -1744,9 +1746,10 @@ var FormTag = React.forwardRef(function (_a, ref) {
1744
1746
  delete htmlInputProps.value;
1745
1747
  var renderProps = __assign({ name: name, clear: clear, className: classNames(className, 'FormValueItem', 'FormTag'), error: error, disabled: disabled, fullWidth: fullWidth, required: required, exceptValue: exceptValue, slotProps: __assign(__assign({}, slotProps), { inputLabel: __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.inputLabel), { htmlFor: params.InputLabelProps.htmlFor, id: params.InputLabelProps.id }), input: __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.input), { style: __assign(__assign({}, (_a = slotProps === null || slotProps === void 0 ? void 0 : slotProps.input) === null || _a === void 0 ? void 0 : _a.style), (variant === 'outlined' && size === 'small'
1746
1748
  ? { paddingTop: 7, paddingBottom: 6, marginTop: -2 }
1747
- : undefined)), className: params.InputProps.className, ref: params.InputProps.ref, startAdornment: params.InputProps.startAdornment }), htmlInput: __assign(__assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.htmlInput), htmlInputProps), { style: __assign(__assign(__assign({}, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.htmlInput) === null || _b === void 0 ? void 0 : _b.style), htmlInputProps.style), (variant === 'outlined' && size === 'small' ? { marginTop: 4, paddingBottom: 2 } : undefined)) }) }), helperText: error ? errorHelperText : helperText, onAppendTag: appendTag }, props);
1749
+ : undefined)), className: params.InputProps.className, ref: params.InputProps.ref, startAdornment: params.InputProps.startAdornment }), htmlInput: __assign(__assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.htmlInput), htmlInputProps), { style: __assign(__assign(__assign({}, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.htmlInput) === null || _b === void 0 ? void 0 : _b.style), htmlInputProps.style), (variant === 'outlined' && size === 'small' ? { marginTop: 4, paddingBottom: 2 } : undefined)) }) }), helperText: error ? errorHelperText : helperText, allowSpace: allowSpace, onAppendTag: appendTag }, props);
1748
1750
  return React.createElement(FormTagText, __assign({ ref: handleRef }, renderProps));
1749
1751
  }, [
1752
+ allowSpace,
1750
1753
  appendTag,
1751
1754
  className,
1752
1755
  clear,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pdg/react-form",
3
3
  "title": "React Form",
4
- "version": "1.0.160",
4
+ "version": "1.0.162",
5
5
  "description": "React Form",
6
6
  "type": "module",
7
7
  "types": "dist/index.d.ts",