@thecb/components 11.1.16 → 11.2.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": "11.1.16",
3
+ "version": "11.2.0",
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,59 @@ 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
+ }
96
123
  }
97
124
  };
98
125
 
@@ -123,7 +150,7 @@ const RadioSection = ({
123
150
  openSection={openSection}
124
151
  toggleOpenSection={toggleOpenSection}
125
152
  onKeyDown={e =>
126
- !section.disabled && handleKeyDown(section.id, e, i)
153
+ !section.disabled && handleKeyDown(e, section.id, i)
127
154
  }
128
155
  ariaLabelledBy={section.id}
129
156
  ariaDescribedBy={`right-icons-${idString(section)}`}
@@ -135,33 +162,48 @@ const RadioSection = ({
135
162
  groupedSections.map((sectionGroup, sectionGroupIndex) =>
136
163
  sectionGroup
137
164
  .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
- ))
165
+ .map((section, sectionIndex) => {
166
+ const flatGroupSectionIndex = getFlatGroupIndex(
167
+ sectionGroupIndex,
168
+ sectionIndex
169
+ );
170
+ return (
171
+ <Fragment key={`key-${sectionGroupIndex}-${sectionIndex}`}>
172
+ <InnerRadioSection
173
+ themeValues={themeValues}
174
+ sectionIndex={flatGroupSectionIndex}
175
+ section={section}
176
+ sectionRefs={groupedSectionsRefs}
177
+ focused={focused}
178
+ setFocused={setFocused}
179
+ openHeight={openHeight}
180
+ ariaLabelledBy={section.id}
181
+ ariaDescribedBy={`right-icons-${idString(section)}`}
182
+ openSection={openSection}
183
+ toggleOpenSection={toggleOpenSection}
184
+ onKeyDown={e =>
185
+ !section.disabled &&
186
+ handleKeyDown(
187
+ e,
188
+ section.id,
189
+ flatGroupSectionIndex,
190
+ true
191
+ )
192
+ }
193
+ isLastGroupedItemInSection={
194
+ sectionIndex === sectionGroup.length - 1
195
+ }
196
+ />
197
+ {sectionIndex === sectionGroup.length - 1 &&
198
+ sectionGroupIndex !== groupedSections.length - 1 && (
199
+ <SolidDivider
200
+ borderSize="1px"
201
+ borderColor={MANATEE_GREY}
202
+ />
203
+ )}
204
+ </Fragment>
205
+ );
206
+ })
165
207
  )}
166
208
  </Stack>
167
209
  </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>