@thecb/components 4.1.4 → 4.1.6-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.
@@ -1,6 +1,8 @@
1
- import React, { useEffect } from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import { required, hasLength } from "redux-freeform";
3
+ import styled from "styled-components";
3
4
  import StateProvinceDropdown from "../../atoms/state-province-dropdown";
5
+ import Checkbox from "../../atoms/checkbox";
4
6
  // import CountryDropdown from "../../atoms/country-dropdown";
5
7
  import { zipFormat } from "../../../util/formats";
6
8
  import { noop } from "../../../util/general";
@@ -10,14 +12,28 @@ import {
10
12
  FormInputColumn
11
13
  } from "../../atoms/form-layouts";
12
14
 
15
+ const CheckboxWrapper = styled.div`
16
+ outline: none;
17
+ `;
18
+
13
19
  const AddressForm = ({
14
20
  variant = "default",
15
21
  fields,
16
22
  actions,
17
23
  clearOnDismount,
18
24
  showErrors,
19
- handleSubmit = noop
25
+ handleSubmit = noop,
26
+ showWalletCheckbox,
27
+ saveToWallet,
28
+ walletCheckboxMarked
20
29
  }) => {
30
+ const [checkboxFocused, focusCheckbox] = useState(false);
31
+
32
+ const handleClick = (e, func) => {
33
+ if (e?.keyCode === 13) {
34
+ func();
35
+ }
36
+ };
21
37
  if (clearOnDismount) {
22
38
  useEffect(() => () => actions.form.clear(), []);
23
39
  }
@@ -103,6 +119,22 @@ const AddressForm = ({
103
119
  showErrors={showErrors}
104
120
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
105
121
  />
122
+ {showWalletCheckbox && (
123
+ <CheckboxWrapper
124
+ tabIndex="0"
125
+ onFocus={() => focusCheckbox(true)}
126
+ onBlur={() => focusCheckbox(false)}
127
+ onKeyDown={e => handleClick(e, saveToWallet)}
128
+ >
129
+ <Checkbox
130
+ name="address checkbox"
131
+ title="Save address to wallet"
132
+ checked={walletCheckboxMarked}
133
+ onChange={saveToWallet}
134
+ focused={checkboxFocused}
135
+ />
136
+ </CheckboxWrapper>
137
+ )}
106
138
  </FormInputColumn>
107
139
  </FormContainer>
108
140
  );
@@ -1,13 +1,19 @@
1
- import React, { useEffect } from "react";
1
+ import React, { useEffect, useState } from "react";
2
+ import styled from "styled-components";
2
3
  import { required, isProbablyEmail } from "redux-freeform";
3
4
  import {
4
5
  FormInput,
5
6
  FormContainer,
6
7
  FormInputColumn
7
8
  } from "../../atoms/form-layouts";
9
+ import Checkbox from "../../atoms/checkbox";
8
10
  import Paragraph from "../../atoms/paragraph";
9
11
  import { noop } from "../../../util/general";
10
12
 
13
+ const CheckboxWrapper = styled.div`
14
+ outline: none;
15
+ `;
16
+
11
17
  const EmailForm = ({
12
18
  variant = "default",
13
19
  clearOnDismount,
@@ -15,8 +21,18 @@ const EmailForm = ({
15
21
  actions,
16
22
  showErrors,
17
23
  guestCheckout,
18
- handleSubmit = noop
24
+ handleSubmit = noop,
25
+ showWalletCheckbox,
26
+ saveToWallet,
27
+ walletCheckboxMarked
19
28
  }) => {
29
+ const [checkboxFocused, focusCheckbox] = useState(false);
30
+ const handleClick = (e, func) => {
31
+ if (e?.keyCode === 13) {
32
+ func();
33
+ }
34
+ };
35
+
20
36
  if (clearOnDismount) {
21
37
  useEffect(() => () => actions.form.clear(), []);
22
38
  }
@@ -42,6 +58,22 @@ const EmailForm = ({
42
58
  showErrors={showErrors}
43
59
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
44
60
  />
61
+ {showWalletCheckbox && (
62
+ <CheckboxWrapper
63
+ tabIndex="0"
64
+ onFocus={() => focusCheckbox(true)}
65
+ onBlur={() => focusCheckbox(false)}
66
+ onKeyDown={e => handleClick(e, saveToWallet)}
67
+ >
68
+ <Checkbox
69
+ name="email checkbox"
70
+ title="Save email address to wallet"
71
+ checked={walletCheckboxMarked}
72
+ onChange={saveToWallet}
73
+ focused={checkboxFocused}
74
+ />
75
+ </CheckboxWrapper>
76
+ )}
45
77
  </FormInputColumn>
46
78
  </FormContainer>
47
79
  );
@@ -18,6 +18,10 @@ import { noop } from "../../../util/general";
18
18
 
19
19
  const ModalWrapper = styled.div``;
20
20
 
21
+ const CheckboxWrapper = styled.div`
22
+ outline: none;
23
+ `;
24
+
21
25
  const PaymentFormACH = ({
22
26
  variant = "default",
23
27
  defaultMethod,
@@ -28,8 +32,17 @@ const PaymentFormACH = ({
28
32
  fields,
29
33
  actions,
30
34
  showErrors,
31
- handleSubmit = noop
35
+ handleSubmit = noop,
36
+ showWalletCheckbox,
37
+ saveToWallet,
38
+ walletCheckboxMarked
32
39
  }) => {
40
+ const [checkboxFocused, focusCheckbox] = useState(false);
41
+ const handleClick = (e, func) => {
42
+ if (e?.keyCode === 13) {
43
+ func();
44
+ }
45
+ };
33
46
  if (clearOnDismount) {
34
47
  useEffect(() => () => actions.form.clear(), []);
35
48
  }
@@ -162,6 +175,22 @@ const PaymentFormACH = ({
162
175
  hidden={hideDefaultPayment}
163
176
  />
164
177
  )}
178
+ {showWalletCheckbox && (
179
+ <CheckboxWrapper
180
+ tabIndex="0"
181
+ onFocus={() => focusCheckbox(true)}
182
+ onBlur={() => focusCheckbox(false)}
183
+ onKeyDown={e => handleClick(e, saveToWallet)}
184
+ >
185
+ <Checkbox
186
+ name="bank checkbox"
187
+ title="Save bank account to wallet"
188
+ checked={walletCheckboxMarked}
189
+ onChange={saveToWallet}
190
+ focused={checkboxFocused}
191
+ />
192
+ </CheckboxWrapper>
193
+ )}
165
194
  </FormInputColumn>
166
195
  </FormContainer>
167
196
  );
@@ -1,5 +1,7 @@
1
- import React, { useEffect } from "react";
1
+ import React, { useEffect, useState } from "react";
2
+ import styled from "styled-components";
2
3
  import { required, hasLength, matchesRegex } from "redux-freeform";
4
+ import Checkbox from "../../atoms/checkbox";
3
5
  import { checkCardBrand, noop } from "../../../util/general";
4
6
  import { expirationDateFormat, creditCardFormat } from "../../../util/formats";
5
7
  import {
@@ -10,6 +12,10 @@ import {
10
12
  } from "../../atoms/form-layouts";
11
13
  import { Box } from "../../atoms/layouts";
12
14
 
15
+ const CheckboxWrapper = styled.div`
16
+ outline: none;
17
+ `;
18
+
13
19
  const nameOnCardErrors = {
14
20
  [required.error]: "Name is required"
15
21
  };
@@ -39,8 +45,17 @@ const PaymentFormCard = ({
39
45
  actions,
40
46
  showErrors,
41
47
  handleSubmit = noop,
42
- isMobile
48
+ isMobile,
49
+ showWalletCheckbox,
50
+ saveToWallet,
51
+ walletCheckboxMarked
43
52
  }) => {
53
+ const [checkboxFocused, focusCheckbox] = useState(false);
54
+ const handleClick = (e, func) => {
55
+ if (e?.keyCode === 13) {
56
+ func();
57
+ }
58
+ };
44
59
  useEffect(() => {
45
60
  if (clearOnDismount) {
46
61
  return () => actions.form.clear();
@@ -105,6 +120,22 @@ const PaymentFormCard = ({
105
120
  />
106
121
  </Box>
107
122
  )}
123
+ {showWalletCheckbox && (
124
+ <CheckboxWrapper
125
+ tabIndex="0"
126
+ onFocus={() => focusCheckbox(true)}
127
+ onBlur={() => focusCheckbox(false)}
128
+ onKeyDown={e => handleClick(e, saveToWallet)}
129
+ >
130
+ <Checkbox
131
+ name="credit card checkbox"
132
+ title="Save credit card to wallet"
133
+ checked={walletCheckboxMarked}
134
+ onChange={saveToWallet}
135
+ focused={checkboxFocused}
136
+ />
137
+ </CheckboxWrapper>
138
+ )}
108
139
  </FormInputColumn>
109
140
  </FormContainer>
110
141
  );
@@ -1,5 +1,5 @@
1
- import React, { useEffect } from "react";
2
- import { phoneFormats, formatDelimiter } from "../../../util/formats";
1
+ import React, { useEffect, useState } from "react";
2
+ import styled from "styled-components";
3
3
  import { required, hasLength } from "redux-freeform";
4
4
  import { createFormat } from "formatted-input";
5
5
  import {
@@ -7,7 +7,13 @@ import {
7
7
  FormContainer,
8
8
  FormInputColumn
9
9
  } from "../../atoms/form-layouts";
10
+ import Checkbox from "../../atoms/checkbox";
10
11
  import { noop } from "../../../util/general";
12
+ import { phoneFormats, formatDelimiter } from "../../../util/formats";
13
+
14
+ const CheckboxWrapper = styled.div`
15
+ outline: none;
16
+ `;
11
17
 
12
18
  const PhoneForm = ({
13
19
  variant = "default",
@@ -15,8 +21,18 @@ const PhoneForm = ({
15
21
  actions,
16
22
  clearOnDismount,
17
23
  showErrors,
18
- handleSubmit = noop
24
+ handleSubmit = noop,
25
+ showWalletCheckbox,
26
+ saveToWallet,
27
+ walletCheckboxMarked
19
28
  }) => {
29
+ const [checkboxFocused, focusCheckbox] = useState(false);
30
+ const handleClick = (e, func) => {
31
+ if (e?.keyCode === 13) {
32
+ func();
33
+ }
34
+ };
35
+
20
36
  if (clearOnDismount) {
21
37
  useEffect(() => () => actions.form.clear(), []);
22
38
  }
@@ -37,6 +53,22 @@ const PhoneForm = ({
37
53
  formatter={createFormat(phoneFormats, formatDelimiter)}
38
54
  onKeyUp={e => e.key === "Enter" && handleSubmit(e)}
39
55
  />
56
+ {showWalletCheckbox && (
57
+ <CheckboxWrapper
58
+ tabIndex="0"
59
+ onFocus={() => focusCheckbox(true)}
60
+ onBlur={() => focusCheckbox(false)}
61
+ onKeyDown={e => handleClick(e, saveToWallet)}
62
+ >
63
+ <Checkbox
64
+ name="phone checkbox"
65
+ title="Save phone number to wallet"
66
+ checked={walletCheckboxMarked}
67
+ onChange={saveToWallet}
68
+ focused={checkboxFocused}
69
+ />
70
+ </CheckboxWrapper>
71
+ )}
40
72
  </FormInputColumn>
41
73
  </FormContainer>
42
74
  );