@thecb/components 10.7.6-beta.0 → 10.7.7

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": "10.7.6-beta.0",
3
+ "version": "10.7.7",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -120,6 +120,7 @@ const FormInput = ({
120
120
  ...props
121
121
  }) => {
122
122
  const [showPassword, setShowPassword] = useState(false);
123
+ const [isFocused, setIsFocused] = useState(false);
123
124
  const { isMobile } = useContext(ThemeContext);
124
125
 
125
126
  const setValue = value => {
@@ -134,6 +135,7 @@ const FormInput = ({
134
135
  if (isRequired && value === "") {
135
136
  setValue("");
136
137
  }
138
+ setIsFocused(false);
137
139
  };
138
140
 
139
141
  return (
@@ -226,6 +228,15 @@ const FormInput = ({
226
228
  data-qa={dataQa || labelTextWhenNoError}
227
229
  autoComplete={autocompleteValue}
228
230
  required={isRequired}
231
+ // Additional handler to detect autofilled values
232
+ {...(autocompleteValue && {
233
+ onFocus: e => {
234
+ if (!isFocused) {
235
+ setValue(e.target?.value);
236
+ setIsFocused(true);
237
+ }
238
+ }
239
+ })}
229
240
  {...props}
230
241
  />
231
242
  ) : (
@@ -3,7 +3,6 @@ import styled from "styled-components";
3
3
  import posed from "react-pose";
4
4
  import { fallbackValues } from "./ToggleSwitch.theme";
5
5
  import { themeComponent } from "../../../util/themeUtils";
6
- import Heading from "../heading";
7
6
  import { Box, Center, Cover, Cluster } from "../layouts";
8
7
  import { FONT_WEIGHT_SEMIBOLD } from "../../../constants/style_constants";
9
8
  import { CHARADE_GREY } from "../../../constants/colors";
@@ -12,16 +11,16 @@ import { noop } from "../../../util/general";
12
11
 
13
12
  const HiddenToggleSwitchBox = styled.input`
14
13
  opacity: 0;
14
+ margin: 0;
15
15
  position: absolute;
16
16
  cursor: ${({ disabled }) => (disabled ? "auto" : "pointer")};
17
- height: 24px;
18
- width: 50px;
19
- ${({ isMobile }) => (isMobile ? `transform: scale(0.75)` : ``)}
17
+ height: ${({ isMobile }) => (isMobile ? `22px` : `24px`)};
18
+ width: ${({ isMobile }) => (isMobile ? `40px` : `44px`)};
20
19
  `;
21
20
 
22
- const VisibleSwitchComponent = styled.label`
23
- width: 44px;
24
- height: 24px;
21
+ const VisibleSwitchComponent = styled.span`
22
+ width: ${({ isMobile }) => (isMobile ? `40px` : `44px`)};
23
+ height: ${({ isMobile }) => (isMobile ? `22px` : `24px`)};
25
24
  border-radius: 12px;
26
25
  border: none;
27
26
  position: relative;
@@ -37,30 +36,34 @@ const VisibleSwitchComponent = styled.label`
37
36
  &:focus {
38
37
  box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.5);
39
38
  }
40
-
41
- ${({ isMobile }) => (isMobile ? `transform: scale(0.75)` : ``)}
42
39
  `;
43
40
 
44
- const ToggleSwitchRingComponent = styled.div`
41
+ const ToggleSwitchRingComponent = styled.span`
45
42
  position: absolute;
46
- width: 16px;
47
- height: 16px;
43
+ width: ${({ isMobile }) => (isMobile ? `14px` : `16px`)};
44
+ height: ${({ isMobile }) => (isMobile ? `14px` : `16px`)};
48
45
  border: none;
49
46
  border-radius: 50%;
50
47
  box-sizing: border-box;
51
48
  `;
52
49
 
53
50
  const ToggleSwitch = ({
51
+ ariaDescribedBy = "",
54
52
  isOn = false,
55
53
  onToggle = noop,
56
54
  disabled = false,
57
- name = "",
55
+ name = "toggle",
58
56
  label = null,
59
57
  labelLeft = false,
58
+ labelStyles = "",
59
+ labelAs = "label",
60
60
  themeValues,
61
61
  isMobile,
62
- dataQa
62
+ dataQa,
63
+ minWidth = "80px",
64
+ extraStyles = ""
63
65
  }) => {
66
+ const nameId = name.replace(/ /g, "-");
64
67
  const ToggleSwitchRing = posed(ToggleSwitchRingComponent)({
65
68
  off: {
66
69
  backgroundColor: disabled
@@ -131,13 +134,21 @@ const ToggleSwitch = ({
131
134
 
132
135
  return (
133
136
  <Box
134
- padding="0"
135
- extraStyles={
136
- labelLeft ? themeValues.leftLabelStyles : themeValues.rightLabelStyles
137
- }
137
+ padding="0.5rem"
138
+ extraStyles={`
139
+ margin: 0 0.5rem;
140
+ ${
141
+ labelLeft ? themeValues.leftLabelStyles : themeValues.rightLabelStyles
142
+ }${extraStyles}`}
138
143
  >
139
144
  <Center>
140
- <Cluster justify="stretch" align="center" overflow="visible">
145
+ <Cluster
146
+ justify="space-between"
147
+ align="center"
148
+ overflow="visible"
149
+ childGap="0"
150
+ minWidth={minWidth ?? (isMobile ? "75px" : "84px")}
151
+ >
141
152
  <Cover minHeight="100%" singleChild>
142
153
  <Box
143
154
  minWidth="100%"
@@ -146,36 +157,48 @@ const ToggleSwitch = ({
146
157
  dataQa={dataQa}
147
158
  >
148
159
  <HiddenToggleSwitchBox
160
+ type="checkbox"
161
+ aria-checked={isOn}
149
162
  aria-label={name}
163
+ aria-labelledby={label ? `${nameId}-label` : null}
164
+ aria-describedby={ariaDescribedBy ? ariaDescribedBy : null}
150
165
  checked={isOn}
151
166
  onChange={disabled ? noop : onToggle}
152
167
  disabled={disabled}
153
- id={`#toggle-${name}`}
168
+ id={`#${nameId}`}
154
169
  isMobile={isMobile}
155
170
  />
156
171
  <VisibleSwitch
157
- name={name}
158
- htmlFor={`#toggle-${name}`}
159
172
  onClick={disabled ? noop : onToggle}
160
173
  onKeyDown={disabled ? noop : handleKeyDown}
161
174
  pose={isOn ? "on" : "off"}
162
175
  tabIndex={disabled ? -1 : 0}
163
176
  disabled={disabled}
164
177
  isMobile={isMobile}
178
+ tabindex="0"
165
179
  >
166
- <ToggleSwitchRing />
180
+ <ToggleSwitchRing isMobile={isMobile} />
167
181
  </VisibleSwitch>
168
182
  </Box>
169
183
  </Cover>
170
184
  {label && (
171
- <Heading
172
- variant={"h4"}
173
- weight={FONT_WEIGHT_SEMIBOLD}
174
- extraStyles={`margin: 0 0.5rem; position: relative; bottom: 1px; display: inline-block;`}
175
- color={CHARADE_GREY}
185
+ <Box
186
+ as={labelAs}
187
+ aria-label={`${name}: ${label}`}
188
+ extraStyles={`
189
+ font-weight: ${FONT_WEIGHT_SEMIBOLD};
190
+ color: ${CHARADE_GREY};
191
+ margin: 0 0 0 0.25rem;
192
+ position: relative;
193
+ bottom: 1px;
194
+ display: inline-block;
195
+ ${labelStyles}`}
196
+ id={`${nameId}-label`}
197
+ htmlFor={labelAs === "label" ? nameId : null}
198
+ padding="0"
176
199
  >
177
200
  {label}
178
- </Heading>
201
+ </Box>
179
202
  )}
180
203
  </Cluster>
181
204
  </Center>
@@ -134,6 +134,7 @@ const PaymentFormCard = ({
134
134
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
135
135
  isNum
136
136
  autocompleteValue="cc-number"
137
+ name="cc-number"
137
138
  isRequired={true}
138
139
  />
139
140
  <FormInputRow
Binary file