@thecb/components 12.0.6 → 12.1.0-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "12.0.6",
3
+ "version": "12.1.0-beta.0",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -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
  );
@@ -178,7 +178,7 @@ const PaymentFormACH = ({
178
178
  <Checkbox
179
179
  name="bank checkbox"
180
180
  dataQa="Save checking account to wallet"
181
- title="Save checking account to wallet."
181
+ title="Save checking account to wallet (optional)."
182
182
  checked={walletCheckboxMarked}
183
183
  onChange={saveToWallet}
184
184
  />
@@ -0,0 +1,121 @@
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
+ };
@@ -202,7 +202,7 @@ const PaymentFormCard = ({
202
202
  <Checkbox
203
203
  name="credit card checkbox"
204
204
  dataQa="Save credit card to wallet"
205
- title="Save credit card to wallet."
205
+ title="Save credit card to wallet (optional)."
206
206
  checked={walletCheckboxMarked}
207
207
  onChange={saveToWallet}
208
208
  />
@@ -0,0 +1,120 @@
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
+ import { fn } from "@storybook/test";
8
+
9
+ const store = createStore(
10
+ PaymentFormCardState.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
+ <PaymentFormCard
20
+ {...props}
21
+ walletCheckboxMarked={walletChecked}
22
+ saveToWallet={() => setWalletChecked(!walletChecked)}
23
+ />
24
+ );
25
+ };
26
+
27
+ const ConnectedForm = connect(
28
+ PaymentFormCardState.mapStateToProps,
29
+ PaymentFormCardState.mapDispatchToProps
30
+ )(FormWrapper);
31
+
32
+ export default {
33
+ title: "Molecules/PaymentFormCard",
34
+ component: ConnectedForm,
35
+ tags: ["!autodocs"],
36
+ parameters: {
37
+ layout: "centered",
38
+ controls: { expanded: true }
39
+ },
40
+ args: {
41
+ showErrors: false,
42
+ hideZipCode: false,
43
+ showWalletCheckbox: false,
44
+ deniedCards: undefined,
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
+ hideZipCode: {
57
+ description: "Hides the country dropdown and zip code field.",
58
+ control: { type: "boolean" },
59
+ table: {
60
+ type: { summary: "boolean" },
61
+ defaultValue: { summary: false }
62
+ }
63
+ },
64
+ showWalletCheckbox: {
65
+ description:
66
+ 'Shows the "Save credit card to wallet (optional)." checkbox.',
67
+ control: { type: "boolean" },
68
+ table: {
69
+ type: { summary: "boolean" },
70
+ defaultValue: { summary: false }
71
+ }
72
+ },
73
+ deniedCards: {
74
+ description: 'Array of card brand strings to deny (e.g. `["AMEX"]`).',
75
+ control: { type: "object" },
76
+ table: {
77
+ type: { summary: "string[]" },
78
+ defaultValue: { summary: undefined }
79
+ }
80
+ },
81
+ handleSubmit: {
82
+ description: "Function called when Enter is pressed on any text input.",
83
+ control: { type: "object" },
84
+ table: {
85
+ type: { summary: "function" },
86
+ defaultValue: { summary: undefined }
87
+ }
88
+ }
89
+ },
90
+ decorators: [
91
+ Story => (
92
+ <Provider store={store}>
93
+ <Story />
94
+ </Provider>
95
+ )
96
+ ]
97
+ };
98
+
99
+ export const Basic = args => <ConnectedForm {...args} />;
100
+
101
+ export const WithWalletCheckbox = {
102
+ args: {
103
+ showWalletCheckbox: true
104
+ },
105
+ render: args => <ConnectedForm {...args} />
106
+ };
107
+
108
+ export const ShowErrors = {
109
+ args: {
110
+ showErrors: true
111
+ },
112
+ render: args => <ConnectedForm {...args} />
113
+ };
114
+
115
+ export const WithDeniedCards = {
116
+ args: {
117
+ deniedCards: ["AMEX"]
118
+ },
119
+ render: args => <ConnectedForm {...args} />
120
+ };