@thecb/components 11.1.16 → 11.2.0-beta.1

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": "11.1.16",
3
+ "version": "11.2.0-beta.1",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -28,7 +28,7 @@ const InactiveTitleModule = ({ title, subtitle, autoPayEnabled }) => (
28
28
  Unable to load account details
29
29
  </Detail>
30
30
  <Detail variant="extraSmall" as="p" color={BLACK}>
31
- {`This may mean that the account has been paid off or there was an error loading it. If you have questions about this account, please contact us.${
31
+ {`This may mean the balance has been paid and was removed from the system, or that there was an error loading it. .${
32
32
  autoPayEnabled
33
33
  ? " You may disable autopay for this account by pressing the 'Turn off Autopay' button."
34
34
  : ""
@@ -57,7 +57,7 @@ const RadioSection = ({
57
57
  containerStyles = "",
58
58
  ariaDescribedBy,
59
59
  isSectionRequired = false,
60
- groupedSections,
60
+ groupedSections = [],
61
61
  borderOverride,
62
62
  ...rest
63
63
  }) => {
@@ -67,32 +67,60 @@ const RadioSection = ({
67
67
  [...Array(sections.length)].map(() => createRef())
68
68
  );
69
69
 
70
- const handleKeyDown = (id, e, i) => {
71
- if (e.currentTarget !== e.target) {
70
+ // Flatten the groupedSections while keeping track of indices
71
+ const flattenedGroupedSections = groupedSections.flatMap(
72
+ (group, groupIndex) =>
73
+ group.map((section, sectionIndex) => ({
74
+ ...section,
75
+ groupIndex,
76
+ sectionIndex
77
+ }))
78
+ );
79
+ const groupedSectionsRefs = useRef(
80
+ [...Array(flattenedGroupedSections.length)].map(() => createRef())
81
+ );
82
+
83
+ const getFlatGroupIndex = (groupIndex, sectionIndex) =>
84
+ flattenedGroupedSections.findIndex(
85
+ item =>
86
+ item.groupIndex === groupIndex && item.sectionIndex === sectionIndex
87
+ );
88
+
89
+ const handleKeyDown = (e, sectionID, sectionIndex, isGroup) => {
90
+ const { currentTarget, target, keyCode } = e;
91
+ if (currentTarget !== target) {
72
92
  return;
73
93
  }
94
+ const refs = isGroup ? groupedSectionsRefs : sectionRefs;
95
+ const currSection = isGroup ? flattenedGroupedSections : sections;
74
96
 
75
97
  // Allow Enter and Space to select a section
76
- if (e.keyCode === ENTER || e.keyCode === SPACEBAR) {
98
+ if (keyCode === ENTER || keyCode === SPACEBAR) {
77
99
  e.preventDefault();
78
- toggleOpenSection(id);
100
+ toggleOpenSection(sectionID);
79
101
  }
80
102
 
81
103
  // Allow Up and Down arrow navigation between sections
82
104
  if (
83
- e.keyCode == ARROW_UP ||
84
- e.keyCode == ARROW_DOWN ||
85
- e.keyCode == ARROW_LEFT ||
86
- e.keyCode == ARROW_RIGHT
105
+ keyCode == ARROW_UP ||
106
+ keyCode == ARROW_DOWN ||
107
+ keyCode == ARROW_LEFT ||
108
+ keyCode == ARROW_RIGHT
87
109
  ) {
88
110
  e.preventDefault();
89
111
  const indexIncrement =
90
- e.keyCode == ARROW_RIGHT || e.keyCode == ARROW_DOWN ? 1 : -1;
91
- const nextIndex = wrapIndex(i + indexIncrement, sections.length);
92
-
93
- sectionRefs?.current[nextIndex]?.current?.focus();
94
- setFocused(sections[nextIndex]?.id);
95
- toggleOpenSection(sections[nextIndex]?.id);
112
+ keyCode == ARROW_RIGHT || keyCode == ARROW_DOWN ? 1 : -1;
113
+ const nextIndex = wrapIndex(
114
+ sectionIndex + indexIncrement,
115
+ currSection.length
116
+ );
117
+ const nextRef = refs?.current[nextIndex]?.current;
118
+ if (nextRef) {
119
+ nextRef.focus();
120
+ const nextRadioID = currSection[nextIndex]?.id;
121
+ setFocused(nextRadioID);
122
+ toggleOpenSection(nextRadioID);
123
+ }
96
124
  }
97
125
  };
98
126
 
@@ -123,7 +151,7 @@ const RadioSection = ({
123
151
  openSection={openSection}
124
152
  toggleOpenSection={toggleOpenSection}
125
153
  onKeyDown={e =>
126
- !section.disabled && handleKeyDown(section.id, e, i)
154
+ !section.disabled && handleKeyDown(e, section.id, i)
127
155
  }
128
156
  ariaLabelledBy={section.id}
129
157
  ariaDescribedBy={`right-icons-${idString(section)}`}
@@ -135,33 +163,48 @@ const RadioSection = ({
135
163
  groupedSections.map((sectionGroup, sectionGroupIndex) =>
136
164
  sectionGroup
137
165
  .filter(unfilteredSection => !unfilteredSection.hidden)
138
- .map((section, sectionIndex) => (
139
- <Fragment key={`key-${sectionGroupIndex}-${sectionIndex}`}>
140
- <InnerRadioSection
141
- themeValues={themeValues}
142
- sectionIndex={`${sectionGroupIndex}-${sectionIndex}`}
143
- section={section}
144
- sectionRefs={sectionRefs}
145
- focused={focused}
146
- setFocused={setFocused}
147
- openHeight={openHeight}
148
- ariaLabelledBy={section.id}
149
- ariaDescribedBy={`right-icons-${idString(section)}`}
150
- openSection={openSection}
151
- toggleOpenSection={toggleOpenSection}
152
- isLastGroupedItemInSection={
153
- sectionIndex === sectionGroup.length - 1
154
- }
155
- />
156
- {sectionIndex === sectionGroup.length - 1 &&
157
- sectionGroupIndex !== groupedSections.length - 1 && (
158
- <SolidDivider
159
- borderSize="1px"
160
- borderColor={MANATEE_GREY}
161
- />
162
- )}
163
- </Fragment>
164
- ))
166
+ .map((section, sectionIndex) => {
167
+ const flatGroupSectionIndex = getFlatGroupIndex(
168
+ sectionGroupIndex,
169
+ sectionIndex
170
+ );
171
+ return (
172
+ <Fragment key={`key-${sectionGroupIndex}-${sectionIndex}`}>
173
+ <InnerRadioSection
174
+ themeValues={themeValues}
175
+ sectionIndex={flatGroupSectionIndex}
176
+ section={section}
177
+ sectionRefs={groupedSectionsRefs}
178
+ focused={focused}
179
+ setFocused={setFocused}
180
+ openHeight={openHeight}
181
+ ariaLabelledBy={section.id}
182
+ ariaDescribedBy={`right-icons-${idString(section)}`}
183
+ openSection={openSection}
184
+ toggleOpenSection={toggleOpenSection}
185
+ onKeyDown={e =>
186
+ !section.disabled &&
187
+ handleKeyDown(
188
+ e,
189
+ section.id,
190
+ flatGroupSectionIndex,
191
+ true
192
+ )
193
+ }
194
+ isLastGroupedItemInSection={
195
+ sectionIndex === sectionGroup.length - 1
196
+ }
197
+ />
198
+ {sectionIndex === sectionGroup.length - 1 &&
199
+ sectionGroupIndex !== groupedSections.length - 1 && (
200
+ <SolidDivider
201
+ borderSize="1px"
202
+ borderColor={MANATEE_GREY}
203
+ />
204
+ )}
205
+ </Fragment>
206
+ );
207
+ })
165
208
  )}
166
209
  </Stack>
167
210
  </Box>
@@ -25,21 +25,25 @@ const RadioButton = ({
25
25
  const buttonBorder = {
26
26
  onFocused: {
27
27
  borderColor: themeValues.activeColor,
28
- outline: `3px solid ${themeValues.activeColor}`,
28
+ outlineWidth: "3px",
29
+ outlineColor: themeValues.activeColor,
29
30
  outlineOffset: "2px"
30
31
  },
31
32
  offFocused: {
32
33
  borderColor: themeValues.activeColor,
33
- outline: `3px solid ${themeValues.activeColor}`,
34
+ outlineWidth: "3px",
35
+ outlineColor: themeValues.activeColor,
34
36
  outlineOffset: "2px"
35
37
  },
36
38
  on: {
37
39
  borderColor: themeValues.activeColor,
38
- outline: "0"
40
+ outlineWidth: "0px",
41
+ outlineColor: "rgba(0, 0, 0, 0)"
39
42
  },
40
43
  off: {
41
44
  borderColor: themeValues.inactiveColor,
42
- outline: "0"
45
+ outlineWidth: "0px",
46
+ outlineColor: "rgba(0, 0, 0, 0)"
43
47
  }
44
48
  };
45
49
 
@@ -106,7 +110,7 @@ const RadioButton = ({
106
110
  width="24px"
107
111
  variants={buttonBorder}
108
112
  display="flex"
109
- extraStyles={`justify-content: center; align-items: center;`}
113
+ extraStyles={`outline: 0px solid rgba(0, 0, 0, 0); justify-content: center; align-items: center;`}
110
114
  >
111
115
  <Motion variants={buttonCenter} borderRadius="8px" />
112
116
  </Motion>