@thecb/components 10.11.0 → 10.11.2-beta.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/dist/index.cjs.js CHANGED
@@ -27092,79 +27092,83 @@ var createFormat = function createFormat(formats, formatChar) {
27092
27092
  var FormattedInput = function FormattedInput(_ref) {
27093
27093
  var value = _ref.value,
27094
27094
  formatter = _ref.formatter,
27095
- _onChange = _ref.onChange,
27095
+ onChange = _ref.onChange,
27096
27096
  props = _objectWithoutProperties$1(_ref, ["value", "formatter", "onChange"]);
27097
27097
 
27098
- var inputEl = React.useRef(null);
27098
+ var _useState = React.useState(format$1(formatter)(value)),
27099
+ _useState2 = _slicedToArray$1(_useState, 2),
27100
+ formattedValue = _useState2[0],
27101
+ setFormattedValue = _useState2[1];
27099
27102
 
27100
- var _useState = React.useState({
27103
+ var inputEl = React.useRef(null);
27104
+ var stateRefs = React.useRef({
27101
27105
  selectionStart: 0,
27102
27106
  selectionEnd: 0,
27103
- rawValue: value,
27104
- "delete": false,
27105
- formattedValue: format$1(formatter)(value)
27106
- }),
27107
- _useState2 = _slicedToArray$1(_useState, 2),
27108
- state = _useState2[0],
27109
- setState = _useState2[1];
27110
-
27107
+ isDelete: false,
27108
+ rawValue: ''
27109
+ });
27111
27110
  React.useLayoutEffect(function () {
27112
27111
  // A lot of the work here is cursor manipulation
27113
27112
  if (inputEl.current && inputEl.current === document.activeElement) {
27114
- inputEl.current.setSelectionRange(state.selectionStart, state.selectionEnd);
27113
+ inputEl.current.setSelectionRange(stateRefs.current.selectionStart, stateRefs.current.selectionEnd);
27115
27114
  }
27116
- });
27115
+ }, [stateRefs]);
27116
+
27117
+ var handleChange = function handleChange(event) {
27118
+ var deleteKeyPressed = stateRefs.current.isDelete;
27119
+ var maxFormatExceeded = stateRefs.current.rawValue.length >= formatter.formats.length - 1;
27120
+
27121
+ if (maxFormatExceeded && !deleteKeyPressed) {
27122
+ return;
27123
+ }
27124
+ /* At the beginning of onChange, event.target.value is a concat of the previous formatted value
27125
+ * and an unformatted injection at the start, end, or in the middle (maybe a deletion). To prepare
27126
+ * the unformatted value for the user's onChange, the formatted string and unformatted injection need
27127
+ * to be separated, then unformat the formatted string, then insert (or delete) the injection from the
27128
+ * old unformatted value.
27129
+ */
27130
+
27131
+
27132
+ var injectionLength = event.target.value.length - formattedValue.length;
27133
+ var end = stateRefs.current.selectionStart === stateRefs.current.selectionEnd ? stateRefs.current.selectionStart + injectionLength : stateRefs.current.selectionEnd - 1;
27134
+ var injection = event.target.value.substring(stateRefs.current.selectionStart, end); // Injection is the new unformatted piece of the input
27135
+ // Need to find where to put it
27136
+
27137
+ var rawInjectionPointStart = formattedToUnformattedIndex(stateRefs.current.selectionStart, stateRefs.current.rawValue, formatter);
27138
+ var rawInjectionPointEnd = formattedToUnformattedIndex(stateRefs.current.selectionEnd, stateRefs.current.rawValue, formatter); // Unformat the previous formatted value for injection
27139
+ // Using the relevant format string, strips away chars not marked with the formatChar
27140
+
27141
+ var unformattedOldValue = unformat(formatter)(formattedValue, stateRefs.current.rawValue.length); // Edit the previous unformatted value (either add, update or delete)
27142
+
27143
+ var injectIntoOldValue = inject(unformattedOldValue);
27144
+ var unformattedNewValue = deleteKeyPressed ? rawInjectionPointStart === rawInjectionPointEnd ? injectIntoOldValue(rawInjectionPointStart - 1, rawInjectionPointStart, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, injection);
27145
+ var lengthDifference = unformattedNewValue.length - stateRefs.current.rawValue.length;
27146
+ var rawIndex = formattedToUnformattedIndex(stateRefs.current.selectionStart, stateRefs.current.rawValue, formatter) + lengthDifference; // Find the new cursor position for the potential formatted value
27147
+ // Applied by useLayoutEffect
27148
+
27149
+ var newFormattedCursorPosition = stateRefs.current.selectionStart === stateRefs.current.selectionEnd ? unformattedToFormattedIndex(rawIndex, unformattedNewValue, formatter, deleteKeyPressed) : deleteKeyPressed ? stateRefs.current.selectionStart : stateRefs.current.selectionEnd;
27150
+ var formattedNewValue = format$1(formatter)(unformattedNewValue);
27151
+ setFormattedValue(formattedNewValue); // Apply the external onChange function to the raw underlying string
27152
+ // This is where the user generally updates the input value
27153
+
27154
+ if (onChange) {
27155
+ onChange(unformattedNewValue);
27156
+ }
27157
+ };
27158
+
27117
27159
  return React__default.createElement("input", _extends$2({}, props, {
27118
27160
  ref: inputEl,
27119
27161
  value: format$1(formatter)(value),
27120
27162
  onKeyDown: function onKeyDown(event) {
27121
- // Keep track of the state of the input before onChange, including if user is hitting delete
27122
- setState({
27123
- rawValue: value,
27163
+ // Keep track of the state of the input before onChange
27164
+ stateRefs.current = {
27165
+ isDelete: event.key === "Backspace" || event.key === "Delete",
27124
27166
  selectionStart: event.target.selectionStart,
27125
27167
  selectionEnd: event.target.selectionEnd,
27126
- "delete": event.key === "Backspace" || event.key === "Delete",
27127
- formattedValue: event.target.value
27128
- });
27168
+ rawValue: value
27169
+ };
27129
27170
  },
27130
- onChange: function onChange(event) {
27131
- /* At the beginning of onChange, event.target.value is a concat of the previous formatted value
27132
- * and an unformatted injection at the start, end, or in the middle (maybe a deletion). To prepare
27133
- * the unformatted value for the user's onChange, the formatted string and unformatted injection need
27134
- * to be separated, then unformat the formatted string, then insert (or delete) the injection from the
27135
- * old unformatted value.
27136
- */
27137
- var injectionLength = event.target.value.length - state.formattedValue.length;
27138
- var end = state.selectionStart === state.selectionEnd ? state.selectionStart + injectionLength : state.selectionEnd - 1;
27139
- var injection = event.target.value.substring(state.selectionStart, end); // Injection is the new unformatted piece of the input
27140
- // Need to find where to put it
27141
-
27142
- var rawInjectionPointStart = formattedToUnformattedIndex(state.selectionStart, state.rawValue, formatter);
27143
- var rawInjectionPointEnd = formattedToUnformattedIndex(state.selectionEnd, state.rawValue, formatter); // Unformat the previous formatted value for injection
27144
- // Using the relevant format string, strips away chars not marked with the formatChar
27145
-
27146
- var unformattedOldValue = unformat(formatter)(state.formattedValue, state.rawValue.length); // Edit the previous unformatted value (either add, update or delete)
27147
-
27148
- var injectIntoOldValue = inject(unformattedOldValue);
27149
- var unformattedNewValue = state["delete"] ? rawInjectionPointStart === rawInjectionPointEnd ? injectIntoOldValue(rawInjectionPointStart - 1, rawInjectionPointStart, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, injection);
27150
- var lengthDifference = unformattedNewValue.length - state.rawValue.length;
27151
- var rawIndex = formattedToUnformattedIndex(state.selectionStart, state.rawValue, formatter) + lengthDifference; // Find the new cursor position for the potential formatted value
27152
- // Applied by useLayoutEffect
27153
-
27154
- var newFormattedCursorPosition = state.selectionStart == state.selectionEnd ? unformattedToFormattedIndex(rawIndex, unformattedNewValue, formatter, state["delete"]) : state["delete"] ? state.selectionStart : state.selectionEnd;
27155
- setState({
27156
- selectionStart: newFormattedCursorPosition,
27157
- selectionEnd: newFormattedCursorPosition,
27158
- rawValue: state.rawValue,
27159
- "delete": false,
27160
- formattedValue: state.formattedValue
27161
- }); // Apply the external onChange function to the raw underlying string
27162
- // This is where the user generally updates the input value
27163
-
27164
- if (_onChange) {
27165
- _onChange(unformattedNewValue);
27166
- }
27167
- }
27171
+ onChange: handleChange
27168
27172
  }));
27169
27173
  };
27170
27174
 
@@ -27233,7 +27237,7 @@ var fallbackValues$n = {
27233
27237
  };
27234
27238
 
27235
27239
  var _excluded$v = ["showErrors", "themeValues"],
27236
- _excluded2 = ["type", "labelTextWhenNoError", "errorMessages", "isNum", "isEmail", "helperModal", "field", "fieldActions", "showErrors", "formatter", "decorator", "themeValues", "background", "customHeight", "autocompleteValue", "extraStyles", "removeFromValue", "dataQa", "isRequired", "errorFieldExtraStyles", "showFieldErrorRow"];
27240
+ _excluded2 = ["type", "labelTextWhenNoError", "errorMessages", "isNum", "isEmail", "helperModal", "field", "fieldActions", "showErrors", "formatter", "decorator", "themeValues", "background", "customHeight", "autocompleteValue", "extraStyles", "removeFromValue", "dataQa", "isRequired", "errorFieldExtraStyles", "showFieldErrorRow", "labelTextVariant", "errorTextVariant"];
27237
27241
  var InputField = styled__default.input.withConfig({
27238
27242
  displayName: "FormInput__InputField",
27239
27243
  componentId: "sc-l094r1-0"
@@ -27324,6 +27328,10 @@ var FormInput = function FormInput(_ref15) {
27324
27328
  errorFieldExtraStyles = _ref15.errorFieldExtraStyles,
27325
27329
  _ref15$showFieldError = _ref15.showFieldErrorRow,
27326
27330
  showFieldErrorRow = _ref15$showFieldError === void 0 ? true : _ref15$showFieldError,
27331
+ _ref15$labelTextVaria = _ref15.labelTextVariant,
27332
+ labelTextVariant = _ref15$labelTextVaria === void 0 ? "pS" : _ref15$labelTextVaria,
27333
+ _ref15$errorTextVaria = _ref15.errorTextVariant,
27334
+ errorTextVariant = _ref15$errorTextVaria === void 0 ? "pXS" : _ref15$errorTextVaria,
27327
27335
  props = _objectWithoutProperties(_ref15, _excluded2);
27328
27336
  var _useState = React.useState(false),
27329
27337
  _useState2 = _slicedToArray(_useState, 2),
@@ -27358,7 +27366,7 @@ var FormInput = function FormInput(_ref15) {
27358
27366
  }, /*#__PURE__*/React__default.createElement(Text$1, {
27359
27367
  as: "label",
27360
27368
  color: themeValues.labelColor,
27361
- variant: "pS",
27369
+ variant: labelTextVariant,
27362
27370
  weight: themeValues.fontWeight,
27363
27371
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
27364
27372
  id: createIdFromString(labelTextWhenNoError)
@@ -27371,12 +27379,12 @@ var FormInput = function FormInput(_ref15) {
27371
27379
  }, /*#__PURE__*/React__default.createElement(Text$1, {
27372
27380
  as: "label",
27373
27381
  color: themeValues.labelColor,
27374
- variant: "pS",
27382
+ variant: labelTextVariant,
27375
27383
  fontWeight: themeValues.fontWeight,
27376
27384
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
27377
27385
  id: createIdFromString(labelTextWhenNoError)
27378
27386
  }, labelTextWhenNoError), type === "password" && /*#__PURE__*/React__default.createElement(Text$1, {
27379
- variant: "pS",
27387
+ variant: labelTextVariant,
27380
27388
  color: themeValues.linkColor,
27381
27389
  weight: themeValues.fontWeight,
27382
27390
  hoverStyles: themeValues.hoverFocusStyles,
@@ -27456,7 +27464,7 @@ var FormInput = function FormInput(_ref15) {
27456
27464
  "aria-atomic": true
27457
27465
  }, field.hasErrors && field.dirty || field.hasErrors && showErrors ? /*#__PURE__*/React__default.createElement(Text$1, {
27458
27466
  color: ERROR_COLOR,
27459
- variant: "pXS",
27467
+ variant: errorTextVariant,
27460
27468
  weight: themeValues.fontWeight,
27461
27469
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }\n ".concat(errorFieldExtraStyles, ";"),
27462
27470
  id: createIdFromString(labelTextWhenNoError, "error message")
@@ -39053,6 +39061,15 @@ var allOptions = {
39053
39061
  }, {
39054
39062
  text: "Wyoming",
39055
39063
  value: "WY"
39064
+ }, {
39065
+ text: "Armed Forces Americas",
39066
+ value: "AA"
39067
+ }, {
39068
+ text: "Armed Forces Europe",
39069
+ value: "AE"
39070
+ }, {
39071
+ text: "Armed Forces Pacific",
39072
+ value: "AP"
39056
39073
  }],
39057
39074
  UM: [{
39058
39075
  text: "Palmyra Atoll",
@@ -49189,27 +49206,33 @@ PhoneForm.mapDispatchToProps = mapDispatchToProps$8;
49189
49206
  var DefaultHeading = styled__default.div.withConfig({
49190
49207
  displayName: "RadioGroup__DefaultHeading",
49191
49208
  componentId: "sc-7lqrl8-0"
49192
- })(["font-size:0.875rem;color:", " margin:0;padding:8px 0px;"], CHARADE_GREY);
49209
+ })(["", " color:", ";margin:0;padding:8px 0px;"], function (_ref) {
49210
+ var fontSize = _ref.fontSize;
49211
+ return "font-size: ".concat(fontSize, ";");
49212
+ }, CHARADE_GREY);
49193
49213
  var StyledFieldset = styled__default.fieldset.withConfig({
49194
49214
  displayName: "RadioGroup__StyledFieldset",
49195
49215
  componentId: "sc-7lqrl8-1"
49196
49216
  })(["", ""], function (props) {
49197
49217
  return props.$extraStyles;
49198
49218
  });
49199
- var RadioGroup = function RadioGroup(_ref) {
49200
- var headingText = _ref.headingText,
49201
- groupName = _ref.groupName,
49202
- _ref$heading = _ref.heading,
49203
- Heading = _ref$heading === void 0 ? /*#__PURE__*/React__default.createElement(DefaultHeading, {
49219
+ var RadioGroup = function RadioGroup(_ref2) {
49220
+ var headingText = _ref2.headingText,
49221
+ groupName = _ref2.groupName,
49222
+ _ref2$headingFontSize = _ref2.headingFontSize,
49223
+ headingFontSize = _ref2$headingFontSize === void 0 ? "0.875rem" : _ref2$headingFontSize,
49224
+ _ref2$heading = _ref2.heading,
49225
+ Heading = _ref2$heading === void 0 ? /*#__PURE__*/React__default.createElement(DefaultHeading, {
49204
49226
  role: "heading",
49205
- id: "radio-group-".concat(groupName, "-heading")
49206
- }, headingText) : _ref$heading,
49207
- config = _ref.config,
49208
- extraStyles = _ref.extraStyles,
49209
- _ref$handleChange = _ref.handleChange,
49210
- handleChange = _ref$handleChange === void 0 ? noop : _ref$handleChange,
49211
- field = _ref.field,
49212
- fieldActions = _ref.fieldActions;
49227
+ id: "radio-group-".concat(groupName, "-heading"),
49228
+ fontSize: headingFontSize
49229
+ }, headingText) : _ref2$heading,
49230
+ config = _ref2.config,
49231
+ extraStyles = _ref2.extraStyles,
49232
+ _ref2$handleChange = _ref2.handleChange,
49233
+ handleChange = _ref2$handleChange === void 0 ? noop : _ref2$handleChange,
49234
+ field = _ref2.field,
49235
+ fieldActions = _ref2.fieldActions;
49213
49236
  var setValue = function setValue(value) {
49214
49237
  return fieldActions.set(value);
49215
49238
  };