@thecb/components 4.1.9 → 4.1.10-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
@@ -18907,7 +18907,7 @@ function _templateObject3$5() {
18907
18907
  }
18908
18908
 
18909
18909
  function _templateObject2$b() {
18910
- var data = _taggedTemplateLiteral(["\n transform-origin: 0 0;\n border: 1px solid ", ";\n border-radius: 2px;\n background-color: ", ";\n padding: 8px 0 8px;\n position: absolute;\n width: 100%;\n max-height: ", ";\n overflow-y: scroll;\n z-index: 1;\n box-sizing: border-box;\n &:focus {\n outline: none;\n }\n"]);
18910
+ var data = _taggedTemplateLiteral(["\n transform-origin: 0 0;\n border: 1px solid ", ";\n border-radius: 2px;\n background-color: ", ";\n padding: 8px 0 8px;\n position: absolute;\n width: ", ";\n min-width: 100%;\n max-height: ", ";\n overflow-y: scroll;\n z-index: 1;\n box-sizing: border-box;\n &:focus {\n outline: none;\n }\n"]);
18911
18911
 
18912
18912
  _templateObject2$b = function _templateObject2() {
18913
18913
  return data;
@@ -18917,7 +18917,7 @@ function _templateObject2$b() {
18917
18917
  }
18918
18918
 
18919
18919
  function _templateObject$n() {
18920
- var data = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n justify-content: center;\n transition: transform 0.3s ease;\n ", "\n"]);
18920
+ var data = _taggedTemplateLiteral(["\n display: flex;\n padding-left: 8px;\n flex-direction: column;\n justify-content: center;\n transition: transform 0.3s ease;\n ", "\n"]);
18921
18921
 
18922
18922
  _templateObject$n = function _templateObject() {
18923
18923
  return data;
@@ -18930,47 +18930,52 @@ var IconWrapper = styled__default.div(_templateObject$n(), function (_ref) {
18930
18930
  return open ? "transform: rotate(-180deg)" : "";
18931
18931
  });
18932
18932
  var DropdownContentWrapper = styled__default.div(_templateObject2$b(), GREY_CHATEAU, WHITE, function (_ref2) {
18933
- var maxHeight = _ref2.maxHeight;
18933
+ var widthFitOptions = _ref2.widthFitOptions;
18934
+ return widthFitOptions ? "fit-content" : "100%";
18935
+ }, function (_ref3) {
18936
+ var maxHeight = _ref3.maxHeight;
18934
18937
  return maxHeight || "400px";
18935
18938
  });
18936
- var DropdownItemWrapper = styled__default.div(_templateObject3$5(), function (_ref3) {
18937
- var selected = _ref3.selected,
18938
- themeValues = _ref3.themeValues;
18939
+ var DropdownItemWrapper = styled__default.div(_templateObject3$5(), function (_ref4) {
18940
+ var selected = _ref4.selected,
18941
+ themeValues = _ref4.themeValues;
18939
18942
  return selected ? themeValues.selectedColor : WHITE;
18940
- }, function (_ref4) {
18941
- var disabled = _ref4.disabled;
18942
- return disabled ? "default" : "pointer";
18943
18943
  }, function (_ref5) {
18944
- var selected = _ref5.selected,
18945
- disabled = _ref5.disabled,
18946
- themeValues = _ref5.themeValues;
18947
- return selected ? themeValues.selectedColor : disabled ? WHITE : themeValues.hoverColor;
18944
+ var disabled = _ref5.disabled;
18945
+ return disabled ? "default" : "pointer";
18948
18946
  }, function (_ref6) {
18949
18947
  var selected = _ref6.selected,
18950
18948
  disabled = _ref6.disabled,
18951
18949
  themeValues = _ref6.themeValues;
18952
18950
  return selected ? themeValues.selectedColor : disabled ? WHITE : themeValues.hoverColor;
18951
+ }, function (_ref7) {
18952
+ var selected = _ref7.selected,
18953
+ disabled = _ref7.disabled,
18954
+ themeValues = _ref7.themeValues;
18955
+ return selected ? themeValues.selectedColor : disabled ? WHITE : themeValues.hoverColor;
18953
18956
  });
18954
- var SearchInput = styled__default.input(_templateObject4$2(), function (_ref7) {
18955
- var themeValues = _ref7.themeValues;
18957
+ var SearchInput = styled__default.input(_templateObject4$2(), function (_ref8) {
18958
+ var themeValues = _ref8.themeValues;
18956
18959
  return themeValues.hoverColor && themeValues.hoverColor;
18957
18960
  });
18958
18961
 
18959
- var Dropdown = function Dropdown(_ref8) {
18962
+ var Dropdown = function Dropdown(_ref9) {
18960
18963
  var _options$find;
18961
18964
 
18962
- var placeholder = _ref8.placeholder,
18963
- options = _ref8.options,
18964
- value = _ref8.value,
18965
- isOpen = _ref8.isOpen,
18966
- isError = _ref8.isError,
18967
- onSelect = _ref8.onSelect,
18968
- _ref8$disabledValues = _ref8.disabledValues,
18969
- disabledValues = _ref8$disabledValues === void 0 ? [] : _ref8$disabledValues,
18970
- _ref8$onClick = _ref8.onClick,
18971
- onClick = _ref8$onClick === void 0 ? noop : _ref8$onClick,
18972
- themeValues = _ref8.themeValues,
18973
- maxHeight = _ref8.maxHeight;
18965
+ var placeholder = _ref9.placeholder,
18966
+ options = _ref9.options,
18967
+ value = _ref9.value,
18968
+ isOpen = _ref9.isOpen,
18969
+ isError = _ref9.isError,
18970
+ onSelect = _ref9.onSelect,
18971
+ _ref9$disabledValues = _ref9.disabledValues,
18972
+ disabledValues = _ref9$disabledValues === void 0 ? [] : _ref9$disabledValues,
18973
+ _ref9$onClick = _ref9.onClick,
18974
+ onClick = _ref9$onClick === void 0 ? noop : _ref9$onClick,
18975
+ themeValues = _ref9.themeValues,
18976
+ maxHeight = _ref9.maxHeight,
18977
+ _ref9$widthFitOptions = _ref9.widthFitOptions,
18978
+ widthFitOptions = _ref9$widthFitOptions === void 0 ? false : _ref9$widthFitOptions;
18974
18979
 
18975
18980
  var _useState = React.useState(""),
18976
18981
  _useState2 = _slicedToArray(_useState, 2),
@@ -19066,7 +19071,7 @@ var Dropdown = function Dropdown(_ref8) {
19066
19071
  break;
19067
19072
  }
19068
19073
 
19069
- if (keyCode > 64 && keyCode < 91 || keyCode == 32) {
19074
+ if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
19070
19075
  e.preventDefault();
19071
19076
  setInputValue(inputValue + key);
19072
19077
  }
@@ -19137,6 +19142,7 @@ var Dropdown = function Dropdown(_ref8) {
19137
19142
  maxHeight: maxHeight,
19138
19143
  open: isOpen,
19139
19144
  ref: dropdownRef,
19145
+ widthFitOptions: widthFitOptions,
19140
19146
  tabIndex: 0
19141
19147
  }, /*#__PURE__*/React__default.createElement(Stack, {
19142
19148
  childGap: "0"
@@ -34259,17 +34265,33 @@ var AddressForm = function AddressForm(_ref) {
34259
34265
 
34260
34266
  var zipErrorMessages = (_zipErrorMessages = {}, _defineProperty(_zipErrorMessages, required.error, "Zip code is required"), _defineProperty(_zipErrorMessages, hasLength.error, "Zip code must be 5 or 9 digits"), _zipErrorMessages);
34261
34267
 
34262
- var stateProvinceErrorMessages = _defineProperty({}, required.error, "State or Province is required"); // const countryErrorMessages = {
34263
- // [required.error]: "Country is required"
34264
- // };
34268
+ var stateProvinceErrorMessages = _defineProperty({}, required.error, "State or Province is required");
34265
34269
 
34270
+ var countryErrorMessages = _defineProperty({}, required.error, "Country is required");
34266
34271
 
34267
34272
  var isUS = fields.country.rawValue === "US";
34268
34273
  return /*#__PURE__*/React__default.createElement(FormContainer$1, {
34269
34274
  variant: variant,
34270
34275
  role: "form",
34271
34276
  "aria-label": "Address"
34272
- }, /*#__PURE__*/React__default.createElement(FormInputColumn, null, /*#__PURE__*/React__default.createElement(FormInput$1, {
34277
+ }, /*#__PURE__*/React__default.createElement(FormInputColumn, null, /*#__PURE__*/React__default.createElement(CountryDropdown, {
34278
+ labelTextWhenNoError: "Country",
34279
+ errorMessages: countryErrorMessages,
34280
+ field: fields.country,
34281
+ onChange: function onChange(value) {
34282
+ actions.fields.country.set(value); // temporary measure to not dirty fields until
34283
+ // we can write a reset function for fields
34284
+
34285
+ if (fields.stateProvince.rawValue) {
34286
+ actions.fields.stateProvince.set("");
34287
+ }
34288
+
34289
+ if (fields.zip.rawValue) {
34290
+ actions.fields.zip.set("");
34291
+ }
34292
+ },
34293
+ showErrors: showErrors
34294
+ }), /*#__PURE__*/React__default.createElement(FormInput$1, {
34273
34295
  labelTextWhenNoError: "Address",
34274
34296
  errorMessages: street1ErrorMessages,
34275
34297
  field: fields.street1,
@@ -39321,6 +39343,8 @@ var expirationDateErrors = (_expirationDateErrors = {}, _defineProperty(_expirat
39321
39343
  var cvvErrors = (_cvvErrors = {}, _defineProperty(_cvvErrors, required.error, "CVV is required"), _defineProperty(_cvvErrors, hasLength.error, "CVV is invalid"), _cvvErrors);
39322
39344
  var zipCodeErrors = (_zipCodeErrors = {}, _defineProperty(_zipCodeErrors, required.error, "Zip code is required"), _defineProperty(_zipCodeErrors, hasLength.error, "Zip code is invalid"), _zipCodeErrors);
39323
39345
 
39346
+ var countryErrorMessages = _defineProperty({}, required.error, "Country is required");
39347
+
39324
39348
  var PaymentFormCard = function PaymentFormCard(_ref) {
39325
39349
  var _ref$variant = _ref.variant,
39326
39350
  variant = _ref$variant === void 0 ? "default" : _ref$variant,
@@ -39355,11 +39379,29 @@ var PaymentFormCard = function PaymentFormCard(_ref) {
39355
39379
  };
39356
39380
  }
39357
39381
  }, []);
39382
+ var isUS = fields.country.rawValue === "US";
39358
39383
  return /*#__PURE__*/React__default.createElement(FormContainer$1, {
39359
39384
  variant: variant,
39360
39385
  role: "form",
39361
39386
  "aria-label": "Card payment"
39362
- }, /*#__PURE__*/React__default.createElement(FormInputColumn, null, /*#__PURE__*/React__default.createElement(FormInput$1, {
39387
+ }, /*#__PURE__*/React__default.createElement(FormInputColumn, null, /*#__PURE__*/React__default.createElement(CountryDropdown, {
39388
+ labelTextWhenNoError: "Country",
39389
+ errorMessages: countryErrorMessages,
39390
+ field: fields.country,
39391
+ onChange: function onChange(value) {
39392
+ actions.fields.country.set(value); // temporary measure to not dirty fields until
39393
+ // we can write a reset function for fields
39394
+
39395
+ if (fields.stateProvince.rawValue) {
39396
+ actions.fields.stateProvince.set("");
39397
+ }
39398
+
39399
+ if (fields.zipCode.rawValue) {
39400
+ actions.fields.zipCode.set("");
39401
+ }
39402
+ },
39403
+ showErrors: showErrors
39404
+ }), /*#__PURE__*/React__default.createElement(FormInput$1, {
39363
39405
  labelTextWhenNoError: "Name on card",
39364
39406
  errorMessages: nameOnCardErrors,
39365
39407
  field: fields.nameOnCard,
@@ -39404,6 +39446,8 @@ var PaymentFormCard = function PaymentFormCard(_ref) {
39404
39446
  padding: isMobile ? "0" : "0 0.5rem 0 0",
39405
39447
  width: isMobile ? "100%" : "50%"
39406
39448
  }, /*#__PURE__*/React__default.createElement(FormInput$1, {
39449
+ isNum: isUS,
39450
+ formatter: isUS ? zipFormat : null,
39407
39451
  labelTextWhenNoError: "Zip code",
39408
39452
  errorMessages: zipCodeErrors,
39409
39453
  field: fields.zipCode,
@@ -39433,6 +39477,10 @@ var PaymentFormCard = function PaymentFormCard(_ref) {
39433
39477
  };
39434
39478
 
39435
39479
  var formConfig$7 = {
39480
+ country: {
39481
+ defaultValue: "US",
39482
+ validators: [required()]
39483
+ },
39436
39484
  nameOnCard: {
39437
39485
  validators: [required()]
39438
39486
  },
@@ -39449,8 +39497,8 @@ var formConfig$7 = {
39449
39497
  constraints: [onlyIntegers(), hasLength(0, 4)]
39450
39498
  },
39451
39499
  zipCode: {
39452
- validators: [required(), hasLength(5, 5)],
39453
- constraints: [onlyIntegers(), hasLength(0, 5)]
39500
+ validators: [required(), validateWhen(validateWhen(hasLength(5, 5), hasLength(0, 5)), matchesRegex("US"), "country"), validateWhen(validateWhen(hasLength(9, 9), hasLength(6, 9)), matchesRegex("US"), "country")],
39501
+ constraints: [validateWhen(onlyIntegers(), matchesRegex("US"), "country"), validateWhen(hasLength(0, 9), matchesRegex("US"), "country")]
39454
39502
  }
39455
39503
  };
39456
39504
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "4.1.9",
3
+ "version": "4.1.10-beta.0",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -17,6 +17,7 @@ import { themeComponent } from "../../../util/themeUtils";
17
17
 
18
18
  const IconWrapper = styled.div`
19
19
  display: flex;
20
+ padding-left: 8px;
20
21
  flex-direction: column;
21
22
  justify-content: center;
22
23
  transition: transform 0.3s ease;
@@ -30,7 +31,8 @@ const DropdownContentWrapper = styled.div`
30
31
  background-color: ${WHITE};
31
32
  padding: 8px 0 8px;
32
33
  position: absolute;
33
- width: 100%;
34
+ width: ${({ widthFitOptions }) => (widthFitOptions ? "fit-content" : "100%")};
35
+ min-width: 100%;
34
36
  max-height: ${({ maxHeight }) => maxHeight || "400px"};
35
37
  overflow-y: scroll;
36
38
  z-index: 1;
@@ -89,7 +91,8 @@ const Dropdown = ({
89
91
  disabledValues = [],
90
92
  onClick = noop,
91
93
  themeValues,
92
- maxHeight
94
+ maxHeight,
95
+ widthFitOptions = false
93
96
  }) => {
94
97
  const [inputValue, setInputValue] = useState("");
95
98
  const [optionsState, setOptionsState] = useState([]);
@@ -151,7 +154,7 @@ const Dropdown = ({
151
154
  setInputValue(inputValue.slice(0, -1));
152
155
  break;
153
156
  }
154
- if ((keyCode > 64 && keyCode < 91) || keyCode == 32) {
157
+ if ((keyCode > 64 && keyCode < 91) || keyCode == 32 || keyCode == 189) {
155
158
  e.preventDefault();
156
159
  setInputValue(inputValue + key);
157
160
  }
@@ -247,6 +250,7 @@ const Dropdown = ({
247
250
  maxHeight={maxHeight}
248
251
  open={isOpen}
249
252
  ref={dropdownRef}
253
+ widthFitOptions={widthFitOptions}
250
254
  tabIndex={0}
251
255
  >
252
256
  <Stack childGap="0">
@@ -3,7 +3,7 @@ import { required, hasLength } from "redux-freeform";
3
3
  import styled from "styled-components";
4
4
  import StateProvinceDropdown from "../../atoms/state-province-dropdown";
5
5
  import Checkbox from "../../atoms/checkbox";
6
- // import CountryDropdown from "../../atoms/country-dropdown";
6
+ import CountryDropdown from "../../atoms/country-dropdown";
7
7
  import { zipFormat } from "../../../util/formats";
8
8
  import { noop } from "../../../util/general";
9
9
  import {
@@ -51,16 +51,16 @@ const AddressForm = ({
51
51
  const stateProvinceErrorMessages = {
52
52
  [required.error]: "State or Province is required"
53
53
  };
54
- // const countryErrorMessages = {
55
- // [required.error]: "Country is required"
56
- // };
54
+ const countryErrorMessages = {
55
+ [required.error]: "Country is required"
56
+ };
57
57
 
58
58
  const isUS = fields.country.rawValue === "US";
59
59
 
60
60
  return (
61
61
  <FormContainer variant={variant} role="form" aria-label="Address">
62
62
  <FormInputColumn>
63
- {/* <CountryDropdown
63
+ <CountryDropdown
64
64
  labelTextWhenNoError="Country"
65
65
  errorMessages={countryErrorMessages}
66
66
  field={fields.country}
@@ -76,7 +76,7 @@ const AddressForm = ({
76
76
  }
77
77
  }}
78
78
  showErrors={showErrors}
79
- /> */}
79
+ />
80
80
  <FormInput
81
81
  labelTextWhenNoError="Address"
82
82
  errorMessages={street1ErrorMessages}
@@ -2,8 +2,13 @@ import React, { useEffect, useState } from "react";
2
2
  import styled from "styled-components";
3
3
  import { required, hasLength, matchesRegex } from "redux-freeform";
4
4
  import Checkbox from "../../atoms/checkbox";
5
+ import CountryDropdown from "../../atoms/country-dropdown";
5
6
  import { checkCardBrand, noop } from "../../../util/general";
6
- import { expirationDateFormat, creditCardFormat } from "../../../util/formats";
7
+ import {
8
+ expirationDateFormat,
9
+ creditCardFormat,
10
+ zipFormat
11
+ } from "../../../util/formats";
7
12
  import {
8
13
  FormInput,
9
14
  FormInputColumn,
@@ -36,6 +41,9 @@ const zipCodeErrors = {
36
41
  [required.error]: "Zip code is required",
37
42
  [hasLength.error]: "Zip code is invalid"
38
43
  };
44
+ const countryErrorMessages = {
45
+ [required.error]: "Country is required"
46
+ };
39
47
 
40
48
  const PaymentFormCard = ({
41
49
  variant = "default",
@@ -61,9 +69,27 @@ const PaymentFormCard = ({
61
69
  return () => actions.form.clear();
62
70
  }
63
71
  }, []);
72
+ const isUS = fields.country.rawValue === "US";
64
73
  return (
65
74
  <FormContainer variant={variant} role="form" aria-label="Card payment">
66
75
  <FormInputColumn>
76
+ <CountryDropdown
77
+ labelTextWhenNoError="Country"
78
+ errorMessages={countryErrorMessages}
79
+ field={fields.country}
80
+ onChange={value => {
81
+ actions.fields.country.set(value);
82
+ // temporary measure to not dirty fields until
83
+ // we can write a reset function for fields
84
+ if (fields.stateProvince.rawValue) {
85
+ actions.fields.stateProvince.set("");
86
+ }
87
+ if (fields.zipCode.rawValue) {
88
+ actions.fields.zipCode.set("");
89
+ }
90
+ }}
91
+ showErrors={showErrors}
92
+ />
67
93
  <FormInput
68
94
  labelTextWhenNoError="Name on card"
69
95
  errorMessages={nameOnCardErrors}
@@ -111,6 +137,8 @@ const PaymentFormCard = ({
111
137
  width={isMobile ? "100%" : "50%"}
112
138
  >
113
139
  <FormInput
140
+ isNum={isUS}
141
+ formatter={isUS ? zipFormat : null}
114
142
  labelTextWhenNoError="Zip code"
115
143
  errorMessages={zipCodeErrors}
116
144
  field={fields.zipCode}
@@ -3,12 +3,17 @@ import {
3
3
  required,
4
4
  onlyIntegers,
5
5
  hasLength,
6
- matchesRegex
6
+ matchesRegex,
7
+ validateWhen
7
8
  } from "redux-freeform";
8
9
 
9
10
  //TODO: Will make zip code able to have more than 5 digits once we add in the FormattedInput because it will have issues with format of 60606-1111.
10
11
 
11
12
  const formConfig = {
13
+ country: {
14
+ defaultValue: "US",
15
+ validators: [required()]
16
+ },
12
17
  nameOnCard: {
13
18
  validators: [required()]
14
19
  },
@@ -29,8 +34,23 @@ const formConfig = {
29
34
  constraints: [onlyIntegers(), hasLength(0, 4)]
30
35
  },
31
36
  zipCode: {
32
- validators: [required(), hasLength(5, 5)],
33
- constraints: [onlyIntegers(), hasLength(0, 5)]
37
+ validators: [
38
+ required(),
39
+ validateWhen(
40
+ validateWhen(hasLength(5, 5), hasLength(0, 5)),
41
+ matchesRegex("US"),
42
+ "country"
43
+ ),
44
+ validateWhen(
45
+ validateWhen(hasLength(9, 9), hasLength(6, 9)),
46
+ matchesRegex("US"),
47
+ "country"
48
+ )
49
+ ],
50
+ constraints: [
51
+ validateWhen(onlyIntegers(), matchesRegex("US"), "country"),
52
+ validateWhen(hasLength(0, 9), matchesRegex("US"), "country")
53
+ ]
34
54
  }
35
55
  };
36
56