@spscommerce/ds-react 5.19.0 → 5.20.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
@@ -2463,7 +2463,7 @@ function documentClickHandlerFactory(rootRef, popupRef, doHidePopup) {
2463
2463
  }
2464
2464
  };
2465
2465
  }
2466
- function useInputPopup(rootRef, popupRef) {
2466
+ function useInputPopup(rootRef, popupRef, onHide) {
2467
2467
  const suppressPopup = React.useRef(false);
2468
2468
  const [showPopup, setShowPopup] = React.useState(false);
2469
2469
  const doShowPopup = React.useCallback(() => {
@@ -2476,6 +2476,9 @@ function useInputPopup(rootRef, popupRef) {
2476
2476
  const doHidePopup = React.useCallback((suppressNextShow = false) => {
2477
2477
  setShowPopup(false);
2478
2478
  suppressPopup.current = suppressNextShow;
2479
+ if (onHide) {
2480
+ onHide();
2481
+ }
2479
2482
  }, []);
2480
2483
  useDocumentEventListener("click", documentClickHandlerFactory, [
2481
2484
  rootRef,
@@ -15350,7 +15353,7 @@ function SpsContentRowCol(props2) {
15350
15353
  ].join(" "));
15351
15354
  }
15352
15355
  }, [leaner]);
15353
- const classes = clsx(unsafelyReplaceClassName || "sps-content-row__col", borderless && "sps-content-row__col--borderless", (lean || leaner) && "sps-content-row__col--lean");
15356
+ const classes = clsx(unsafelyReplaceClassName || "sps-content-row__col", borderless && "sps-content-row__col--borderless", (lean || leaner) && "sps-content-row__col--lean", className);
15354
15357
  const width = widthPx ? widthPx / 16 : widthRem;
15355
15358
  const inlineStyles = width ? __spreadProps(__spreadValues({}, style2), {
15356
15359
  width: `${width}rem`
@@ -29901,6 +29904,7 @@ const SpsModalExamples = {
29901
29904
  };
29902
29905
  const propsDoc$P = {
29903
29906
  captionKey: "string",
29907
+ clearSearchOnBlur: "boolean",
29904
29908
  debounce: "number",
29905
29909
  disabled: "boolean",
29906
29910
  disableSelected: "boolean",
@@ -29909,6 +29913,7 @@ const propsDoc$P = {
29909
29913
  hideSelected: "boolean",
29910
29914
  icon: "SpsIcon",
29911
29915
  onChange: "ChangeEventHandler",
29916
+ onSearchChange: "(searchText: string) => void",
29912
29917
  options: "Eventually<any[]> | (filter?: string) => Eventually<any[]>",
29913
29918
  placeholder: "string",
29914
29919
  tallOptionList: "boolean",
@@ -29922,6 +29927,7 @@ const propsDoc$P = {
29922
29927
  const propTypes$R = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
29923
29928
  action: fun(),
29924
29929
  captionKey: propTypes$1O.exports.string,
29930
+ clearSearchOnBlur: propTypes$1O.exports.bool,
29925
29931
  debounce: propTypes$1O.exports.number,
29926
29932
  disabled: propTypes$1O.exports.bool,
29927
29933
  disableSelected: propTypes$1O.exports.bool,
@@ -29931,6 +29937,7 @@ const propTypes$R = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
29931
29937
  hideSelected: propTypes$1O.exports.bool,
29932
29938
  icon: enumValue(SpsIcon),
29933
29939
  onChange: fun(),
29940
+ onSearchChange: fun(),
29934
29941
  options: propTypes$1O.exports.oneOfType([
29935
29942
  propTypes$1O.exports.array,
29936
29943
  propTypes$1O.exports.instanceOf(Promise),
@@ -29950,6 +29957,7 @@ function SpsMultiSelect(_w) {
29950
29957
  action,
29951
29958
  captionKey,
29952
29959
  className,
29960
+ clearSearchOnBlur,
29953
29961
  debounce: debounce2,
29954
29962
  disabled,
29955
29963
  disableSelected = false,
@@ -29959,6 +29967,7 @@ function SpsMultiSelect(_w) {
29959
29967
  hideSelected,
29960
29968
  id: id2,
29961
29969
  onChange,
29970
+ onSearchChange,
29962
29971
  options,
29963
29972
  placeholder,
29964
29973
  tallOptionList,
@@ -29975,6 +29984,7 @@ function SpsMultiSelect(_w) {
29975
29984
  "action",
29976
29985
  "captionKey",
29977
29986
  "className",
29987
+ "clearSearchOnBlur",
29978
29988
  "debounce",
29979
29989
  "disabled",
29980
29990
  "disableSelected",
@@ -29984,6 +29994,7 @@ function SpsMultiSelect(_w) {
29984
29994
  "hideSelected",
29985
29995
  "id",
29986
29996
  "onChange",
29997
+ "onSearchChange",
29987
29998
  "options",
29988
29999
  "placeholder",
29989
30000
  "tallOptionList",
@@ -30006,15 +30017,27 @@ function SpsMultiSelect(_w) {
30006
30017
  activeTagIndex: null,
30007
30018
  optionIds: ""
30008
30019
  });
30020
+ React.useEffect(() => {
30021
+ if (onSearchChange) {
30022
+ onSearchChange(state.searchText);
30023
+ }
30024
+ }, [state.searchText]);
30009
30025
  const rootElement = React.useRef();
30010
30026
  const inputVisual = React.useRef();
30011
30027
  const textInput = React.useRef();
30012
30028
  const optionListRef = React.useRef();
30029
+ function handleBlur() {
30030
+ if (clearSearchOnBlur) {
30031
+ patchState({
30032
+ searchText: ""
30033
+ });
30034
+ }
30035
+ }
30013
30036
  const {
30014
30037
  showPopup,
30015
30038
  doShowPopup,
30016
30039
  doHidePopup
30017
- } = useInputPopup(rootElement, optionListRef);
30040
+ } = useInputPopup(rootElement, optionListRef, handleBlur);
30018
30041
  function open() {
30019
30042
  patchState({ activeTagIndex: null });
30020
30043
  doShowPopup();
@@ -30362,6 +30385,56 @@ const SpsMultiSelectExamples = {
30362
30385
  `
30363
30386
  }
30364
30387
  }
30388
+ },
30389
+ searchText: {
30390
+ label: "Search text",
30391
+ description: "Get search text",
30392
+ examples: {
30393
+ a_actionWithSearchText: {
30394
+ react: code`
30395
+ function Component() {
30396
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"]);
30397
+ const { formValue, formMeta, updateForm } = useSpsForm({
30398
+ tags: [opts[0]],
30399
+ });
30400
+
30401
+ const [searchText, setSearchText] = React.useState("");
30402
+
30403
+ React.useEffect(() => {
30404
+ updateAction({
30405
+ label: searchText ? \`Create a New Tag "\${searchText}"\` : "Create a New Tag",
30406
+ });
30407
+ }, [searchText, opts]);
30408
+
30409
+ const handleSearchChange = (searchTextValue) => {
30410
+ setSearchText(searchTextValue)
30411
+ }
30412
+
30413
+ const [action, updateAction] = useSpsAction(
30414
+ {
30415
+ label: "Create a New Tag",
30416
+ icon: SpsIcon.PLUS_SIGN,
30417
+ },
30418
+ () => console.log("New Tag has been created")
30419
+ );
30420
+
30421
+ return (
30422
+ <>
30423
+ <SpsLabel for={formMeta.fields.tags}>Tags</SpsLabel>
30424
+ <SpsMultiSelect
30425
+ disableSelected
30426
+ icon={SpsIcon.FILTER}
30427
+ options={opts}
30428
+ action={action}
30429
+ formMeta={formMeta.fields.tags}
30430
+ value={formValue.tags}
30431
+ onSearchChange={handleSearchChange}
30432
+ />
30433
+ </>
30434
+ );
30435
+ }`
30436
+ }
30437
+ }
30365
30438
  }
30366
30439
  };
30367
30440
  const propsDoc$O = {};
@@ -8,6 +8,7 @@ import type { SpsFormFieldMeta } from "../form/hooks/useSpsForm";
8
8
  declare const propTypes: {
9
9
  action: PropTypes.Requireable<SpsActionMethod>;
10
10
  captionKey: PropTypes.Requireable<string>;
11
+ clearSearchOnBlur: PropTypes.Requireable<boolean>;
11
12
  debounce: PropTypes.Requireable<number>;
12
13
  disabled: PropTypes.Requireable<boolean>;
13
14
  disableSelected: PropTypes.Requireable<boolean>;
@@ -17,6 +18,7 @@ declare const propTypes: {
17
18
  hideSelected: PropTypes.Requireable<boolean>;
18
19
  icon: PropTypes.Requireable<SpsIcon>;
19
20
  onChange: PropTypes.Requireable<React.ChangeEventHandler<Element>>;
21
+ onSearchChange: PropTypes.Requireable<(searchText: string) => void>;
20
22
  options: PropTypes.Validator<any[] | Promise<any[]> | ((filter?: string) => Eventually<any[]>)>;
21
23
  placeholder: PropTypes.Requireable<string>;
22
24
  tallOptionList: PropTypes.Requireable<boolean>;
@@ -32,5 +34,5 @@ declare const propTypes: {
32
34
  unsafelyReplaceClassName: PropTypes.Requireable<string>;
33
35
  };
34
36
  export declare type SpsMultiSelectProps = PropTypes.InferTS<typeof propTypes, HTMLInputElement>;
35
- export declare function SpsMultiSelect({ action, captionKey, className, debounce, disabled, disableSelected, comparisonKey, formControl, formMeta, hideSelected, id, onChange, options, placeholder, tallOptionList, textKey, unsafelyReplaceClassName, value, zeroState, loading, icon, maxHeightOptionListPx, maxHeightOptionListRem, "data-testid": testId, ...rest }: SpsMultiSelectProps): JSX.Element;
37
+ export declare function SpsMultiSelect({ action, captionKey, className, clearSearchOnBlur, debounce, disabled, disableSelected, comparisonKey, formControl, formMeta, hideSelected, id, onChange, onSearchChange, options, placeholder, tallOptionList, textKey, unsafelyReplaceClassName, value, zeroState, loading, icon, maxHeightOptionListPx, maxHeightOptionListRem, "data-testid": testId, ...rest }: SpsMultiSelectProps): JSX.Element;
36
38
  export {};
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- export declare function useInputPopup(rootRef: React.MutableRefObject<HTMLElement>, popupRef: React.MutableRefObject<HTMLElement>): {
2
+ export declare function useInputPopup(rootRef: React.MutableRefObject<HTMLElement>, popupRef: React.MutableRefObject<HTMLElement>, onHide?: () => void): {
3
3
  showPopup: boolean;
4
4
  doShowPopup: () => void;
5
5
  doHidePopup: (suppressNextShow?: any) => void;
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": "5.19.0",
4
+ "version": "5.20.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,11 +28,11 @@
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@react-stately/collections": "^3.3.3",
31
- "@spscommerce/ds-colors": "5.19.0",
32
- "@spscommerce/ds-illustrations": "5.19.0",
33
- "@spscommerce/ds-shared": "5.19.0",
34
- "@spscommerce/positioning": "5.19.0",
35
- "@spscommerce/utils": "5.19.0",
31
+ "@spscommerce/ds-colors": "5.20.0",
32
+ "@spscommerce/ds-illustrations": "5.20.0",
33
+ "@spscommerce/ds-shared": "5.20.0",
34
+ "@spscommerce/positioning": "5.20.0",
35
+ "@spscommerce/utils": "5.20.0",
36
36
  "moment": "^2.25.3",
37
37
  "moment-timezone": "^0.5.28",
38
38
  "react": "^16.9.0",
@@ -40,11 +40,11 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@react-stately/collections": "^3.3.3",
43
- "@spscommerce/ds-colors": "5.19.0",
44
- "@spscommerce/ds-illustrations": "5.19.0",
45
- "@spscommerce/ds-shared": "5.19.0",
46
- "@spscommerce/positioning": "5.19.0",
47
- "@spscommerce/utils": "5.19.0",
43
+ "@spscommerce/ds-colors": "5.20.0",
44
+ "@spscommerce/ds-illustrations": "5.20.0",
45
+ "@spscommerce/ds-shared": "5.20.0",
46
+ "@spscommerce/positioning": "5.20.0",
47
+ "@spscommerce/utils": "5.20.0",
48
48
  "@testing-library/react": "^9.3.2",
49
49
  "@types/prop-types": "^15.7.1",
50
50
  "@types/react": "^16.9.0",