@spscommerce/ds-react 5.18.3 → 5.20.1

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
@@ -2458,12 +2458,13 @@ function useDocumentEventListener(eventName, listenerFactory, deps) {
2458
2458
  }
2459
2459
  function documentClickHandlerFactory(rootRef, popupRef, doHidePopup) {
2460
2460
  return function documentClickHandler(event) {
2461
- if (!rootRef.current.contains(event.target) && !popupRef.current.contains(event.target)) {
2461
+ var _a, _b;
2462
+ if (!((_a = rootRef.current) == null ? void 0 : _a.contains(event.target)) && !((_b = popupRef.current) == null ? void 0 : _b.contains(event.target))) {
2462
2463
  doHidePopup();
2463
2464
  }
2464
2465
  };
2465
2466
  }
2466
- function useInputPopup(rootRef, popupRef) {
2467
+ function useInputPopup(rootRef, popupRef, onHide) {
2467
2468
  const suppressPopup = React.useRef(false);
2468
2469
  const [showPopup, setShowPopup] = React.useState(false);
2469
2470
  const doShowPopup = React.useCallback(() => {
@@ -2476,6 +2477,9 @@ function useInputPopup(rootRef, popupRef) {
2476
2477
  const doHidePopup = React.useCallback((suppressNextShow = false) => {
2477
2478
  setShowPopup(false);
2478
2479
  suppressPopup.current = suppressNextShow;
2480
+ if (onHide) {
2481
+ onHide();
2482
+ }
2479
2483
  }, []);
2480
2484
  useDocumentEventListener("click", documentClickHandlerFactory, [
2481
2485
  rootRef,
@@ -15350,7 +15354,7 @@ function SpsContentRowCol(props2) {
15350
15354
  ].join(" "));
15351
15355
  }
15352
15356
  }, [leaner]);
15353
- const classes = clsx(unsafelyReplaceClassName || "sps-content-row__col", borderless && "sps-content-row__col--borderless", (lean || leaner) && "sps-content-row__col--lean");
15357
+ const classes = clsx(unsafelyReplaceClassName || "sps-content-row__col", borderless && "sps-content-row__col--borderless", (lean || leaner) && "sps-content-row__col--lean", className);
15354
15358
  const width = widthPx ? widthPx / 16 : widthRem;
15355
15359
  const inlineStyles = width ? __spreadProps(__spreadValues({}, style2), {
15356
15360
  width: `${width}rem`
@@ -28451,11 +28455,13 @@ Object.assign(SpsListToolbar, {
28451
28455
  });
28452
28456
  const propsDoc$S = {
28453
28457
  options: "SortOption[]",
28454
- onSortChange: "(key: string, direction: SortDirection) => void",
28458
+ activeOption: "SortOption",
28459
+ onSortChange: "(option: SortOption) => void",
28455
28460
  defaultOption: "SortOption"
28456
28461
  };
28457
28462
  const propTypes$U = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
28458
28463
  options: propTypes$1O.exports.arrayOf(impl()),
28464
+ activeOption: impl(),
28459
28465
  onSortChange: fun(),
28460
28466
  defaultOption: impl()
28461
28467
  });
@@ -28464,24 +28470,16 @@ function SpsListToolbarSortBy(props2) {
28464
28470
  options,
28465
28471
  onSortChange,
28466
28472
  defaultOption,
28473
+ activeOption,
28467
28474
  className,
28468
28475
  unsafelyReplaceClassName
28469
28476
  } = props2;
28470
- const [label, setLabel] = React.useState(defaultOption.label || "");
28471
- const [directionIcon, setDirectionIcon] = React.useState(defaultOption.icon);
28472
- const sortOptions = options.map((option) => [
28473
- { label: option.label, icon: option.icon },
28474
- () => {
28475
- setLabel(option.label);
28476
- setDirectionIcon(option.icon);
28477
- onSortChange(option.key, option.direction);
28478
- }
28479
- ]);
28477
+ const sortOptions = options.map((option) => [{ label: option.label, icon: option.icon }, () => onSortChange(option)]);
28480
28478
  const classes = clsx(unsafelyReplaceClassName || "sps-list-toolbar-sort-by", className);
28481
28479
  return /* @__PURE__ */ React.createElement(SpsDropdown, {
28482
28480
  className: classes,
28483
- icon: directionIcon,
28484
- label,
28481
+ icon: (activeOption == null ? void 0 : activeOption.icon) || (defaultOption == null ? void 0 : defaultOption.icon),
28482
+ label: (activeOption == null ? void 0 : activeOption.label) || (defaultOption == null ? void 0 : defaultOption.label),
28485
28483
  options: sortOptions
28486
28484
  });
28487
28485
  }
@@ -29177,53 +29175,53 @@ const SpsListToolbarExamples = {
29177
29175
  title: {
29178
29176
  react: code`
29179
29177
  function Component() {
29178
+ const [activeOption, setActiveOption] = React.useState(null);
29179
+ const defaultOption = {
29180
+ label: "Default",
29181
+ key: "default",
29182
+ direction: SortDirection.ASCENDING,
29183
+ icon: SpsIcon.SORT_ALPHA_ASC,
29184
+ }
29185
+ const options = [
29186
+ defaultOption,
29187
+ {
29188
+ label: "Company Name: A-Z",
29189
+ key: "name",
29190
+ direction: SortDirection.ASCENDING,
29191
+ icon: SpsIcon.SORT_ALPHA_ASC,
29192
+ },
29193
+ {
29194
+ label: "Company Name: Z-A",
29195
+ key: "name",
29196
+ direction: SortDirection.DESCENDING,
29197
+ icon: SpsIcon.SORT_ALPHA_DESC,
29198
+ },
29199
+ {
29200
+ label: 'Created Date: Oldest to Newest',
29201
+ key: 'created',
29202
+ direction: SortDirection.ASCENDING,
29203
+ icon: SpsIcon.SORT_NUM_ASC,
29204
+ },
29205
+ {
29206
+ label: 'Created Date: Newest to Oldest',
29207
+ key: 'created',
29208
+ direction: SortDirection.DESCENDING,
29209
+ icon: SpsIcon.SORT_NUM_DESC,
29210
+ }
29211
+ ]
29212
+
29180
29213
  return (
29181
29214
  <SpsListToolbar title="List of sortable rows">
29182
- <SpsButton kind={ButtonKind.ICON} icon={SpsIcon.DOWNLOAD_CLOUD} />
29183
- <SpsVerticalRule />
29184
- <SpsListToolbarSortBy
29185
- options={[
29186
- {
29187
- label: "Default",
29188
- key: "default",
29189
- direction: SortDirection.ASCENDING,
29190
- icon: SpsIcon.SORT_ALPHA_ASC,
29191
- },
29192
- {
29193
- label: "Company Name: A-Z",
29194
- key: "name",
29195
- direction: SortDirection.ASCENDING,
29196
- icon: SpsIcon.SORT_ALPHA_ASC,
29197
- },
29198
- {
29199
- label: "Company Name: Z-A",
29200
- key: "name",
29201
- direction: SortDirection.DESCENDING,
29202
- icon: SpsIcon.SORT_ALPHA_DESC,
29203
- },
29204
- {
29205
- label: 'Created Date: Oldest to Newest',
29206
- key: 'created',
29207
- direction: SortDirection.ASCENDING,
29208
- icon: SpsIcon.SORT_NUM_ASC,
29209
- },
29210
- {
29211
- label: 'Created Date: Newest to Oldest',
29212
- key: 'created',
29213
- direction: SortDirection.DESCENDING,
29214
- icon: SpsIcon.SORT_NUM_DESC,
29215
- }
29216
- ]}
29217
- defaultOption={{
29218
- label: "Default",
29219
- key: "default",
29220
- direction: SortDirection.ASCENDING,
29221
- icon: SpsIcon.SORT_ALPHA_ASC,
29222
- }}
29223
- onSortChange={(key, direction) => console.log(key, direction)}
29224
- />
29225
- <SpsVerticalRule />
29226
- <SpsButton kind={ButtonKind.CONFIRM}>Create New</SpsButton>
29215
+ <SpsButton kind={ButtonKind.ICON} icon={SpsIcon.DOWNLOAD_CLOUD} />
29216
+ <SpsVerticalRule />
29217
+ <SpsListToolbarSortBy
29218
+ options={options}
29219
+ activeOption={activeOption}
29220
+ defaultOption={defaultOption}
29221
+ onSortChange={(option) => setActiveOption(option)}
29222
+ />
29223
+ <SpsVerticalRule />
29224
+ <SpsButton kind={ButtonKind.CONFIRM}>Create New</SpsButton>
29227
29225
  </SpsListToolbar>
29228
29226
  )
29229
29227
  }
@@ -29907,6 +29905,7 @@ const SpsModalExamples = {
29907
29905
  };
29908
29906
  const propsDoc$P = {
29909
29907
  captionKey: "string",
29908
+ clearSearchOnBlur: "boolean",
29910
29909
  debounce: "number",
29911
29910
  disabled: "boolean",
29912
29911
  disableSelected: "boolean",
@@ -29915,6 +29914,7 @@ const propsDoc$P = {
29915
29914
  hideSelected: "boolean",
29916
29915
  icon: "SpsIcon",
29917
29916
  onChange: "ChangeEventHandler",
29917
+ onSearchChange: "(searchText: string) => void",
29918
29918
  options: "Eventually<any[]> | (filter?: string) => Eventually<any[]>",
29919
29919
  placeholder: "string",
29920
29920
  tallOptionList: "boolean",
@@ -29928,6 +29928,7 @@ const propsDoc$P = {
29928
29928
  const propTypes$R = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
29929
29929
  action: fun(),
29930
29930
  captionKey: propTypes$1O.exports.string,
29931
+ clearSearchOnBlur: propTypes$1O.exports.bool,
29931
29932
  debounce: propTypes$1O.exports.number,
29932
29933
  disabled: propTypes$1O.exports.bool,
29933
29934
  disableSelected: propTypes$1O.exports.bool,
@@ -29937,6 +29938,7 @@ const propTypes$R = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
29937
29938
  hideSelected: propTypes$1O.exports.bool,
29938
29939
  icon: enumValue(SpsIcon),
29939
29940
  onChange: fun(),
29941
+ onSearchChange: fun(),
29940
29942
  options: propTypes$1O.exports.oneOfType([
29941
29943
  propTypes$1O.exports.array,
29942
29944
  propTypes$1O.exports.instanceOf(Promise),
@@ -29956,6 +29958,7 @@ function SpsMultiSelect(_w) {
29956
29958
  action,
29957
29959
  captionKey,
29958
29960
  className,
29961
+ clearSearchOnBlur,
29959
29962
  debounce: debounce2,
29960
29963
  disabled,
29961
29964
  disableSelected = false,
@@ -29965,6 +29968,7 @@ function SpsMultiSelect(_w) {
29965
29968
  hideSelected,
29966
29969
  id: id2,
29967
29970
  onChange,
29971
+ onSearchChange,
29968
29972
  options,
29969
29973
  placeholder,
29970
29974
  tallOptionList,
@@ -29981,6 +29985,7 @@ function SpsMultiSelect(_w) {
29981
29985
  "action",
29982
29986
  "captionKey",
29983
29987
  "className",
29988
+ "clearSearchOnBlur",
29984
29989
  "debounce",
29985
29990
  "disabled",
29986
29991
  "disableSelected",
@@ -29990,6 +29995,7 @@ function SpsMultiSelect(_w) {
29990
29995
  "hideSelected",
29991
29996
  "id",
29992
29997
  "onChange",
29998
+ "onSearchChange",
29993
29999
  "options",
29994
30000
  "placeholder",
29995
30001
  "tallOptionList",
@@ -30012,15 +30018,27 @@ function SpsMultiSelect(_w) {
30012
30018
  activeTagIndex: null,
30013
30019
  optionIds: ""
30014
30020
  });
30021
+ React.useEffect(() => {
30022
+ if (onSearchChange) {
30023
+ onSearchChange(state.searchText);
30024
+ }
30025
+ }, [state.searchText]);
30015
30026
  const rootElement = React.useRef();
30016
30027
  const inputVisual = React.useRef();
30017
30028
  const textInput = React.useRef();
30018
30029
  const optionListRef = React.useRef();
30030
+ function handleBlur() {
30031
+ if (clearSearchOnBlur) {
30032
+ patchState({
30033
+ searchText: ""
30034
+ });
30035
+ }
30036
+ }
30019
30037
  const {
30020
30038
  showPopup,
30021
30039
  doShowPopup,
30022
30040
  doHidePopup
30023
- } = useInputPopup(rootElement, optionListRef);
30041
+ } = useInputPopup(rootElement, optionListRef, handleBlur);
30024
30042
  function open() {
30025
30043
  patchState({ activeTagIndex: null });
30026
30044
  doShowPopup();
@@ -30368,6 +30386,56 @@ const SpsMultiSelectExamples = {
30368
30386
  `
30369
30387
  }
30370
30388
  }
30389
+ },
30390
+ searchText: {
30391
+ label: "Search text",
30392
+ description: "Get search text",
30393
+ examples: {
30394
+ a_actionWithSearchText: {
30395
+ react: code`
30396
+ function Component() {
30397
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"]);
30398
+ const { formValue, formMeta, updateForm } = useSpsForm({
30399
+ tags: [opts[0]],
30400
+ });
30401
+
30402
+ const [searchText, setSearchText] = React.useState("");
30403
+
30404
+ React.useEffect(() => {
30405
+ updateAction({
30406
+ label: searchText ? \`Create a New Tag "\${searchText}"\` : "Create a New Tag",
30407
+ });
30408
+ }, [searchText, opts]);
30409
+
30410
+ const handleSearchChange = (searchTextValue) => {
30411
+ setSearchText(searchTextValue)
30412
+ }
30413
+
30414
+ const [action, updateAction] = useSpsAction(
30415
+ {
30416
+ label: "Create a New Tag",
30417
+ icon: SpsIcon.PLUS_SIGN,
30418
+ },
30419
+ () => console.log("New Tag has been created")
30420
+ );
30421
+
30422
+ return (
30423
+ <>
30424
+ <SpsLabel for={formMeta.fields.tags}>Tags</SpsLabel>
30425
+ <SpsMultiSelect
30426
+ disableSelected
30427
+ icon={SpsIcon.FILTER}
30428
+ options={opts}
30429
+ action={action}
30430
+ formMeta={formMeta.fields.tags}
30431
+ value={formValue.tags}
30432
+ onSearchChange={handleSearchChange}
30433
+ />
30434
+ </>
30435
+ );
30436
+ }`
30437
+ }
30438
+ }
30371
30439
  }
30372
30440
  };
30373
30441
  const propsDoc$O = {};
@@ -8,7 +8,8 @@ export interface SortOption {
8
8
  }
9
9
  declare const propTypes: {
10
10
  options: PropTypes.Requireable<SortOption[]>;
11
- onSortChange: PropTypes.Requireable<(key: string, direction: SortDirection) => void>;
11
+ activeOption: PropTypes.Requireable<SortOption>;
12
+ onSortChange: PropTypes.Requireable<(option: SortOption) => void>;
12
13
  defaultOption: PropTypes.Requireable<SortOption>;
13
14
  children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
14
15
  className: PropTypes.Requireable<string>;
@@ -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.18.3",
4
+ "version": "5.20.1",
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.18.3",
32
- "@spscommerce/ds-illustrations": "5.18.3",
33
- "@spscommerce/ds-shared": "5.18.3",
34
- "@spscommerce/positioning": "5.18.3",
35
- "@spscommerce/utils": "5.18.3",
31
+ "@spscommerce/ds-colors": "5.20.1",
32
+ "@spscommerce/ds-illustrations": "5.20.1",
33
+ "@spscommerce/ds-shared": "5.20.1",
34
+ "@spscommerce/positioning": "5.20.1",
35
+ "@spscommerce/utils": "5.20.1",
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.18.3",
44
- "@spscommerce/ds-illustrations": "5.18.3",
45
- "@spscommerce/ds-shared": "5.18.3",
46
- "@spscommerce/positioning": "5.18.3",
47
- "@spscommerce/utils": "5.18.3",
43
+ "@spscommerce/ds-colors": "5.20.1",
44
+ "@spscommerce/ds-illustrations": "5.20.1",
45
+ "@spscommerce/ds-shared": "5.20.1",
46
+ "@spscommerce/positioning": "5.20.1",
47
+ "@spscommerce/utils": "5.20.1",
48
48
  "@testing-library/react": "^9.3.2",
49
49
  "@types/prop-types": "^15.7.1",
50
50
  "@types/react": "^16.9.0",