@thecb/components 9.1.3 → 9.1.4-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "9.1.3",
3
+ "version": "9.1.4-beta.5",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
package/src/.DS_Store CHANGED
Binary file
Binary file
Binary file
@@ -10,7 +10,8 @@ const CountryDropdown = ({
10
10
  fieldActions,
11
11
  showErrors,
12
12
  onChange,
13
- dataQa = null
13
+ dataQa = null,
14
+ isRequired = false
14
15
  }) => (
15
16
  <FormSelect
16
17
  options={options}
@@ -22,6 +23,7 @@ const CountryDropdown = ({
22
23
  showErrors={showErrors}
23
24
  onChange={onChange}
24
25
  autocompleteValue="country-name"
26
+ isRequired={isRequired}
25
27
  />
26
28
  );
27
29
  export default CountryDropdown;
@@ -116,6 +116,7 @@ const FormInput = ({
116
116
  extraStyles,
117
117
  removeFromValue, // regex of characters to remove before setting value
118
118
  dataQa = null,
119
+ isRequired = false,
119
120
  ...props
120
121
  }) => {
121
122
  const [showPassword, setShowPassword] = useState(false);
@@ -221,6 +222,7 @@ const FormInput = ({
221
222
  $extraStyles={extraStyles}
222
223
  data-qa={dataQa || labelTextWhenNoError}
223
224
  autoComplete={autocompleteValue}
225
+ required={isRequired}
224
226
  {...props}
225
227
  />
226
228
  ) : (
@@ -247,6 +249,7 @@ const FormInput = ({
247
249
  $extraStyles={extraStyles}
248
250
  data-qa={dataQa || labelTextWhenNoError}
249
251
  autoComplete={autocompleteValue}
252
+ required={isRequired}
250
253
  {...props}
251
254
  />
252
255
  )}
@@ -24,7 +24,8 @@ const FormSelect = ({
24
24
  autocompleteValue, // browser autofill value, like country-name
25
25
  smoothScroll = true, // whether the browser should animate scroll to selected item on first open
26
26
  dataQa = null,
27
- widthFitOptions = false
27
+ widthFitOptions = false,
28
+ isRequired = false
28
29
  }) => {
29
30
  const [open, setOpen] = useState(false);
30
31
  const dropdownRef = useRef(null);
@@ -94,6 +95,7 @@ const FormSelect = ({
94
95
  disabled={disabled}
95
96
  autocompleteValue={autocompleteValue}
96
97
  smoothScroll={smoothScroll}
98
+ required={isRequired}
97
99
  />
98
100
  <Stack direction="row" justify="space-between">
99
101
  <Text
@@ -8,7 +8,7 @@ export const MotionWrapper = styled(motion.div)`
8
8
  padding: ${({ padding }) => padding};
9
9
  border: ${({ borderShorthand }) => borderShorthand};
10
10
  border-color: ${({ borderColor }) => borderColor};
11
- border-size: ${({ borderSize }) => borderSize};
11
+ border-width: ${({ borderSize }) => borderSize};
12
12
  border-style: ${({ borderStyle }) => borderStyle};
13
13
  border-width: ${({ borderWidth }) => borderWidth};
14
14
  border-radius: ${({ borderRadius }) => borderRadius};
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from "react";
1
+ import React, { useEffect, useState, useCallback } from "react";
2
2
  import Checkbox from "../../atoms/checkbox";
3
3
  import {
4
4
  required,
@@ -50,7 +50,8 @@ const PaymentFormACH = ({
50
50
  };
51
51
  const confirmRoutingNumberErrors = {
52
52
  [matchesField.error]:
53
- "Confirm routing number field must match routing number"
53
+ "Confirm routing number field must match routing number",
54
+ [required.error]: "Confirm routing number is required"
54
55
  };
55
56
  const accountNumberErrors = {
56
57
  [required.error]: "Account number is required",
@@ -58,12 +59,21 @@ const PaymentFormACH = ({
58
59
  };
59
60
  const confirmAccountNumberErrors = {
60
61
  [matchesField.error]:
61
- "Confirm account number field must match account number"
62
+ "Confirm account number field must match account number",
63
+ [required.error]: "Confirm account number is required"
62
64
  };
63
65
  const accountTypeErrors = {
64
66
  [required.error]: "Account type is required"
65
67
  };
66
68
 
69
+ const getIsRequiredFromValidators = useCallback(
70
+ field =>
71
+ !!field?.validators?.find(
72
+ validator => validator.type === "validator/REQUIRED"
73
+ ),
74
+ []
75
+ );
76
+
67
77
  return (
68
78
  <FormContainer variant={variant} role="form" aria-label="ACH Payment">
69
79
  <FormInputColumn>
@@ -76,6 +86,7 @@ const PaymentFormACH = ({
76
86
  showErrors={showErrors}
77
87
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
78
88
  autocompleteValue="name"
89
+ isRequired={getIsRequiredFromValidators(fields.name)}
79
90
  />
80
91
  <FormInput
81
92
  labelTextWhenNoError="Routing number"
@@ -84,6 +95,7 @@ const PaymentFormACH = ({
84
95
  field={fields.routingNumber}
85
96
  fieldActions={actions.fields.routingNumber}
86
97
  showErrors={showErrors}
98
+ isRequired={getIsRequiredFromValidators(fields.routingNumber)}
87
99
  isNum
88
100
  helperModal={() => (
89
101
  <AccountAndRoutingModal
@@ -106,6 +118,7 @@ const PaymentFormACH = ({
106
118
  fieldActions={actions.fields.confirmRoutingNumber}
107
119
  showErrors={showErrors}
108
120
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
121
+ isRequired={getIsRequiredFromValidators(fields.confirmRoutingNumber)}
109
122
  isNum
110
123
  />
111
124
  <FormInput
@@ -115,6 +128,7 @@ const PaymentFormACH = ({
115
128
  field={fields.accountNumber}
116
129
  fieldActions={actions.fields.accountNumber}
117
130
  showErrors={showErrors}
131
+ isRequired={getIsRequiredFromValidators(fields.accountNumber)}
118
132
  isNum
119
133
  helperModal={() => (
120
134
  <AccountAndRoutingModal
@@ -137,6 +151,7 @@ const PaymentFormACH = ({
137
151
  fieldActions={actions.fields.confirmAccountNumber}
138
152
  showErrors={showErrors}
139
153
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
154
+ isRequired={getIsRequiredFromValidators(fields.confirmAccountNumber)}
140
155
  isNum
141
156
  />
142
157
  {allowBankAccountType && (
@@ -152,6 +167,7 @@ const PaymentFormACH = ({
152
167
  showErrors={showErrors}
153
168
  errorMessages={accountTypeErrors}
154
169
  field={fields.accountType}
170
+ isRequired={getIsRequiredFromValidators(fields.accountType)}
155
171
  />
156
172
  )}
157
173
  {!hideDefaultPayment && (
@@ -16,7 +16,7 @@ const formConfig = {
16
16
  constraints: [onlyIntegers(), hasLength(0, 9)]
17
17
  },
18
18
  confirmRoutingNumber: {
19
- validators: [matchesField("routingNumber")],
19
+ validators: [matchesField("routingNumber"), required()],
20
20
  constraints: [onlyIntegers(), hasLength(0, 9)]
21
21
  },
22
22
  accountNumber: {
@@ -24,7 +24,7 @@ const formConfig = {
24
24
  constraints: [onlyIntegers(), hasLength(0, 17)]
25
25
  },
26
26
  confirmAccountNumber: {
27
- validators: [matchesField("accountNumber")],
27
+ validators: [matchesField("accountNumber"), required()],
28
28
  constraints: [onlyIntegers(), hasLength(0, 17)]
29
29
  },
30
30
  accountType: {
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useContext, useState } from "react";
1
+ import React, { useEffect, useContext, useCallback } from "react";
2
2
  import { ThemeContext } from "styled-components";
3
3
  import {
4
4
  required,
@@ -47,6 +47,14 @@ const PaymentFormCard = ({
47
47
  const { isMobile } = useContext(ThemeContext);
48
48
  const showTerms = !!termsContent;
49
49
 
50
+ const getIsRequiredFromValidators = useCallback(
51
+ field =>
52
+ !!field?.validators?.find(
53
+ validator => validator.type === "validator/REQUIRED"
54
+ ),
55
+ []
56
+ );
57
+
50
58
  useEffect(() => {
51
59
  if (deniedCards) {
52
60
  deniedCards.map(card =>
@@ -110,6 +118,7 @@ const PaymentFormCard = ({
110
118
  }}
111
119
  showErrors={showErrors}
112
120
  dataQa="Country"
121
+ isRequired={getIsRequiredFromValidators(fields.country)}
113
122
  />
114
123
  )}
115
124
  <FormInput
@@ -121,6 +130,7 @@ const PaymentFormCard = ({
121
130
  showErrors={showErrors}
122
131
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
123
132
  autocompleteValue="cc-name"
133
+ isRequired={getIsRequiredFromValidators(fields.nameOnCard)}
124
134
  />
125
135
  <FormInput
126
136
  labelTextWhenNoError="Credit card number"
@@ -133,6 +143,7 @@ const PaymentFormCard = ({
133
143
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
134
144
  isNum
135
145
  autocompleteValue="cc-number"
146
+ isRequired={getIsRequiredFromValidators(fields.creditCardNumber)}
136
147
  />
137
148
  <FormInputRow
138
149
  breakpoint={isMobile ? "1000rem" : "21rem"}
@@ -150,6 +161,7 @@ const PaymentFormCard = ({
150
161
  isNum
151
162
  removeFromValue={/\//} // removes "/" from browser autofill
152
163
  autocompleteValue="cc-exp"
164
+ isRequired={getIsRequiredFromValidators(fields.expirationDate)}
153
165
  />
154
166
  <FormInput
155
167
  labelTextWhenNoError="CVV"
@@ -166,6 +178,7 @@ const PaymentFormCard = ({
166
178
  }
167
179
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
168
180
  autocompleteValue="cc-csc"
181
+ isRequired={getIsRequiredFromValidators(fields.cvv)}
169
182
  />
170
183
  </FormInputRow>
171
184
  {!hideZipCode && (
@@ -184,6 +197,7 @@ const PaymentFormCard = ({
184
197
  showErrors={showErrors}
185
198
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
186
199
  autocompleteValue="billing postal-code"
200
+ isRequired={getIsRequiredFromValidators(fields.zipCode)}
187
201
  />
188
202
  </Box>
189
203
  )}
@@ -123,7 +123,8 @@ const RadioSection = ({
123
123
  extraStyles={borderStyles}
124
124
  role="radio"
125
125
  aria-checked={openSection === section.id}
126
- aria-disabled={section.disabled}
126
+ disabled={section.disabled}
127
+ required={section?.required}
127
128
  >
128
129
  <Stack childGap="0">
129
130
  <Box
@@ -166,6 +167,8 @@ const RadioSection = ({
166
167
  {!section.hideRadioButton && (
167
168
  <Box padding="0">
168
169
  <RadioButton
170
+ role="radio"
171
+ required={!!section?.required}
169
172
  id={`radio-input-${idString(section)}`}
170
173
  name={idString(section)}
171
174
  ariaDescribedBy={ariaDescribedBy}