@thecb/components 12.1.0-beta.1 → 12.1.0-beta.3

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": "12.1.0-beta.1",
3
+ "version": "12.1.0-beta.3",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -9,7 +9,9 @@
9
9
  "scripts": {
10
10
  "storybook": "storybook dev -p 6006",
11
11
  "build": "rollup -cm",
12
- "build-storybook": "storybook build"
12
+ "build-storybook": "storybook build",
13
+ "sync": "./scripts/sync-to-project.sh",
14
+ "publish-beta": "./scripts/publish-beta.sh"
13
15
  },
14
16
  "repository": {
15
17
  "type": "git",
@@ -122,47 +122,41 @@ const Checkbox = forwardRef(
122
122
  }
123
123
  };
124
124
 
125
- const titleId = title ? `checkboxlabel-${name}` : undefined;
126
- const ariaLabelledById = labelledById ?? titleId;
127
- const ariaLabel = ariaLabelledById ? undefined : name;
125
+ const normalizedName = name ? name.replace(/\s+/g, "-") : name;
126
+ const checkboxId = `checkbox-${normalizedName}`;
127
+ const titleId = title ? `checkboxlabel-${normalizedName}` : undefined;
128
+ // aria-label fallback when no visible title or external labelledById is provided
129
+ const ariaLabel = !labelledById && !title ? name : undefined;
128
130
 
129
131
  return (
130
132
  <Box
131
133
  ref={ref}
132
134
  padding="0"
133
- tabIndex="0"
134
- role="checkbox"
135
- aria-checked={checked}
136
- aria-required={isRequired || undefined}
137
- aria-invalid={error}
138
- aria-label={ariaLabel}
139
- aria-labelledby={ariaLabelledById}
140
- aria-describedby={error ? `${name}-error-message` : undefined}
141
- onFocus={() => setFocused(true)}
142
- onBlur={() => setFocused(false)}
143
- onKeyDown={e => handleClick(e, onChange)}
144
135
  hiddenStyles={hidden}
145
136
  background={themeValues.backgroundColor}
146
137
  extraStyles={`
147
- :focus {
148
- outline: 0;
149
- }
150
138
  ${extraStyles};
151
139
  margin: ${checkboxMargin};
152
140
  `}
153
141
  {...rest}
154
142
  >
155
- <CheckboxLabelContainer data-qa={dataQa}>
143
+ <CheckboxLabelContainer htmlFor={checkboxId} data-qa={dataQa}>
156
144
  <CheckboxContainer data-qa="Checkbox">
157
145
  <HiddenCheckbox
158
- id={`checkbox-${name}`}
146
+ id={checkboxId}
159
147
  disabled={disabled}
160
148
  name={name}
161
149
  checked={checked}
162
150
  onChange={onChange}
163
- tabIndex="-1"
151
+ tabIndex="0"
164
152
  required={isRequired}
165
- aria-hidden="true"
153
+ aria-invalid={error}
154
+ aria-label={ariaLabel}
155
+ aria-labelledby={labelledById}
156
+ aria-describedby={error ? `${name}-error-message` : undefined}
157
+ onKeyDown={e => handleClick(e, onChange)}
158
+ onFocus={() => setFocused(true)}
159
+ onBlur={() => setFocused(false)}
166
160
  />
167
161
  <StyledCheckbox
168
162
  aria-hidden="true"
@@ -95,9 +95,15 @@ const RequiredCheckbox = props => {
95
95
  onChange={onChange}
96
96
  checked={checked}
97
97
  error={!checked}
98
+ extraStyles="display: inline-block;"
98
99
  />
99
100
  {!checked && (
100
- <div id={`${props.name}-error-message`}>You must check this!</div>
101
+ <div
102
+ id={`${props.name}-error-message`}
103
+ style={{ display: "inline-block" }}
104
+ >
105
+ This box is required.
106
+ </div>
101
107
  )}
102
108
  </div>
103
109
  );
@@ -39,7 +39,7 @@ const PartialAmountField = ({
39
39
  variant={themeValues.detailVariant}
40
40
  weight="400"
41
41
  >
42
- {lineItem.subDescription} payment amount
42
+ {lineItem.subDescription}
43
43
  </Detail>
44
44
  </Box>
45
45
  </Stack>
@@ -53,7 +53,6 @@ const PartialAmountField = ({
53
53
  placeholder="$0.00"
54
54
  formatter={moneyFormat}
55
55
  isNum
56
- isRequired
57
56
  decorator={
58
57
  <Text variant="p">
59
58
  Amount owed:{" "}
@@ -14,8 +14,10 @@ import {
14
14
  } from "../../atoms/form-layouts";
15
15
  import AccountAndRoutingModal from "../account-and-routing-modal";
16
16
  import { noop } from "../../../util/general";
17
- import { Cluster, Cover } from "../../atoms/layouts";
17
+ import { Cluster } from "../../atoms/layouts";
18
18
  import TermsAndConditions from "../terms-and-conditions";
19
+ import TermsAndConditionsModal from "../terms-and-conditions-modal";
20
+ import { useScrollTo } from "../../../hooks";
19
21
 
20
22
  const PaymentFormACH = ({
21
23
  variant = "default",
@@ -38,8 +40,16 @@ const PaymentFormACH = ({
38
40
  }
39
41
  const [showRouting, toggleShowRouting] = useState(false);
40
42
  const [showAccount, toggleShowAccount] = useState(false);
43
+ const [showTermsModal, setShowTermsModal] = useState(false);
41
44
  const showTerms = !!termsContent;
42
45
 
46
+ const toggleTermsModal = open => {
47
+ setShowTermsModal(open);
48
+ if (open) {
49
+ useScrollTo("terms-body-text", 0, 0, "smooth", 100);
50
+ }
51
+ };
52
+
43
53
  const nameErrors = {
44
54
  [required.error]: "Name is required"
45
55
  };
@@ -172,29 +182,39 @@ const PaymentFormACH = ({
172
182
  hidden={hideDefaultPayment}
173
183
  />
174
184
  )}
175
- {(showWalletCheckbox || showTerms) && (
176
- <Cluster childGap={"4px"} align="center">
177
- {showWalletCheckbox && (
178
- <Checkbox
179
- name="bank checkbox"
180
- dataQa="Save checking account to wallet"
181
- title="Save checking account to wallet."
182
- checked={walletCheckboxMarked}
183
- onChange={saveToWallet}
184
- />
185
- )}
186
- {showTerms && (
187
- <Cover singleChild>
188
- <TermsAndConditions
189
- version="v2"
190
- showCheckbox={false}
191
- description="View"
192
- terms={termsContent}
193
- initialFocusSelector={".modal-close-button"}
194
- />
195
- </Cover>
196
- )}
197
- </Cluster>
185
+ {showWalletCheckbox && (
186
+ <Checkbox
187
+ name="bank checkbox"
188
+ dataQa="Save checking account to wallet"
189
+ title={
190
+ <>
191
+ Save checking account to wallet (optional).{" "}
192
+ {showTerms && (
193
+ <span onClick={e => e.stopPropagation()}>
194
+ View{" "}
195
+ <TermsAndConditionsModal
196
+ link="Terms and Conditions"
197
+ terms={termsContent}
198
+ isOpen={showTermsModal}
199
+ toggleOpen={toggleTermsModal}
200
+ initialFocusSelector=".modal-close-button"
201
+ />
202
+ </span>
203
+ )}
204
+ </>
205
+ }
206
+ checked={walletCheckboxMarked}
207
+ onChange={saveToWallet}
208
+ />
209
+ )}
210
+ {!showWalletCheckbox && showTerms && (
211
+ <TermsAndConditions
212
+ version="v2"
213
+ showCheckbox={false}
214
+ description="View"
215
+ terms={termsContent}
216
+ initialFocusSelector=".modal-close-button"
217
+ />
198
218
  )}
199
219
  </FormInputColumn>
200
220
  </FormContainer>
@@ -0,0 +1,133 @@
1
+ import React, { useState } from "react";
2
+ import { connect, Provider } from "react-redux";
3
+ import { createStore } from "redux";
4
+ import PaymentFormACH from "./PaymentFormACH";
5
+ import * as PaymentFormACHState from "./PaymentFormACH.state";
6
+ import { noop } from "../../../util/general";
7
+ import { fn } from "@storybook/test";
8
+
9
+ const store = createStore(
10
+ PaymentFormACHState.reducer,
11
+ window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
12
+ );
13
+
14
+ const FormWrapper = props => {
15
+ const [walletChecked, setWalletChecked] = useState(
16
+ props.walletCheckboxMarked ?? false
17
+ );
18
+ return (
19
+ <PaymentFormACH
20
+ {...props}
21
+ walletCheckboxMarked={walletChecked}
22
+ saveToWallet={() => setWalletChecked(!walletChecked)}
23
+ />
24
+ );
25
+ };
26
+
27
+ const ConnectedForm = connect(
28
+ PaymentFormACHState.mapStateToProps,
29
+ PaymentFormACHState.mapDispatchToProps
30
+ )(FormWrapper);
31
+
32
+ export default {
33
+ title: "Molecules/PaymentFormACH",
34
+ component: ConnectedForm,
35
+ tags: ["!autodocs"],
36
+ parameters: {
37
+ layout: "centered",
38
+ controls: { expanded: true }
39
+ },
40
+ args: {
41
+ showErrors: false,
42
+ hideDefaultPayment: true,
43
+ allowBankAccountType: false,
44
+ showWalletCheckbox: false,
45
+ handleSubmit: noop
46
+ },
47
+ argTypes: {
48
+ showErrors: {
49
+ description: "Displays validation error messages on each field.",
50
+ control: { type: "boolean" },
51
+ table: {
52
+ type: { summary: "boolean" },
53
+ defaultValue: { summary: false }
54
+ }
55
+ },
56
+ hideDefaultPayment: {
57
+ description:
58
+ "Hides the 'Save as Default Payment Method' checkbox. Defaults to `true`.",
59
+ control: { type: "boolean" },
60
+ table: {
61
+ type: { summary: "boolean" },
62
+ defaultValue: { summary: true }
63
+ }
64
+ },
65
+ allowBankAccountType: {
66
+ description: "Shows the account type dropdown (Checking / Savings).",
67
+ control: { type: "boolean" },
68
+ table: {
69
+ type: { summary: "boolean" },
70
+ defaultValue: { summary: false }
71
+ }
72
+ },
73
+ showWalletCheckbox: {
74
+ description:
75
+ 'Shows the "Save checking account to wallet (optional)." checkbox.',
76
+ control: { type: "boolean" },
77
+ table: {
78
+ type: { summary: "boolean" },
79
+ defaultValue: { summary: false }
80
+ }
81
+ },
82
+ handleSubmit: {
83
+ description: "Function called when Enter is pressed on any text input.",
84
+ control: { type: "object" },
85
+ table: {
86
+ type: { summary: "function" },
87
+ defaultValue: { summary: undefined }
88
+ }
89
+ }
90
+ },
91
+ decorators: [
92
+ Story => (
93
+ <Provider store={store}>
94
+ <Story />
95
+ </Provider>
96
+ )
97
+ ]
98
+ };
99
+
100
+ export const Basic = args => <ConnectedForm {...args} />;
101
+
102
+ export const WithWalletCheckbox = {
103
+ args: {
104
+ showWalletCheckbox: true
105
+ },
106
+ render: args => <ConnectedForm {...args} />
107
+ };
108
+
109
+ export const ShowErrors = {
110
+ args: {
111
+ showErrors: true
112
+ },
113
+ render: args => <ConnectedForm {...args} />
114
+ };
115
+
116
+ export const WithAccountType = {
117
+ args: {
118
+ allowBankAccountType: true
119
+ },
120
+ render: args => <ConnectedForm {...args} />
121
+ };
122
+
123
+ export const WithWalletCheckboxAndTermsAndConditions = {
124
+ args: {
125
+ showWalletCheckbox: true,
126
+ termsContent: "View Terms and Conditions"
127
+ },
128
+ render: args => (
129
+ <div style={{ width: "100%", maxWidth: "560px" }}>
130
+ <ConnectedForm {...args} />
131
+ </div>
132
+ )
133
+ };
@@ -27,9 +27,11 @@ import {
27
27
  FormContainer,
28
28
  FormInputRow
29
29
  } from "../../atoms/form-layouts";
30
- import { Box, Cluster, Cover } from "../../atoms/layouts";
30
+ import { Box, Cluster } from "../../atoms/layouts";
31
31
  import withWindowSize from "../../withWindowSize";
32
32
  import TermsAndConditions from "../terms-and-conditions";
33
+ import TermsAndConditionsModal from "../terms-and-conditions-modal";
34
+ import { useScrollTo } from "../../../hooks";
33
35
 
34
36
  const PaymentFormCard = ({
35
37
  variant = "default",
@@ -46,8 +48,16 @@ const PaymentFormCard = ({
46
48
  termsContent
47
49
  }) => {
48
50
  const { isMobile } = useContext(ThemeContext);
51
+ const [showTermsModal, setShowTermsModal] = useState(false);
49
52
  const showTerms = !!termsContent;
50
53
 
54
+ const toggleTermsModal = open => {
55
+ setShowTermsModal(open);
56
+ if (open) {
57
+ useScrollTo("terms-body-text", 0, 0, "smooth", 100);
58
+ }
59
+ };
60
+
51
61
  useEffect(() => {
52
62
  if (deniedCards) {
53
63
  deniedCards.map(card =>
@@ -196,29 +206,39 @@ const PaymentFormCard = ({
196
206
  />
197
207
  </Box>
198
208
  )}
199
- {(showWalletCheckbox || showTerms) && (
200
- <Cluster childGap={"4px"} align="center">
201
- {showWalletCheckbox && (
202
- <Checkbox
203
- name="credit card checkbox"
204
- dataQa="Save credit card to wallet"
205
- title="Save credit card to wallet."
206
- checked={walletCheckboxMarked}
207
- onChange={saveToWallet}
208
- />
209
- )}
210
- {showTerms && (
211
- <Cover singleChild>
212
- <TermsAndConditions
213
- version="v2"
214
- showCheckbox={false}
215
- description="View"
216
- terms={termsContent}
217
- initialFocusSelector={".modal-close-button"}
218
- />
219
- </Cover>
220
- )}
221
- </Cluster>
209
+ {showWalletCheckbox && (
210
+ <Checkbox
211
+ name="credit card checkbox"
212
+ dataQa="Save credit card to wallet"
213
+ title={
214
+ <>
215
+ Save credit card to wallet (optional).{" "}
216
+ {showTerms && (
217
+ <span onClick={e => e.stopPropagation()}>
218
+ View{" "}
219
+ <TermsAndConditionsModal
220
+ link="Terms and Conditions"
221
+ terms={termsContent}
222
+ isOpen={showTermsModal}
223
+ toggleOpen={toggleTermsModal}
224
+ initialFocusSelector=".modal-close-button"
225
+ />
226
+ </span>
227
+ )}
228
+ </>
229
+ }
230
+ checked={walletCheckboxMarked}
231
+ onChange={saveToWallet}
232
+ />
233
+ )}
234
+ {!showWalletCheckbox && showTerms && (
235
+ <TermsAndConditions
236
+ version="v2"
237
+ showCheckbox={false}
238
+ description="View"
239
+ terms={termsContent}
240
+ initialFocusSelector=".modal-close-button"
241
+ />
222
242
  )}
223
243
  </FormInputColumn>
224
244
  </FormContainer>
@@ -0,0 +1,131 @@
1
+ import React, { useState } from "react";
2
+ import { connect, Provider } from "react-redux";
3
+ import { createStore } from "redux";
4
+ import PaymentFormCard from "./PaymentFormCard";
5
+ import * as PaymentFormCardState from "./PaymentFormCard.state";
6
+ import { noop } from "../../../util/general";
7
+
8
+ const store = createStore(
9
+ PaymentFormCardState.reducer,
10
+ window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
11
+ );
12
+
13
+ const FormWrapper = props => {
14
+ const [walletChecked, setWalletChecked] = useState(
15
+ props.walletCheckboxMarked ?? false
16
+ );
17
+ return (
18
+ <PaymentFormCard
19
+ {...props}
20
+ walletCheckboxMarked={walletChecked}
21
+ saveToWallet={() => setWalletChecked(!walletChecked)}
22
+ />
23
+ );
24
+ };
25
+
26
+ const ConnectedForm = connect(
27
+ PaymentFormCardState.mapStateToProps,
28
+ PaymentFormCardState.mapDispatchToProps
29
+ )(FormWrapper);
30
+
31
+ export default {
32
+ title: "Molecules/PaymentFormCard",
33
+ component: ConnectedForm,
34
+ tags: ["!autodocs"],
35
+ parameters: {
36
+ layout: "centered",
37
+ controls: { expanded: true }
38
+ },
39
+ args: {
40
+ showErrors: false,
41
+ hideZipCode: false,
42
+ showWalletCheckbox: false,
43
+ deniedCards: undefined,
44
+ handleSubmit: noop
45
+ },
46
+ argTypes: {
47
+ showErrors: {
48
+ description: "Displays validation error messages on each field.",
49
+ control: { type: "boolean" },
50
+ table: {
51
+ type: { summary: "boolean" },
52
+ defaultValue: { summary: false }
53
+ }
54
+ },
55
+ hideZipCode: {
56
+ description: "Hides the country dropdown and zip code field.",
57
+ control: { type: "boolean" },
58
+ table: {
59
+ type: { summary: "boolean" },
60
+ defaultValue: { summary: false }
61
+ }
62
+ },
63
+ showWalletCheckbox: {
64
+ description:
65
+ 'Shows the "Save credit card to wallet (optional)." checkbox.',
66
+ control: { type: "boolean" },
67
+ table: {
68
+ type: { summary: "boolean" },
69
+ defaultValue: { summary: false }
70
+ }
71
+ },
72
+ deniedCards: {
73
+ description: 'Array of card brand strings to deny (e.g. `["AMEX"]`).',
74
+ control: { type: "object" },
75
+ table: {
76
+ type: { summary: "string[]" },
77
+ defaultValue: { summary: undefined }
78
+ }
79
+ },
80
+ handleSubmit: {
81
+ description: "Function called when Enter is pressed on any text input.",
82
+ control: { type: "object" },
83
+ table: {
84
+ type: { summary: "function" },
85
+ defaultValue: { summary: undefined }
86
+ }
87
+ }
88
+ },
89
+ decorators: [
90
+ Story => (
91
+ <Provider store={store}>
92
+ <Story />
93
+ </Provider>
94
+ )
95
+ ]
96
+ };
97
+
98
+ export const Basic = args => <ConnectedForm {...args} />;
99
+
100
+ export const WithWalletCheckbox = {
101
+ args: {
102
+ showWalletCheckbox: true
103
+ },
104
+ render: args => <ConnectedForm {...args} />
105
+ };
106
+
107
+ export const ShowErrors = {
108
+ args: {
109
+ showErrors: true
110
+ },
111
+ render: args => <ConnectedForm {...args} />
112
+ };
113
+
114
+ export const WithDeniedCards = {
115
+ args: {
116
+ deniedCards: ["AMEX"]
117
+ },
118
+ render: args => <ConnectedForm {...args} />
119
+ };
120
+
121
+ export const WithWalletCheckboxAndTermsAndConditions = {
122
+ args: {
123
+ showWalletCheckbox: true,
124
+ termsContent: "View Terms and Conditions"
125
+ },
126
+ render: args => (
127
+ <div style={{ width: "100%", maxWidth: "560px" }}>
128
+ <ConnectedForm {...args} />
129
+ </div>
130
+ )
131
+ };
@@ -30,7 +30,8 @@ const TermsAndConditionsControlV2 = ({
30
30
  checkboxMargin = "4px 8px 4px 4px",
31
31
  modalTitle = "Terms and Conditions",
32
32
  initialFocusSelector = "",
33
- isRequired = false
33
+ isRequired = false,
34
+ textExtraStyles = ""
34
35
  }) => {
35
36
  const [showTerms, toggleShowTerms] = useState(false);
36
37
  const standardBoxShadow = generateShadows().standard.base;
@@ -70,7 +71,7 @@ const TermsAndConditionsControlV2 = ({
70
71
  justify="flex-start"
71
72
  align="center"
72
73
  nowrap
73
- extraStyles={`padding-right: 2px; > div > * { margin: 4px 2px; };`}
74
+ extraStyles={`padding-right: 2px; > div > * { margin: 4px 2px; }; ${textExtraStyles}`}
74
75
  id={TermsAndConditionsTitleDivId}
75
76
  >
76
77
  {description && <Text color={CHARADE_GREY}>{description}</Text>}