@spscommerce/ds-react 5.33.9 → 5.33.12

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
@@ -23060,7 +23060,7 @@ function SpsFieldset({
23060
23060
  legend,
23061
23061
  unsafelyReplaceClassName,
23062
23062
  optional = false,
23063
- enabled,
23063
+ enabled = false,
23064
23064
  onToggled,
23065
23065
  tooltip,
23066
23066
  "data-testid": testId
@@ -23070,14 +23070,9 @@ function SpsFieldset({
23070
23070
  const infoCircleElement = React.useRef(null);
23071
23071
  const [showTip, setShowTip] = React.useState(TooltipVisibility.HIDDEN);
23072
23072
  const [wasFocused, setWasFocused] = React.useState(false);
23073
- const [isChecked, setisChecked] = React.useState(false);
23074
- React.useEffect(() => {
23075
- setisChecked(enabled);
23076
- }, [enabled]);
23077
- React.useEffect(() => {
23078
- if (typeof onToggled === "function") {
23079
- onToggled(isChecked);
23080
- }
23073
+ const [isChecked, setIsChecked] = React.useState(enabled);
23074
+ useDidUpdateEffect(() => {
23075
+ onToggled == null ? void 0 : onToggled(isChecked);
23081
23076
  }, [isChecked]);
23082
23077
  React.useEffect(() => {
23083
23078
  if (formControlSet || formMeta) {
@@ -23109,7 +23104,7 @@ function SpsFieldset({
23109
23104
  checked: isChecked,
23110
23105
  className: "d-inline-flex",
23111
23106
  onChange: () => {
23112
- setisChecked(!isChecked);
23107
+ setIsChecked(!isChecked);
23113
23108
  },
23114
23109
  "data-testid": `${testId}__checkbox`
23115
23110
  }), legend, tooltip && /* @__PURE__ */ React.createElement("span", {
@@ -31076,13 +31071,15 @@ const propsDoc$L = {
31076
31071
  page: "number",
31077
31072
  numPages: "number",
31078
31073
  onPageChange: "(number) => void",
31079
- disabled: "boolean"
31074
+ disabled: "boolean",
31075
+ unknownPageCount: "boolean"
31080
31076
  };
31081
31077
  const propTypes$N = __spreadValues({
31082
31078
  numPages: propTypes$1O.exports.number,
31083
31079
  onPageChange: fun(),
31084
31080
  page: propTypes$1O.exports.number,
31085
- disabled: propTypes$1O.exports.bool
31081
+ disabled: propTypes$1O.exports.bool,
31082
+ unknownPageCount: propTypes$1O.exports.bool
31086
31083
  }, spsGlobalPropTypes);
31087
31084
  function SpsPageSelector(props2) {
31088
31085
  const _a = props2, {
@@ -31092,7 +31089,8 @@ function SpsPageSelector(props2) {
31092
31089
  unsafelyReplaceClassName,
31093
31090
  className,
31094
31091
  "data-testid": testId,
31095
- disabled = false
31092
+ disabled = false,
31093
+ unknownPageCount = false
31096
31094
  } = _a, rest = __objRest(_a, [
31097
31095
  "numPages",
31098
31096
  "onPageChange",
@@ -31100,7 +31098,8 @@ function SpsPageSelector(props2) {
31100
31098
  "unsafelyReplaceClassName",
31101
31099
  "className",
31102
31100
  "data-testid",
31103
- "disabled"
31101
+ "disabled",
31102
+ "unknownPageCount"
31104
31103
  ]);
31105
31104
  const { t: t2 } = React.useContext(I18nContext);
31106
31105
  const [inputPage, setInputPage] = React.useState(pageProp);
@@ -31111,7 +31110,7 @@ function SpsPageSelector(props2) {
31111
31110
  }, [pageProp]);
31112
31111
  function updatePage(newPage) {
31113
31112
  const constrainedPage = constrain(newPage, [1, numPages]);
31114
- if (constrainedPage !== inputPage) {
31113
+ if (newPage !== page) {
31115
31114
  setPage(constrainedPage);
31116
31115
  setInputPage(constrainedPage);
31117
31116
  if (onPageChange && typeof onPageChange === "function") {
@@ -31119,17 +31118,15 @@ function SpsPageSelector(props2) {
31119
31118
  }
31120
31119
  }
31121
31120
  }
31122
- const debouncedPageUpdate = debounce(updatePage, 500);
31123
31121
  function onTextInputInput(event) {
31124
- setInputPage(event.target.value);
31125
- void debouncedPageUpdate(parseInt(event.target.value, 10));
31122
+ setInputPage(Number(event.target.value) || "");
31126
31123
  }
31127
31124
  const classes = clsx(unsafelyReplaceClassName || "sps-page-selector", className);
31128
31125
  const id2 = useElementId(null);
31129
31126
  return /* @__PURE__ */ React.createElement("div", __spreadValues({
31130
31127
  className: classes,
31131
31128
  "data-testid": testId
31132
- }, rest), /* @__PURE__ */ React.createElement("div", {
31129
+ }, rest), !unknownPageCount && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
31133
31130
  className: "sps-pagination__input-wrapper",
31134
31131
  "data-testid": `${testId}__input`
31135
31132
  }, /* @__PURE__ */ React.createElement("div", {
@@ -31137,7 +31134,9 @@ function SpsPageSelector(props2) {
31137
31134
  }, inputPage), /* @__PURE__ */ React.createElement("label", {
31138
31135
  htmlFor: id2.current,
31139
31136
  className: "sr-only"
31140
- }, t2("design-system:pagination.page")), /* @__PURE__ */ React.createElement("input", {
31137
+ }, t2("design-system:pagination.page")), /* @__PURE__ */ React.createElement(SpsForm, {
31138
+ onSubmit: () => updatePage(Number(inputPage))
31139
+ }, /* @__PURE__ */ React.createElement("input", {
31141
31140
  id: id2.current,
31142
31141
  type: "text",
31143
31142
  value: inputPage,
@@ -31145,11 +31144,12 @@ function SpsPageSelector(props2) {
31145
31144
  onChange: () => {
31146
31145
  },
31147
31146
  className: "sps-form-control sps-pagination__input",
31148
- disabled
31149
- })), /* @__PURE__ */ React.createElement("span", {
31147
+ disabled,
31148
+ onBlur: () => updatePage(Number(inputPage))
31149
+ }))), /* @__PURE__ */ React.createElement("span", {
31150
31150
  className: "sps-page-selector__total-pages",
31151
31151
  "data-testid": `${testId}_page-count`
31152
- }, Number.isNaN(numPages) ? t2("design-system:pagination.ofMany") : t2("design-system:pagination.ofPageCount", { pageCount: numPages })), /* @__PURE__ */ React.createElement("div", {
31152
+ }, Number.isNaN(numPages) ? t2("design-system:pagination.ofMany") : t2("design-system:pagination.ofPageCount", { pageCount: numPages }))), /* @__PURE__ */ React.createElement("div", {
31153
31153
  className: "sps-icon-button-panel",
31154
31154
  "data-testid": `${testId}__buttons`
31155
31155
  }, /* @__PURE__ */ React.createElement("div", {
@@ -31185,7 +31185,8 @@ const propsDoc$K = {
31185
31185
  pageSizeOptions: "Array<number>",
31186
31186
  totalResults: "number",
31187
31187
  onPageChange: "(page: number, pageSize: number, indices: [number, number]) => void",
31188
- disabled: "boolean"
31188
+ disabled: "boolean",
31189
+ unknownPageCount: "boolean"
31189
31190
  };
31190
31191
  const propTypes$M = __spreadValues({
31191
31192
  onPageChange: fun().isRequired,
@@ -31193,7 +31194,8 @@ const propTypes$M = __spreadValues({
31193
31194
  pageSize: propTypes$1O.exports.number,
31194
31195
  pageSizeOptions: propTypes$1O.exports.arrayOf(propTypes$1O.exports.number),
31195
31196
  totalResults: propTypes$1O.exports.number,
31196
- disabled: propTypes$1O.exports.bool
31197
+ disabled: propTypes$1O.exports.bool,
31198
+ unknownPageCount: propTypes$1O.exports.bool
31197
31199
  }, spsGlobalPropTypes);
31198
31200
  function SpsPagination(props2) {
31199
31201
  const _a = props2, {
@@ -31205,7 +31207,8 @@ function SpsPagination(props2) {
31205
31207
  "data-testid": testId,
31206
31208
  totalResults,
31207
31209
  unsafelyReplaceClassName,
31208
- disabled = false
31210
+ disabled = false,
31211
+ unknownPageCount = false
31209
31212
  } = _a, rest = __objRest(_a, [
31210
31213
  "className",
31211
31214
  "onPageChange",
@@ -31215,7 +31218,8 @@ function SpsPagination(props2) {
31215
31218
  "data-testid",
31216
31219
  "totalResults",
31217
31220
  "unsafelyReplaceClassName",
31218
- "disabled"
31221
+ "disabled",
31222
+ "unknownPageCount"
31219
31223
  ]);
31220
31224
  const [state, patchState] = usePatchReducer({
31221
31225
  page: pageProp,
@@ -31293,13 +31297,16 @@ function SpsPagination(props2) {
31293
31297
  value: state.pageSize,
31294
31298
  className: "ml-1 mr-1",
31295
31299
  disabled
31296
- }), "Per Page"), /* @__PURE__ */ React.createElement("div", {
31300
+ }), "Per Page"), unknownPageCount ? /* @__PURE__ */ React.createElement("div", {
31301
+ className: "sps-pagination__details"
31302
+ }, `Viewing ${state.indices[0]} - ${state.indices[1]}`) : /* @__PURE__ */ React.createElement("div", {
31297
31303
  className: "sps-pagination__details"
31298
31304
  }, `Viewing ${state.indices[0]} - ${state.indices[1]} of ${totalResultsString()}`), /* @__PURE__ */ React.createElement(SpsPageSelector, {
31299
31305
  numPages: state.numPages,
31300
31306
  page: state.page,
31301
31307
  onPageChange: handlePageChange,
31302
- disabled
31308
+ disabled,
31309
+ unknownPageCount
31303
31310
  }));
31304
31311
  }
31305
31312
  Object.assign(SpsPagination, {
@@ -31354,6 +31361,35 @@ const SpsPaginationExamples = {
31354
31361
  }
31355
31362
  `
31356
31363
  },
31364
+ situational: {
31365
+ description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h4", null, "Unknown Page Count"), /* @__PURE__ */ React.createElement("p", null, "In cases where the exact page count of results is not able to be determined, a variation of the Pagination component with limited features can be utilized.")),
31366
+ react: code`
31367
+ function Component() {
31368
+ const [page, setPage] = React.useState(2);
31369
+ const [pageSize, setPageSize] = React.useState(25);
31370
+
31371
+ function handlePageChange(newPage, newPageSize) {
31372
+ console.log("change", newPage, newPageSize);
31373
+ setPage(newPage);
31374
+ setPageSize(newPageSize);
31375
+ }
31376
+
31377
+ return (
31378
+ <React.Fragment>
31379
+ <SpsPagination id="basic"
31380
+ totalResults={123}
31381
+ page={page}
31382
+ pageSize={pageSize}
31383
+ onPageChange={handlePageChange}
31384
+ unknownPageCount
31385
+ />
31386
+ <span className="mr-2">page: {page}</span>
31387
+ <span>pageSize: {pageSize}</span>
31388
+ </React.Fragment>
31389
+ );
31390
+ }
31391
+ `
31392
+ },
31357
31393
  disabled: {
31358
31394
  description: "Disabled state",
31359
31395
  react: code`
@@ -8,6 +8,7 @@ declare const propTypes: {
8
8
  onPageChange: PropTypes.Requireable<(number: any) => void>;
9
9
  page: PropTypes.Requireable<number>;
10
10
  disabled: PropTypes.Requireable<boolean>;
11
+ unknownPageCount: PropTypes.Requireable<boolean>;
11
12
  };
12
13
  export declare type SpsPageSelectorProps = PropTypes.InferTS<typeof propTypes, HTMLDivElement>;
13
14
  export declare function SpsPageSelector(props: SpsPageSelectorProps): JSX.Element;
@@ -10,6 +10,7 @@ declare const propTypes: {
10
10
  pageSizeOptions: PropTypes.Requireable<number[]>;
11
11
  totalResults: PropTypes.Requireable<number>;
12
12
  disabled: PropTypes.Requireable<boolean>;
13
+ unknownPageCount: PropTypes.Requireable<boolean>;
13
14
  };
14
15
  export declare type SpsPaginationProps = PropTypes.InferTS<typeof propTypes, HTMLDivElement>;
15
16
  export declare function SpsPagination(props: SpsPaginationProps): JSX.Element;
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.33.9",
4
+ "version": "5.33.12",
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.33.9",
32
- "@spscommerce/ds-illustrations": "5.33.9",
33
- "@spscommerce/ds-shared": "5.33.9",
34
- "@spscommerce/positioning": "5.33.9",
35
- "@spscommerce/utils": "5.33.9",
31
+ "@spscommerce/ds-colors": "5.33.12",
32
+ "@spscommerce/ds-illustrations": "5.33.12",
33
+ "@spscommerce/ds-shared": "5.33.12",
34
+ "@spscommerce/positioning": "5.33.12",
35
+ "@spscommerce/utils": "5.33.12",
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.33.9",
44
- "@spscommerce/ds-illustrations": "5.33.9",
45
- "@spscommerce/ds-shared": "5.33.9",
46
- "@spscommerce/positioning": "5.33.9",
47
- "@spscommerce/utils": "5.33.9",
43
+ "@spscommerce/ds-colors": "5.33.12",
44
+ "@spscommerce/ds-illustrations": "5.33.12",
45
+ "@spscommerce/ds-shared": "5.33.12",
46
+ "@spscommerce/positioning": "5.33.12",
47
+ "@spscommerce/utils": "5.33.12",
48
48
  "@testing-library/react": "^9.3.2",
49
49
  "@types/prop-types": "^15.7.1",
50
50
  "@types/react": "^16.9.0",