@spscommerce/ds-react 6.2.1 → 6.4.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
@@ -1215,8 +1215,9 @@ function useSpsForm(value, validatorMap) {
1215
1215
  return controlSet;
1216
1216
  }, []);
1217
1217
  const scheduledDispatch = useRef();
1218
- let currentValidatorMap = validatorMap;
1218
+ const validatorMapRef = useRef(validatorMap);
1219
1219
  const reducer2 = useCallback$1((currentState, action) => {
1220
+ var _a, _b, _c;
1220
1221
  let newValue;
1221
1222
  scheduledDispatch.current = null;
1222
1223
  if (action) {
@@ -1228,12 +1229,12 @@ function useSpsForm(value, validatorMap) {
1228
1229
  control.revealAllErrors = true;
1229
1230
  }
1230
1231
  } else if (action.newValidators) {
1231
- if (currentValidatorMap) {
1232
+ if (validatorMapRef.current) {
1232
1233
  const controlPath = action.path.join(".");
1233
- const newValidatorMap = __spreadValues({}, currentValidatorMap);
1234
- newValidatorMap[controlPath] = action.newValidators;
1235
- currentValidatorMap = newValidatorMap;
1236
- updateValidators(currentState.formValue, currentState.formMeta, currentValidatorMap, true);
1234
+ validatorMapRef.current = __spreadProps(__spreadValues({}, validatorMapRef.current), {
1235
+ [controlPath]: action.newValidators
1236
+ });
1237
+ updateValidators(currentState.formValue, currentState.formMeta, validatorMapRef.current, true);
1237
1238
  }
1238
1239
  } else {
1239
1240
  newValue = cloneFormValue(currentState.formValue, action.path);
@@ -1243,6 +1244,10 @@ function useSpsForm(value, validatorMap) {
1243
1244
  newValue = action.value;
1244
1245
  }
1245
1246
  }
1247
+ if ((_a = action.updateFormOptions) == null ? void 0 : _a.validators) {
1248
+ validatorMapRef.current = __spreadValues(__spreadValues({}, validatorMapRef.current), action.updateFormOptions.validators);
1249
+ updateValidators(currentState.formValue, currentState.formMeta, validatorMapRef.current, (_c = (_b = action.updateFormOptions) == null ? void 0 : _b.runValidators) != null ? _c : true);
1250
+ }
1246
1251
  if (newValue) {
1247
1252
  deepFreeze(newValue);
1248
1253
  const valueDiff = diff(currentState.formValue, newValue);
@@ -1279,8 +1284,8 @@ function useSpsForm(value, validatorMap) {
1279
1284
  }
1280
1285
  }
1281
1286
  }
1282
- if (currentValidatorMap) {
1283
- updateValidators(newValue, currentState.formMeta, currentValidatorMap);
1287
+ if (validatorMapRef.current) {
1288
+ updateValidators(newValue, currentState.formMeta, validatorMapRef.current);
1284
1289
  const alreadyValidated = new Set();
1285
1290
  validatorMapForEach(currentState.formMeta, validatorMap, (control, validators) => {
1286
1291
  if (typeof validators === "function") {
@@ -1340,12 +1345,12 @@ function useSpsForm(value, validatorMap) {
1340
1345
  updateForm();
1341
1346
  }
1342
1347
  }
1343
- function updateForm(newValue) {
1344
- if (newValue) {
1348
+ function updateForm(newValue, options) {
1349
+ if (newValue || options) {
1345
1350
  if (scheduledDispatch.current) {
1346
1351
  window.clearTimeout(scheduledDispatch.current);
1347
1352
  }
1348
- const sd = window.setTimeout(dispatch, 0, { value: newValue });
1353
+ const sd = window.setTimeout(dispatch, 0, { value: newValue, updateFormOptions: options });
1349
1354
  scheduledDispatch.current = sd;
1350
1355
  } else if (!scheduledDispatch.current) {
1351
1356
  const sd = window.setTimeout(dispatch, 0, {});
@@ -16725,7 +16730,7 @@ const SpsDateRangePickerExamples = {
16725
16730
  <div className="sfg-row">
16726
16731
  <div className="sfg-col-3">
16727
16732
  <SpsLabel for={formMeta.fields.dateRange}>Date</SpsLabel>
16728
- <SpsDateRangePickerV2
16733
+ <SpsDateRangePicker
16729
16734
  value={formValue.dateRange}
16730
16735
  formMeta={formMeta.fields.dateRange}
16731
16736
  />
@@ -16757,7 +16762,7 @@ const SpsDateRangePickerExamples = {
16757
16762
  <div className="sfg-row">
16758
16763
  <div className="sfg-col-3">
16759
16764
  <SpsLabel for={formMeta.fields.dateRange}>Date</SpsLabel>
16760
- <SpsDateRangePickerV2
16765
+ <SpsDateRangePicker
16761
16766
  value={formValue.dateRange}
16762
16767
  formMeta={formMeta.fields.dateRange}
16763
16768
  {...constraints.current}
@@ -16789,7 +16794,7 @@ const SpsDateRangePickerExamples = {
16789
16794
  <div className="sfg-row">
16790
16795
  <div className="sfg-col-3">
16791
16796
  <SpsLabel for={formMeta.fields.dateRange}>Date</SpsLabel>
16792
- <SpsDateRangePickerV2
16797
+ <SpsDateRangePicker
16793
16798
  value={formValue.dateRange}
16794
16799
  formMeta={formMeta.fields.dateRange}
16795
16800
  disabled
@@ -16837,7 +16842,7 @@ const SpsDateRangePickerExamples = {
16837
16842
  <div className="sfg-row">
16838
16843
  <div className="sfg-col-3">
16839
16844
  <SpsLabel for={formMeta.fields.dateRange}>Date</SpsLabel>
16840
- <SpsDateRangePickerV2
16845
+ <SpsDateRangePicker
16841
16846
  presets={presets.current}
16842
16847
  value={formValue.dateRange}
16843
16848
  formMeta={formMeta.fields.dateRange}
@@ -23826,7 +23831,7 @@ const SpsFormExamples = {
23826
23831
  },
23827
23832
  custom_errors: {
23828
23833
  label: "Custom errors",
23829
- description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "When using custom validators you can specify when to show the errors - on Change, on Blur or on Submit.", /* @__PURE__ */ React.createElement("br", null), "On Blur is the default behavior. If you want to change that behavior you can use ", /* @__PURE__ */ React.createElement("b", null, "useCustomValidator hook"), ". It takes validation function as first argument, validator configuration (object containing errorKey as key and ValidationMode as value) as second argument and dependencies as third argument. useCustomValidator returns a React callback of the validation function with the given dependencies."), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("b", null, "!Note:"), " useCustomValidator hook will make changes to the global scope and once you set a custom error key you can't change it.")),
23834
+ description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "When using custom validators you can specify when to show the errors - on Change, on Blur or on Submit.", /* @__PURE__ */ React.createElement("br", null), "On Blur is the default behavior. If you want to change that behavior you can use", " ", /* @__PURE__ */ React.createElement("b", null, "useCustomValidator hook"), ". It takes validation function as first argument, validator configuration (object containing errorKey as key and ValidationMode as value) as second argument and dependencies as third argument. useCustomValidator returns a React callback of the validation function with the given dependencies."), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("b", null, "!Note:"), " useCustomValidator hook will make changes to the global scope and once you set a custom error key you can't change it.")),
23830
23835
  examples: {
23831
23836
  basic: {
23832
23837
  react: code`
@@ -23885,6 +23890,77 @@ const SpsFormExamples = {
23885
23890
  `
23886
23891
  }
23887
23892
  }
23893
+ },
23894
+ updating_validators: {
23895
+ label: "Updating validators",
23896
+ description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "The updateForm function supports a seconds argument (options) that allows modifying multiple field validators at once.")),
23897
+ examples: {
23898
+ basic: {
23899
+ react: code`
23900
+ function DemoComponent() {
23901
+ const initValue = {
23902
+ fieldA: "",
23903
+ fieldB: "",
23904
+ };
23905
+
23906
+ const { formValue, formMeta, updateForm } = useSpsForm(initValue, {
23907
+ "fieldA": [SpsValidators.required],
23908
+ });
23909
+
23910
+ function handleSubmit() {
23911
+ console.log("submit", formValue);
23912
+ }
23913
+
23914
+ function reset() {
23915
+ updateForm(initValue, { validators: { fieldA: [SpsValidators.required], fieldB: [] }});
23916
+ formMeta.markAsPristine();
23917
+ }
23918
+
23919
+ // This will make field A non required and field B required in a single operation
23920
+ function updateValidators() {
23921
+ updateForm(undefined, { validators: { fieldA: [], fieldB: [SpsValidators.required] }});
23922
+ }
23923
+
23924
+ return <>
23925
+ <SpsForm formMeta={formMeta} onSubmit={handleSubmit}>
23926
+ <div className="sfg-row">
23927
+ <div className="sfg-col-8">
23928
+ <SpsLabel
23929
+ for={formMeta.fields.fieldA}
23930
+ >
23931
+ Field A
23932
+ </SpsLabel>
23933
+ <SpsTextInput
23934
+ value={formValue.fieldA}
23935
+ formMeta={formMeta.fields.fieldA}
23936
+ />
23937
+ </div>
23938
+ <div className="sfg-col-8">
23939
+ <SpsLabel
23940
+ for={formMeta.fields.fieldB}
23941
+ >
23942
+ Field B
23943
+ </SpsLabel>
23944
+ <SpsTextInput
23945
+ value={formValue.fieldB}
23946
+ formMeta={formMeta.fields.fieldB}
23947
+ />
23948
+ </div>
23949
+ </div>
23950
+
23951
+ <div className="sfg-row">
23952
+ <div className="sfg-col-12">
23953
+ <SpsButton className="mr-1" onClick={reset}>Reset</SpsButton>
23954
+ <SpsButton className="mr-1" onClick={updateValidators}>Update Validators</SpsButton>
23955
+ <SpsButton type={ButtonType.SUBMIT} kind={ButtonKind.CONFIRM}>Submit</SpsButton>
23956
+ </div>
23957
+ </div>
23958
+ </SpsForm>
23959
+ </>;
23960
+ }
23961
+ `
23962
+ }
23963
+ }
23888
23964
  }
23889
23965
  };
23890
23966
  const SpsAddRemoveFormRowExamples = {
@@ -30206,212 +30282,375 @@ Object.assign(SpsMultiSelect, {
30206
30282
  displayName: "SpsMultiSelect"
30207
30283
  });
30208
30284
  const SpsMultiSelectExamples = {
30209
- basic: {
30210
- label: "Basic",
30211
- description: "<p>Multi select component</p>",
30285
+ general: {
30286
+ label: "General Usage",
30287
+ description: ({ NavigateTo }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h5", null, "Use a Mulit-Select"), /* @__PURE__ */ React.createElement("ul", null, /* @__PURE__ */ React.createElement("li", null, "When a list of predetermined values can be provided and the input allows multiple entries.")), /* @__PURE__ */ React.createElement("h5", null, "Do Not Use a Multi-Select:"), /* @__PURE__ */ React.createElement("ul", null, /* @__PURE__ */ React.createElement("li", {
30288
+ className: "mb-2"
30289
+ }, "When there are only two possible options. Consider", " ", /* @__PURE__ */ React.createElement(NavigateTo, {
30290
+ to: "checkbox"
30291
+ }, "Checkboxes"), " or", " ", /* @__PURE__ */ React.createElement(NavigateTo, {
30292
+ to: "radio-buttons"
30293
+ }, "Radio Buttons"), " instead."), /* @__PURE__ */ React.createElement("li", null, "When it is ideal to display all available options without requiring a click. Consider", " ", /* @__PURE__ */ React.createElement(NavigateTo, {
30294
+ to: "checkbox"
30295
+ }, "Checkboxes"), " or", " ", /* @__PURE__ */ React.createElement(NavigateTo, {
30296
+ to: "radio-buttons"
30297
+ }, "Radio Buttons"), " instead.")), /* @__PURE__ */ React.createElement("h5", null, "Using Multi-Selects in a Form"), /* @__PURE__ */ React.createElement("p", null, "Reference the ", /* @__PURE__ */ React.createElement(NavigateTo, {
30298
+ to: "form"
30299
+ }, "Forms"), " page for guidelines for placing", " ", /* @__PURE__ */ React.createElement(NavigateTo, {
30300
+ to: "text-inputs"
30301
+ }, "Inputs"), " in Form Layouts."))
30302
+ },
30303
+ basicMuliSelect: {
30304
+ label: "Basic Multi-Selects",
30305
+ description: "Basic Multi-Selects include a label and dropdown menu including a list of options. The user is allowed to make a single selection.",
30212
30306
  examples: {
30213
- a_basic: {
30307
+ basic: {
30214
30308
  react: code`
30215
- function Component() {
30216
- const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30217
- const { formValue, formMeta, updateForm } = useSpsForm({
30218
- things: [ opts[0] ]
30219
- })
30220
-
30221
- return <>
30222
- <SpsLabel for={formMeta.fields.things}>Things</SpsLabel>
30223
- <SpsMultiSelect
30224
- options={opts}
30225
- formMeta={formMeta.fields.things}
30226
- value={formValue.things}
30227
- />
30228
- <br />
30229
- {JSON.stringify(formValue)}
30230
- </>
30231
- }
30232
- `
30309
+ function Component() {
30310
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30311
+ const { formValue, formMeta, updateForm } = useSpsForm({
30312
+ things: [opts[0]]
30313
+ })
30314
+
30315
+ return <>
30316
+ <SpsLabel for={formMeta.fields.things}>Company Names</SpsLabel>
30317
+ <SpsMultiSelect
30318
+ options={opts}
30319
+ formMeta={formMeta.fields.things}
30320
+ value={formValue.things}
30321
+ />
30322
+ <br />
30323
+ {JSON.stringify(formValue)}
30324
+ </>
30325
+ }`
30233
30326
  },
30234
- b_disabled: {
30327
+ customizablePlaceholderText: {
30328
+ description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h4", null, "Customizable Placeholder Text"), /* @__PURE__ */ React.createElement("p", null, "Placeholder text can be customized to specifically reference the content in the dropdown menu.")),
30235
30329
  react: code`
30236
- function Component() {
30237
- const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30238
- const { formValue, formMeta, updateForm } = useSpsForm({
30239
- things: [ opts[0] ]
30240
- })
30241
-
30242
- return <>
30243
- <SpsLabel for={formMeta.fields.things}>Things</SpsLabel>
30244
- <SpsMultiSelect disabled
30245
- options={opts}
30246
- formMeta={formMeta.fields.things}
30247
- value={formValue.things}
30248
- />
30249
- <br />
30250
- {JSON.stringify(formValue)}
30251
- </>
30252
- }
30253
- `
30330
+ function Component() {
30331
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30332
+ const { formValue, formMeta, updateForm } = useSpsForm({
30333
+ things: []
30334
+ })
30335
+
30336
+ return <>
30337
+ <SpsLabel for={formMeta.fields.things}>Company Names</SpsLabel>
30338
+ <SpsMultiSelect
30339
+ placeholder= "Select companies..."
30340
+ options={opts}
30341
+ formMeta={formMeta.fields.things}
30342
+ value={formValue.things}
30343
+ />
30344
+ <br />
30345
+ {JSON.stringify(formValue)}
30346
+ </>
30347
+ }`
30254
30348
  },
30255
- c_externalTags: {
30349
+ zeroStateNoAvailableOptions: {
30350
+ description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h4", null, "Zero State / No Available Options"), /* @__PURE__ */ React.createElement("p", null, "If no options are available in the dropdown menu, a zero state message appears. This option is most commonly used with the Select with Filter option.")),
30256
30351
  react: code`
30257
- function Component() {
30258
- const [foo, setFoo] = React.useState(["orp"])
30259
- const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30260
- function handleChange(event) {
30261
- setFoo(event.target.value)
30262
- }
30263
- function removeByIndex(i) {
30264
- foo.splice(i, 1)
30265
- setFoo([...foo])
30266
- }
30267
- return (
30268
- <>
30269
- <SpsMultiSelect
30270
- hideSelected
30271
- options={opts}
30272
- value={foo}
30273
- onChange={handleChange}
30274
- />
30275
- <br />
30276
- {foo.map((opt, i) => (
30277
- <SpsClickableTag
30278
- className="mt-1 ml-1"
30279
- key={i}
30280
- onRemove={() => removeByIndex(i)}
30281
- >
30282
- {opt}
30283
- </SpsClickableTag>
30284
- ))}
30285
- </>
30286
- )
30287
- }
30288
- `
30289
- },
30290
- icon: {
30352
+ function Component() {
30353
+ const [opts] = React.useState([])
30354
+ const { formValue, formMeta, updateForm } = useSpsForm({
30355
+ things: []
30356
+ })
30357
+
30358
+ return <>
30359
+ <SpsLabel for={formMeta.fields.things}>Company Names</SpsLabel>
30360
+ <SpsMultiSelect
30361
+ zeroState="No options available"
30362
+ options={opts}
30363
+ formMeta={formMeta.fields.things}
30364
+ value={formValue.things}
30365
+ />
30366
+ <br />
30367
+ {JSON.stringify(formValue)}
30368
+ </>
30369
+ }`
30370
+ }
30371
+ }
30372
+ },
30373
+ promise: {
30374
+ label: "Asynchronous Data Source",
30375
+ description: "If the list of options must be sourced asynchronously, the options prop can take a function that returns a Promise.",
30376
+ examples: {
30377
+ returnAPromise: {
30378
+ react: code`function Component() {
30379
+ const { formValue, formMeta, updateForm } = useSpsForm({
30380
+ things: []
30381
+ })
30382
+ function colorSearch(search) {
30383
+ return new Promise((resolve, reject) => {
30384
+ const result = ["foo", "bar", "baz", "orp"]
30385
+ .filter(s => new RegExp(search, "i").test(s));
30386
+ resolve(result);
30387
+ });
30388
+ }
30389
+
30390
+ return <>
30391
+ <SpsLabel for={formMeta.fields.things}>Things</SpsLabel>
30392
+ <SpsMultiSelect
30393
+ options={colorSearch}
30394
+ formMeta={formMeta.fields.things}
30395
+ value={formValue.things}
30396
+ />
30397
+ <br />
30398
+ {JSON.stringify(formValue)}
30399
+ </>
30400
+ }`
30401
+ }
30402
+ }
30403
+ },
30404
+ objectOptions: {
30405
+ label: "Object Options",
30406
+ description: "The values in the select menu can be modified to provide more detail to the user or the system, when necssary.",
30407
+ examples: {
30408
+ basic: {
30291
30409
  react: code`
30292
- function Component() {
30293
- const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30294
- const { formValue, formMeta, updateForm } = useSpsForm({
30295
- things: [ opts[0] ]
30296
- })
30297
-
30298
- return <>
30299
- <SpsLabel for={formMeta.fields.things}>Things</SpsLabel>
30300
- <SpsMultiSelect
30301
- icon={SpsIcon.FILTER}
30302
- options={opts}
30303
- formMeta={formMeta.fields.things}
30304
- value={formValue.things}
30305
- />
30306
- <br />
30307
- {JSON.stringify(formValue)}
30308
- </>
30309
- }
30310
- `
30410
+ function Component() {
30411
+ const [opts] = React.useState([
30412
+ { id: 1, name: "Target" },
30413
+ { id: 2, name: "Cabela's" },
30414
+ { id: 3, name: "Best Buy" },
30415
+ ])
30416
+ const [foo, setFoo] = React.useState([])
30417
+ function handleChange(event) {
30418
+ setFoo(event.target.value)
30419
+ }
30420
+ return (
30421
+ <>
30422
+ <SpsMultiSelect
30423
+ options={opts}
30424
+ textKey="name"
30425
+ value={foo}
30426
+ onChange={handleChange}
30427
+ />
30428
+ <br />
30429
+ {JSON.stringify(foo)}
30430
+ </>
30431
+ )
30432
+ }`
30311
30433
  },
30312
- objects: {
30434
+ extendedDetails: {
30435
+ description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h4", null, "Extended Details"), /* @__PURE__ */ React.createElement("p", null, "Extended details can be displayed in the dropdown menu. Only the primary detail is displayed as the selection.")),
30313
30436
  react: code`
30314
- function Component() {
30315
- const [opts] = React.useState([
30316
- { id: 1, name: "Target" },
30317
- { id: 2, name: "Cabela's" },
30318
- { id: 3, name: "Best Buy" },
30319
- ])
30320
- const [foo, setFoo] = React.useState([])
30321
- function handleChange(event) {
30322
- setFoo(event.target.value)
30323
- }
30324
- return (
30325
- <>
30326
- <SpsMultiSelect
30327
- options={opts}
30328
- textKey="name"
30329
- value={foo}
30330
- onChange={handleChange}
30331
- />
30332
- <br />
30333
- {JSON.stringify(foo)}
30334
- </>
30335
- )
30336
- }
30337
- `
30437
+ function Component() {
30438
+ const [opts] = React.useState([
30439
+ { id: 1, name: "Target", description: "blah", disabled: true },
30440
+ { id: 2, name: "Cabela's", description: "test", disabled: true },
30441
+ { id: 3, name: "Best Buy", description: "2" },
30442
+ ])
30443
+ const [foo, setFoo] = React.useState([])
30444
+ function handleChange(event) {
30445
+ setFoo(event.target.value)
30446
+ }
30447
+ return (
30448
+ <>
30449
+ <SpsMultiSelect
30450
+ options={opts}
30451
+ textKey="name"
30452
+ captionKey="description"
30453
+ value={foo}
30454
+ onChange={handleChange}
30455
+ />
30456
+ <br />
30457
+ {JSON.stringify(foo)}
30458
+ </>
30459
+ )
30460
+ }`
30338
30461
  },
30339
- disabledOptions: {
30462
+ disabledOption: {
30463
+ description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h4", null, "Disabled Options"), /* @__PURE__ */ React.createElement("p", null, "When options in the dropdown list are unavailable (as a result of having been selected or for any other reason) they should adopt a disabled style.")),
30340
30464
  react: code`
30341
- function Component() {
30342
- const [opts] = React.useState([
30343
- { id: 1, name: "Target", disabled: true },
30344
- { id: 2, name: "Cabela's", disabled: true },
30345
- { id: 3, name: "Best Buy" },
30346
- ])
30347
- const [foo, setFoo] = React.useState([])
30348
- function handleChange(event) {
30349
- setFoo(event.target.value)
30350
- }
30351
- return (
30352
- <>
30353
- <SpsMultiSelect
30354
- options={opts}
30355
- textKey="name"
30356
- value={foo}
30357
- onChange={handleChange}
30358
- />
30359
- <br />
30360
- {JSON.stringify(foo)}
30361
- </>
30362
- )
30363
- }
30364
- `
30465
+ function Component() {
30466
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30467
+ const { formValue, formMeta, updateForm } = useSpsForm({
30468
+ things: [ opts[0] ]
30469
+ })
30470
+
30471
+ return <>
30472
+ <SpsLabel for={formMeta.fields.things}>Company Names</SpsLabel>
30473
+ <SpsMultiSelect
30474
+ options={opts}
30475
+ formMeta={formMeta.fields.things}
30476
+ value={formValue.things}
30477
+ disableSelected
30478
+ />
30479
+ <br />
30480
+ {JSON.stringify(formValue)}
30481
+ </>
30482
+ }
30483
+ `
30365
30484
  }
30366
30485
  }
30367
30486
  },
30368
- searchText: {
30369
- label: "Search text",
30370
- description: "Get search text",
30487
+ getSearchText: {
30488
+ label: "Get Search Text",
30489
+ description: "The text that the user has entered into the input can be accessed via passing a handler to onSearchChange. This is typically used in combination with the action option to enable a user to add a value they don't find in the list.",
30371
30490
  examples: {
30372
- a_actionWithSearchText: {
30373
- react: code`
30374
- function Component() {
30375
- const [opts] = React.useState(["foo", "bar", "baz", "orp"]);
30376
- const { formValue, formMeta, updateForm } = useSpsForm({
30377
- tags: [opts[0]],
30491
+ basic: {
30492
+ react: code`function Component() {
30493
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"]);
30494
+ const { formValue, formMeta, updateForm } = useSpsForm({
30495
+ tags: [opts[0]],
30496
+ });
30497
+
30498
+ const [searchText, setSearchText] = React.useState("");
30499
+
30500
+ React.useEffect(() => {
30501
+ updateAction({
30502
+ label: searchText ? \`Create a New Tag "\${searchText}"\` : "Create a New Tag",
30378
30503
  });
30379
-
30380
- const [searchText, setSearchText] = React.useState("");
30381
-
30382
- React.useEffect(() => {
30383
- updateAction({
30384
- label: searchText ? \`Create a New Tag "\${searchText}"\` : "Create a New Tag",
30385
- });
30386
- }, [searchText, opts]);
30387
-
30388
- const handleSearchChange = (searchTextValue) => {
30389
- setSearchText(searchTextValue)
30390
- }
30391
-
30392
- const [action, updateAction] = useSpsAction(
30393
- {
30394
- label: "Create a New Tag",
30395
- icon: SpsIcon.PLUS_SIGN,
30396
- },
30397
- () => console.log("New Tag has been created")
30398
- );
30399
-
30400
- return (
30401
- <>
30402
- <SpsLabel for={formMeta.fields.tags}>Tags</SpsLabel>
30504
+ }, [searchText, opts]);
30505
+
30506
+ const handleSearchChange = (searchTextValue) => {
30507
+ setSearchText(searchTextValue)
30508
+ }
30509
+
30510
+ const [action, updateAction] = useSpsAction(
30511
+ {
30512
+ label: "Create a New Tag",
30513
+ icon: SpsIcon.PLUS_SIGN,
30514
+ },
30515
+ () => console.log("New Tag has been created")
30516
+ );
30517
+
30518
+ return (
30519
+ <>
30520
+ <SpsLabel for={formMeta.fields.tags}>Tags</SpsLabel>
30521
+ <SpsMultiSelect
30522
+ disableSelected
30523
+ icon={SpsIcon.FILTER}
30524
+ options={opts}
30525
+ action={action}
30526
+ formMeta={formMeta.fields.tags}
30527
+ value={formValue.tags}
30528
+ onSearchChange={handleSearchChange}
30529
+ />
30530
+ </>
30531
+ );
30532
+ }`
30533
+ }
30534
+ }
30535
+ },
30536
+ createANewValue: {
30537
+ label: "Create a New Value",
30538
+ description: "This feature allows users to add, and select, a new value that doesn't exist in the current dropdown menu options.",
30539
+ examples: {
30540
+ basic: {
30541
+ react: code`function Component() {
30542
+ const [opts, setOpts] = React.useState(["foo", "bar", "baz", "orp"]);
30543
+ const { formValue, formMeta, updateForm } = useSpsForm({
30544
+ tags: [opts[0]],
30545
+ });
30546
+
30547
+ const [searchText, setSearchText] = React.useState("");
30548
+
30549
+ React.useEffect(() => {
30550
+ updateAction({
30551
+ label: searchText
30552
+ ? \`Create a New Tag "\${searchText}"\`
30553
+ : "Create a New Tag",
30554
+ disabled: searchText === ""
30555
+ });
30556
+ }, [searchText, opts]);
30557
+
30558
+ const handleSearchChange = (searchTextValue) => {
30559
+ setSearchText(searchTextValue);
30560
+ };
30561
+
30562
+ const [action, updateAction] = useSpsAction(
30563
+ {
30564
+ label: "Create a New Tag",
30565
+ icon: SpsIcon.PLUS_SIGN,
30566
+ },
30567
+ () => {
30568
+ setOpts([...opts, searchText]);
30569
+ updateForm({ ...formValue, tags: [...formValue.tags, searchText] });
30570
+ handleSearchChange("");
30571
+ }
30572
+ );
30573
+
30574
+ return (
30575
+ <>
30576
+ <SpsLabel for={formMeta.fields.tags}>Tags</SpsLabel>
30577
+ <SpsMultiSelect
30578
+ disableSelected
30579
+ icon={SpsIcon.FILTER}
30580
+ options={opts}
30581
+ action={action}
30582
+ formMeta={formMeta.fields.tags}
30583
+ value={formValue.tags}
30584
+ onSearchChange={handleSearchChange}
30585
+ clearSearchOnBlur
30586
+ />
30587
+ </>
30588
+ );
30589
+ }`
30590
+ }
30591
+ }
30592
+ },
30593
+ selectedValuesAlternate: {
30594
+ label: "Selected Values Alternate",
30595
+ description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "Use this option when it is ideal for the selected values to appear as tags outside of the input field. Opt for this option when adding or removing values from a large list of selections that would create a cumbersome field."), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("i", null, "Note: The placement of the selected values can appear belcow the input field or elsewhere in the UI if necessary."))),
30596
+ examples: {
30597
+ basic: {
30598
+ react: code`function Component() {
30599
+ const [foo, setFoo] = React.useState(["orp"])
30600
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30601
+ function handleChange(event) {
30602
+ setFoo(event.target.value)
30603
+ }
30604
+ function removeByIndex(i) {
30605
+ foo.splice(i, 1)
30606
+ setFoo([...foo])
30607
+ }
30608
+ return (
30609
+ <>
30403
30610
  <SpsMultiSelect
30404
- disableSelected
30405
- icon={SpsIcon.FILTER}
30406
- options={opts}
30407
- action={action}
30408
- formMeta={formMeta.fields.tags}
30409
- value={formValue.tags}
30410
- onSearchChange={handleSearchChange}
30611
+ hideSelected
30612
+ options={opts}
30613
+ value={foo}
30614
+ onChange={handleChange}
30411
30615
  />
30412
- </>
30413
- );
30414
- }`
30616
+ <br />
30617
+ {foo.map((opt, i) => (
30618
+ <SpsClickableTag
30619
+ className="mt-1 ml-1"
30620
+ key={i}
30621
+ onRemove={() => removeByIndex(i)}
30622
+ >
30623
+ {opt}
30624
+ </SpsClickableTag>
30625
+ ))}
30626
+ </>
30627
+ )
30628
+ }`
30629
+ }
30630
+ }
30631
+ },
30632
+ disabledState: {
30633
+ label: "Disabled State",
30634
+ description: "In the disabled state, select inputs display the current selection or placeholder text, but cannot be interacted with.",
30635
+ examples: {
30636
+ basic: {
30637
+ react: code`function Component() {
30638
+ const [opts] = React.useState(["foo", "bar", "baz", "orp"])
30639
+ const { formValue, formMeta, updateForm } = useSpsForm({
30640
+ things: [ opts[0] ]
30641
+ })
30642
+
30643
+ return <>
30644
+ <SpsLabel for={formMeta.fields.things}>Company Name</SpsLabel>
30645
+ <SpsMultiSelect disabled
30646
+ options={opts}
30647
+ formMeta={formMeta.fields.things}
30648
+ value={formValue.things}
30649
+ />
30650
+ <br />
30651
+ {JSON.stringify(formValue)}
30652
+ </>
30653
+ }`
30415
30654
  }
30416
30655
  }
30417
30656
  }
@@ -37314,13 +37553,7 @@ const MANIFEST = {
37314
37553
  },
37315
37554
  Cards: {
37316
37555
  description: () => /* @__PURE__ */ React.createElement("p", null, "Cards are used to group similar or related content together in a single container. They can be combined with additional elements such as Headers, Footers, or Tabs."),
37317
- components: [
37318
- SpsCardV2,
37319
- SpsCardV2Footer,
37320
- SpsCardV2Header,
37321
- SpsCardV2Title,
37322
- SpsTabsV2
37323
- ],
37556
+ components: [SpsCardV2, SpsCardV2Footer, SpsCardV2Header, SpsCardV2Title, SpsTabsV2],
37324
37557
  examples: SpsCardExamples
37325
37558
  },
37326
37559
  Checkbox: {
@@ -37351,12 +37584,7 @@ const MANIFEST = {
37351
37584
  examples: SpsContentRowExamples
37352
37585
  },
37353
37586
  "Content Tiles": {
37354
- components: [
37355
- SpsTile,
37356
- SpsTileList,
37357
- SpsSortingHeader,
37358
- SpsSortingHeaderCell
37359
- ],
37587
+ components: [SpsTile, SpsTileList, SpsSortingHeader, SpsSortingHeaderCell],
37360
37588
  examples: SpsTileListExamples
37361
37589
  },
37362
37590
  "Filter Tiles": {
@@ -37376,11 +37604,7 @@ const MANIFEST = {
37376
37604
  examples: SpsDatetimeExamples
37377
37605
  },
37378
37606
  "Description Lists": {
37379
- components: [
37380
- SpsDescriptionList,
37381
- SpsDescriptionListDefinition,
37382
- SpsDescriptionListTerm
37383
- ],
37607
+ components: [SpsDescriptionList, SpsDescriptionListDefinition, SpsDescriptionListTerm],
37384
37608
  examples: SpsDescriptionListExamples
37385
37609
  },
37386
37610
  Dropdown: {
@@ -37388,7 +37612,7 @@ const MANIFEST = {
37388
37612
  examples: SpsDropdownExamples
37389
37613
  },
37390
37614
  "Feedback Blocks": {
37391
- description: ({ NavigateTo }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "Feedback Blocks show static informational messages on a page. They should not dynamically appear or disappear. For feedback that responds to a user action, Use a ", /* @__PURE__ */ React.createElement(NavigateTo, {
37615
+ description: ({ NavigateTo }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "Feedback Blocks show static informational messages on a page. They should not dynamically appear or disappear. For feedback that responds to a user action, Use a", " ", /* @__PURE__ */ React.createElement(NavigateTo, {
37392
37616
  to: "growler"
37393
37617
  }, "Growler"), " instead."), /* @__PURE__ */ React.createElement("h5", null, "Variants"), /* @__PURE__ */ React.createElement("p", null, "Variants are generally tied to a specific color and an accompanying icon."), /* @__PURE__ */ React.createElement(SpsMicroBlock, {
37394
37618
  kind: FeedbackBlockKind.ERROR,
@@ -37414,12 +37638,7 @@ const MANIFEST = {
37414
37638
  examples: SpsFieldsetExamples
37415
37639
  },
37416
37640
  "Filter Panel": {
37417
- components: [
37418
- SpsFilterPanel,
37419
- SpsFilterPanelSection,
37420
- SpsFilterPanelCap,
37421
- SpsFilterPanelFilterBox
37422
- ],
37641
+ components: [SpsFilterPanel, SpsFilterPanelSection, SpsFilterPanelCap, SpsFilterPanelFilterBox],
37423
37642
  examples: SpsFilterPanelExamples
37424
37643
  },
37425
37644
  "Focused Task": {
@@ -37476,6 +37695,7 @@ const MANIFEST = {
37476
37695
  examples: SpsModalExamples
37477
37696
  },
37478
37697
  "Multi Select": {
37698
+ description: () => /* @__PURE__ */ React.createElement("p", null, "Multi-Selects consist of a Label and a dropdown menu from which a user selects one or more values from a list of pre-defined options."),
37479
37699
  components: [SpsMultiSelect],
37480
37700
  examples: SpsMultiSelectExamples
37481
37701
  },
@@ -37535,11 +37755,7 @@ const MANIFEST = {
37535
37755
  examples: SpsSlackLinkExamples
37536
37756
  },
37537
37757
  "Summary List Row": {
37538
- components: [
37539
- SpsSummaryListRow,
37540
- SpsSummaryListColumn,
37541
- SpsSummaryListExpansion
37542
- ],
37758
+ components: [SpsSummaryListRow, SpsSummaryListColumn, SpsSummaryListExpansion],
37543
37759
  examples: SpsSummaryListExamples
37544
37760
  },
37545
37761
  Tables: {
@@ -37552,14 +37768,7 @@ const MANIFEST = {
37552
37768
  }, "Content Tiles"), ") are one of three options for displaying a list of records on a page."), /* @__PURE__ */ React.createElement("br", null), /* @__PURE__ */ React.createElement("div", {
37553
37769
  className: "sps-body-14"
37554
37770
  }, "Tables are the ideal solution for displaying tabular data, especially when the listed records contain a considerable amount of data points. While tables are primarily used to display an extensive list of records, often in a paginated format, they can also be used to display smaller sets of tabular data in any context.")),
37555
- components: [
37556
- SpsTable,
37557
- SpsTableBody,
37558
- SpsTableCell,
37559
- SpsTableHead,
37560
- SpsTableHeader,
37561
- SpsTableRow
37562
- ],
37771
+ components: [SpsTable, SpsTableBody, SpsTableCell, SpsTableHead, SpsTableHeader, SpsTableRow],
37563
37772
  examples: SpsTableExamples
37564
37773
  },
37565
37774
  Tags: {
@@ -37593,12 +37802,7 @@ const MANIFEST = {
37593
37802
  examples: SpsWizardExamples
37594
37803
  },
37595
37804
  Workflow: {
37596
- components: [
37597
- SpsWorkflow,
37598
- SpsWorkflowDocument,
37599
- SpsWorkflowDocumentStatus,
37600
- SpsWorkflowStep
37601
- ],
37805
+ components: [SpsWorkflow, SpsWorkflowDocument, SpsWorkflowDocumentStatus, SpsWorkflowStep],
37602
37806
  examples: SpsWorkflowExamples
37603
37807
  },
37604
37808
  "Zero States": {