@spscommerce/ds-react 6.18.3 → 6.19.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/lib/index.es.js CHANGED
@@ -38610,9 +38610,10 @@ const SpsKeyValueTagExamples = {
38610
38610
  }
38611
38611
  }
38612
38612
  };
38613
- const WHITESPACE_COMMA_TAB_NEWLINE_REGEX = new RegExp(/[,\n+\s+\t+]+/);
38614
- function splitStringByDelimiter(str) {
38615
- return str.split(WHITESPACE_COMMA_TAB_NEWLINE_REGEX).filter((s) => s !== "");
38613
+ function splitStringByDelimiter(str, delimiters) {
38614
+ const regexForSplit = new RegExp(`[\\t\r
38615
+ ${delimiters.join("").replace("]", "\\]").replace(" ", "\\s")}]+`);
38616
+ return str.split(regexForSplit).filter((s) => s !== "");
38616
38617
  }
38617
38618
  const propsDoc$1 = {
38618
38619
  disabled: "boolean",
@@ -38621,7 +38622,8 @@ const propsDoc$1 = {
38621
38622
  onChange: "ChangeEventHandler",
38622
38623
  onEntryChange: "(searchText: string) => void",
38623
38624
  placeholder: "string",
38624
- value: "any"
38625
+ value: "any",
38626
+ createTagOptions: "string[]"
38625
38627
  };
38626
38628
  const propTypes$1 = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
38627
38629
  disabled: propTypes$1H.exports.bool,
@@ -38631,7 +38633,8 @@ const propTypes$1 = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
38631
38633
  onChange: fun(),
38632
38634
  onEntryChange: fun(),
38633
38635
  placeholder: propTypes$1H.exports.string,
38634
- value: propTypes$1H.exports.any
38636
+ value: propTypes$1H.exports.any,
38637
+ createTagOptions: propTypes$1H.exports.arrayOf(propTypes$1H.exports.string)
38635
38638
  });
38636
38639
  function SpsMultiValueTextInput(_ma) {
38637
38640
  var _na = _ma, {
@@ -38646,6 +38649,7 @@ function SpsMultiValueTextInput(_ma) {
38646
38649
  unsafelyReplaceClassName,
38647
38650
  value,
38648
38651
  icon,
38652
+ createTagOptions = [" ", ","],
38649
38653
  "data-testid": testId
38650
38654
  } = _na, rest = __objRest(_na, [
38651
38655
  "className",
@@ -38659,6 +38663,7 @@ function SpsMultiValueTextInput(_ma) {
38659
38663
  "unsafelyReplaceClassName",
38660
38664
  "value",
38661
38665
  "icon",
38666
+ "createTagOptions",
38662
38667
  "data-testid"
38663
38668
  ]);
38664
38669
  const meta = formMeta || formControl2;
@@ -38706,6 +38711,21 @@ function SpsMultiValueTextInput(_ma) {
38706
38711
  removeIcon && removeIcon.focus();
38707
38712
  }
38708
38713
  }
38714
+ const createNewTag = React.useCallback((event) => {
38715
+ patchState({ activeTagIndex: null, searchText: "" });
38716
+ const trimmedText = state.searchText.trim();
38717
+ if (trimmedText && value.indexOf(trimmedText) === -1) {
38718
+ updateValue([...value, ...splitStringByDelimiter(trimmedText, createTagOptions)]);
38719
+ }
38720
+ if ((event.key === "Tab" || event.key === "Enter") && !state.searchText) {
38721
+ return;
38722
+ }
38723
+ event.preventDefault();
38724
+ }, [
38725
+ state.searchText,
38726
+ value,
38727
+ splitStringByDelimiter
38728
+ ]);
38709
38729
  function handleKeyDown(event) {
38710
38730
  if (!disabled) {
38711
38731
  const cursorIsAtLeftOfTextInputAndThereIsAtLeastOneSelection = !event.target.selectionStart && value && value.length;
@@ -38734,15 +38754,7 @@ function SpsMultiValueTextInput(_ma) {
38734
38754
  break;
38735
38755
  case "Enter":
38736
38756
  case "Tab":
38737
- case ",":
38738
- case " ":
38739
- if (state.searchText !== "") {
38740
- event.preventDefault();
38741
- }
38742
- patchState({ activeTagIndex: null, searchText: "" });
38743
- if (state.searchText.trim() !== "" && value.indexOf(state.searchText) === -1) {
38744
- updateValue([...value, ...splitStringByDelimiter(state.searchText)]);
38745
- }
38757
+ createNewTag(event);
38746
38758
  break;
38747
38759
  case "Up":
38748
38760
  case "ArrowUp":
@@ -38777,6 +38789,11 @@ function SpsMultiValueTextInput(_ma) {
38777
38789
  }
38778
38790
  break;
38779
38791
  }
38792
+ for (const option of createTagOptions) {
38793
+ if (event.key === option) {
38794
+ createNewTag(event);
38795
+ }
38796
+ }
38780
38797
  event.persist();
38781
38798
  patchState({ keyDown: event });
38782
38799
  }
@@ -12,11 +12,12 @@ declare const propTypes: {
12
12
  onEntryChange: PropTypes.Requireable<(searchText: string) => void>;
13
13
  placeholder: PropTypes.Requireable<string>;
14
14
  value: PropTypes.Requireable<any>;
15
+ createTagOptions: PropTypes.Requireable<string[]>;
15
16
  children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
16
17
  className: PropTypes.Requireable<string>;
17
18
  "data-testid": PropTypes.Requireable<string>;
18
19
  unsafelyReplaceClassName: PropTypes.Requireable<string>;
19
20
  };
20
21
  export declare type SpsMultiValueTextInputProps = PropTypes.InferTS<typeof propTypes, HTMLInputElement>;
21
- export declare function SpsMultiValueTextInput({ className, disabled, formControl, formMeta, id, onChange, onEntryChange, placeholder, unsafelyReplaceClassName, value, icon, "data-testid": testId, ...rest }: SpsMultiValueTextInputProps): JSX.Element;
22
+ export declare function SpsMultiValueTextInput({ className, disabled, formControl, formMeta, id, onChange, onEntryChange, placeholder, unsafelyReplaceClassName, value, icon, createTagOptions, "data-testid": testId, ...rest }: SpsMultiValueTextInputProps): JSX.Element;
22
23
  export {};
@@ -1,2 +1,2 @@
1
1
  export declare const WHITESPACE_COMMA_TAB_NEWLINE_REGEX: RegExp;
2
- export declare function splitStringByDelimiter(str: string): string[];
2
+ export declare function splitStringByDelimiter(str: string, delimiters: string[]): string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@spscommerce/ds-react",
3
3
  "description": "SPS Design System React components",
4
- "version": "6.18.3",
4
+ "version": "6.19.0",
5
5
  "author": "SPS Commerce",
6
6
  "license": "UNLICENSED",
7
7
  "repository": "https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/ds-react",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@react-stately/collections": "^3.3.3",
31
- "@spscommerce/ds-colors": "6.18.3",
32
- "@spscommerce/ds-illustrations": "6.18.3",
33
- "@spscommerce/ds-shared": "6.18.3",
34
- "@spscommerce/positioning": "6.18.3",
31
+ "@spscommerce/ds-colors": "6.19.0",
32
+ "@spscommerce/ds-illustrations": "6.19.0",
33
+ "@spscommerce/ds-shared": "6.19.0",
34
+ "@spscommerce/positioning": "6.19.0",
35
35
  "@spscommerce/utils": "^6.11.3",
36
36
  "moment": "^2.25.3",
37
37
  "moment-timezone": "^0.5.28",
@@ -40,10 +40,10 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@react-stately/collections": "^3.3.3",
43
- "@spscommerce/ds-colors": "6.18.3",
44
- "@spscommerce/ds-illustrations": "6.18.3",
45
- "@spscommerce/ds-shared": "6.18.3",
46
- "@spscommerce/positioning": "6.18.3",
43
+ "@spscommerce/ds-colors": "6.19.0",
44
+ "@spscommerce/ds-illustrations": "6.19.0",
45
+ "@spscommerce/ds-shared": "6.19.0",
46
+ "@spscommerce/positioning": "6.19.0",
47
47
  "@spscommerce/utils": "^6.11.3",
48
48
  "@testing-library/react": "^9.3.2",
49
49
  "@types/prop-types": "^15.7.1",