@spscommerce/ds-react 5.19.0 → 5.20.2

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
@@ -2036,6 +2036,9 @@ function compareOptions(optionA, optionB, comparisonKey) {
2036
2036
  return comparisonKey ? (optionA && optionA[comparisonKey]) === (optionB && optionB[comparisonKey]) : optionA === optionB;
2037
2037
  }
2038
2038
  function isOptionDisabled(disabledOptions, comparisonKey, option) {
2039
+ if (typeof option.value === "function" && option.disabled) {
2040
+ return true;
2041
+ }
2039
2042
  return comparisonKey ? !!(disabledOptions == null ? void 0 : disabledOptions.find((opt) => {
2040
2043
  var _a;
2041
2044
  return opt[comparisonKey] && opt[comparisonKey] === ((_a = option == null ? void 0 : option.value) == null ? void 0 : _a[comparisonKey]);
@@ -2458,12 +2461,13 @@ function useDocumentEventListener(eventName, listenerFactory, deps) {
2458
2461
  }
2459
2462
  function documentClickHandlerFactory(rootRef, popupRef, doHidePopup) {
2460
2463
  return function documentClickHandler(event) {
2461
- if (!rootRef.current.contains(event.target) && !popupRef.current.contains(event.target)) {
2464
+ var _a, _b;
2465
+ if (!((_a = rootRef.current) == null ? void 0 : _a.contains(event.target)) && !((_b = popupRef.current) == null ? void 0 : _b.contains(event.target))) {
2462
2466
  doHidePopup();
2463
2467
  }
2464
2468
  };
2465
2469
  }
2466
- function useInputPopup(rootRef, popupRef) {
2470
+ function useInputPopup(rootRef, popupRef, onHide) {
2467
2471
  const suppressPopup = React.useRef(false);
2468
2472
  const [showPopup, setShowPopup] = React.useState(false);
2469
2473
  const doShowPopup = React.useCallback(() => {
@@ -2476,6 +2480,9 @@ function useInputPopup(rootRef, popupRef) {
2476
2480
  const doHidePopup = React.useCallback((suppressNextShow = false) => {
2477
2481
  setShowPopup(false);
2478
2482
  suppressPopup.current = suppressNextShow;
2483
+ if (onHide) {
2484
+ onHide();
2485
+ }
2479
2486
  }, []);
2480
2487
  useDocumentEventListener("click", documentClickHandlerFactory, [
2481
2488
  rootRef,
@@ -15350,7 +15357,7 @@ function SpsContentRowCol(props2) {
15350
15357
  ].join(" "));
15351
15358
  }
15352
15359
  }, [leaner]);
15353
- const classes = clsx(unsafelyReplaceClassName || "sps-content-row__col", borderless && "sps-content-row__col--borderless", (lean || leaner) && "sps-content-row__col--lean");
15360
+ const classes = clsx(unsafelyReplaceClassName || "sps-content-row__col", borderless && "sps-content-row__col--borderless", (lean || leaner) && "sps-content-row__col--lean", className);
15354
15361
  const width = widthPx ? widthPx / 16 : widthRem;
15355
15362
  const inlineStyles = width ? __spreadProps(__spreadValues({}, style2), {
15356
15363
  width: `${width}rem`
@@ -29901,6 +29908,7 @@ const SpsModalExamples = {
29901
29908
  };
29902
29909
  const propsDoc$P = {
29903
29910
  captionKey: "string",
29911
+ clearSearchOnBlur: "boolean",
29904
29912
  debounce: "number",
29905
29913
  disabled: "boolean",
29906
29914
  disableSelected: "boolean",
@@ -29909,6 +29917,7 @@ const propsDoc$P = {
29909
29917
  hideSelected: "boolean",
29910
29918
  icon: "SpsIcon",
29911
29919
  onChange: "ChangeEventHandler",
29920
+ onSearchChange: "(searchText: string) => void",
29912
29921
  options: "Eventually<any[]> | (filter?: string) => Eventually<any[]>",
29913
29922
  placeholder: "string",
29914
29923
  tallOptionList: "boolean",
@@ -29922,6 +29931,7 @@ const propsDoc$P = {
29922
29931
  const propTypes$R = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
29923
29932
  action: fun(),
29924
29933
  captionKey: propTypes$1O.exports.string,
29934
+ clearSearchOnBlur: propTypes$1O.exports.bool,
29925
29935
  debounce: propTypes$1O.exports.number,
29926
29936
  disabled: propTypes$1O.exports.bool,
29927
29937
  disableSelected: propTypes$1O.exports.bool,
@@ -29931,6 +29941,7 @@ const propTypes$R = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
29931
29941
  hideSelected: propTypes$1O.exports.bool,
29932
29942
  icon: enumValue(SpsIcon),
29933
29943
  onChange: fun(),
29944
+ onSearchChange: fun(),
29934
29945
  options: propTypes$1O.exports.oneOfType([
29935
29946
  propTypes$1O.exports.array,
29936
29947
  propTypes$1O.exports.instanceOf(Promise),
@@ -29950,6 +29961,7 @@ function SpsMultiSelect(_w) {
29950
29961
  action,
29951
29962
  captionKey,
29952
29963
  className,
29964
+ clearSearchOnBlur,
29953
29965
  debounce: debounce2,
29954
29966
  disabled,
29955
29967
  disableSelected = false,
@@ -29959,6 +29971,7 @@ function SpsMultiSelect(_w) {
29959
29971
  hideSelected,
29960
29972
  id: id2,
29961
29973
  onChange,
29974
+ onSearchChange,
29962
29975
  options,
29963
29976
  placeholder,
29964
29977
  tallOptionList,
@@ -29975,6 +29988,7 @@ function SpsMultiSelect(_w) {
29975
29988
  "action",
29976
29989
  "captionKey",
29977
29990
  "className",
29991
+ "clearSearchOnBlur",
29978
29992
  "debounce",
29979
29993
  "disabled",
29980
29994
  "disableSelected",
@@ -29984,6 +29998,7 @@ function SpsMultiSelect(_w) {
29984
29998
  "hideSelected",
29985
29999
  "id",
29986
30000
  "onChange",
30001
+ "onSearchChange",
29987
30002
  "options",
29988
30003
  "placeholder",
29989
30004
  "tallOptionList",
@@ -30006,15 +30021,27 @@ function SpsMultiSelect(_w) {
30006
30021
  activeTagIndex: null,
30007
30022
  optionIds: ""
30008
30023
  });
30024
+ React.useEffect(() => {
30025
+ if (onSearchChange) {
30026
+ onSearchChange(state.searchText);
30027
+ }
30028
+ }, [state.searchText]);
30009
30029
  const rootElement = React.useRef();
30010
30030
  const inputVisual = React.useRef();
30011
30031
  const textInput = React.useRef();
30012
30032
  const optionListRef = React.useRef();
30033
+ function handleBlur() {
30034
+ if (clearSearchOnBlur) {
30035
+ patchState({
30036
+ searchText: ""
30037
+ });
30038
+ }
30039
+ }
30013
30040
  const {
30014
30041
  showPopup,
30015
30042
  doShowPopup,
30016
30043
  doHidePopup
30017
- } = useInputPopup(rootElement, optionListRef);
30044
+ } = useInputPopup(rootElement, optionListRef, handleBlur);
30018
30045
  function open() {
30019
30046
  patchState({ activeTagIndex: null });
30020
30047
  doShowPopup();
@@ -30362,6 +30389,56 @@ const SpsMultiSelectExamples = {
30362
30389
  `
30363
30390
  }
30364
30391
  }
30392
+ },
30393
+ searchText: {
30394
+ label: "Search text",
30395
+ description: "Get search text",
30396
+ examples: {
30397
+ a_actionWithSearchText: {
30398
+ react: code`
30399
+ function Component() {
30400
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"]);
30401
+ const { formValue, formMeta, updateForm } = useSpsForm({
30402
+ tags: [opts[0]],
30403
+ });
30404
+
30405
+ const [searchText, setSearchText] = React.useState("");
30406
+
30407
+ React.useEffect(() => {
30408
+ updateAction({
30409
+ label: searchText ? \`Create a New Tag "\${searchText}"\` : "Create a New Tag",
30410
+ });
30411
+ }, [searchText, opts]);
30412
+
30413
+ const handleSearchChange = (searchTextValue) => {
30414
+ setSearchText(searchTextValue)
30415
+ }
30416
+
30417
+ const [action, updateAction] = useSpsAction(
30418
+ {
30419
+ label: "Create a New Tag",
30420
+ icon: SpsIcon.PLUS_SIGN,
30421
+ },
30422
+ () => console.log("New Tag has been created")
30423
+ );
30424
+
30425
+ return (
30426
+ <>
30427
+ <SpsLabel for={formMeta.fields.tags}>Tags</SpsLabel>
30428
+ <SpsMultiSelect
30429
+ disableSelected
30430
+ icon={SpsIcon.FILTER}
30431
+ options={opts}
30432
+ action={action}
30433
+ formMeta={formMeta.fields.tags}
30434
+ value={formValue.tags}
30435
+ onSearchChange={handleSearchChange}
30436
+ />
30437
+ </>
30438
+ );
30439
+ }`
30440
+ }
30441
+ }
30365
30442
  }
30366
30443
  };
30367
30444
  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.2",
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.2",
32
+ "@spscommerce/ds-illustrations": "5.20.2",
33
+ "@spscommerce/ds-shared": "5.20.2",
34
+ "@spscommerce/positioning": "5.20.2",
35
+ "@spscommerce/utils": "5.20.2",
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.2",
44
+ "@spscommerce/ds-illustrations": "5.20.2",
45
+ "@spscommerce/ds-shared": "5.20.2",
46
+ "@spscommerce/positioning": "5.20.2",
47
+ "@spscommerce/utils": "5.20.2",
48
48
  "@testing-library/react": "^9.3.2",
49
49
  "@types/prop-types": "^15.7.1",
50
50
  "@types/react": "^16.9.0",