@thecb/components 10.7.5 → 10.7.6
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/dist/index.cjs.js +55 -74
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +55 -74
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/form-layouts/FormInput.js +11 -0
- package/src/components/atoms/toggle-switch/ToggleSwitch.js +29 -57
- package/src/components/molecules/payment-form-card/PaymentFormCard.js +1 -0
package/package.json
CHANGED
|
@@ -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,27 +3,25 @@ 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";
|
|
6
7
|
import { Box, Center, Cover, Cluster } from "../layouts";
|
|
7
|
-
import {
|
|
8
|
-
FONT_WEIGHT_SEMIBOLD,
|
|
9
|
-
SCREEN_READER_ONLY
|
|
10
|
-
} from "../../../constants/style_constants";
|
|
8
|
+
import { FONT_WEIGHT_SEMIBOLD } from "../../../constants/style_constants";
|
|
11
9
|
import { CHARADE_GREY } from "../../../constants/colors";
|
|
12
10
|
import { ENTER } from "../../../constants/keyboard";
|
|
13
11
|
import { noop } from "../../../util/general";
|
|
14
12
|
|
|
15
13
|
const HiddenToggleSwitchBox = styled.input`
|
|
16
14
|
opacity: 0;
|
|
17
|
-
margin: 0;
|
|
18
15
|
position: absolute;
|
|
19
16
|
cursor: ${({ disabled }) => (disabled ? "auto" : "pointer")};
|
|
20
|
-
height:
|
|
21
|
-
width:
|
|
17
|
+
height: 24px;
|
|
18
|
+
width: 50px;
|
|
19
|
+
${({ isMobile }) => (isMobile ? `transform: scale(0.75)` : ``)}
|
|
22
20
|
`;
|
|
23
21
|
|
|
24
|
-
const VisibleSwitchComponent = styled.
|
|
25
|
-
width:
|
|
26
|
-
height:
|
|
22
|
+
const VisibleSwitchComponent = styled.label`
|
|
23
|
+
width: 44px;
|
|
24
|
+
height: 24px;
|
|
27
25
|
border-radius: 12px;
|
|
28
26
|
border: none;
|
|
29
27
|
position: relative;
|
|
@@ -39,35 +37,30 @@ const VisibleSwitchComponent = styled.span`
|
|
|
39
37
|
&:focus {
|
|
40
38
|
box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.5);
|
|
41
39
|
}
|
|
40
|
+
|
|
41
|
+
${({ isMobile }) => (isMobile ? `transform: scale(0.75)` : ``)}
|
|
42
42
|
`;
|
|
43
43
|
|
|
44
|
-
const ToggleSwitchRingComponent = styled.
|
|
44
|
+
const ToggleSwitchRingComponent = styled.div`
|
|
45
45
|
position: absolute;
|
|
46
|
-
width:
|
|
47
|
-
height:
|
|
46
|
+
width: 16px;
|
|
47
|
+
height: 16px;
|
|
48
48
|
border: none;
|
|
49
49
|
border-radius: 50%;
|
|
50
50
|
box-sizing: border-box;
|
|
51
51
|
`;
|
|
52
52
|
|
|
53
53
|
const ToggleSwitch = ({
|
|
54
|
-
ariaDescribedBy = "",
|
|
55
54
|
isOn = false,
|
|
56
55
|
onToggle = noop,
|
|
57
56
|
disabled = false,
|
|
58
|
-
name = "
|
|
57
|
+
name = "",
|
|
59
58
|
label = null,
|
|
60
59
|
labelLeft = false,
|
|
61
|
-
labelStyles = "",
|
|
62
|
-
labelAs = "h4",
|
|
63
|
-
srOnlyLabel = "",
|
|
64
60
|
themeValues,
|
|
65
61
|
isMobile,
|
|
66
|
-
dataQa
|
|
67
|
-
minWidth = "80px",
|
|
68
|
-
extraStyles = ""
|
|
62
|
+
dataQa
|
|
69
63
|
}) => {
|
|
70
|
-
const nameId = name.replace(/ /g, "-");
|
|
71
64
|
const ToggleSwitchRing = posed(ToggleSwitchRingComponent)({
|
|
72
65
|
off: {
|
|
73
66
|
backgroundColor: disabled
|
|
@@ -139,20 +132,12 @@ const ToggleSwitch = ({
|
|
|
139
132
|
return (
|
|
140
133
|
<Box
|
|
141
134
|
padding="0"
|
|
142
|
-
extraStyles={
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
labelLeft ? themeValues.leftLabelStyles : themeValues.rightLabelStyles
|
|
146
|
-
}${extraStyles}`}
|
|
135
|
+
extraStyles={
|
|
136
|
+
labelLeft ? themeValues.leftLabelStyles : themeValues.rightLabelStyles
|
|
137
|
+
}
|
|
147
138
|
>
|
|
148
139
|
<Center>
|
|
149
|
-
<Cluster
|
|
150
|
-
justify="space-between"
|
|
151
|
-
align="center"
|
|
152
|
-
overflow="visible"
|
|
153
|
-
childGap="0"
|
|
154
|
-
minWidth={minWidth ?? (isMobile ? "75px" : "84px")}
|
|
155
|
-
>
|
|
140
|
+
<Cluster justify="stretch" align="center" overflow="visible">
|
|
156
141
|
<Cover minHeight="100%" singleChild>
|
|
157
142
|
<Box
|
|
158
143
|
minWidth="100%"
|
|
@@ -161,18 +146,16 @@ const ToggleSwitch = ({
|
|
|
161
146
|
dataQa={dataQa}
|
|
162
147
|
>
|
|
163
148
|
<HiddenToggleSwitchBox
|
|
164
|
-
type="checkbox"
|
|
165
|
-
aria-checked={isOn}
|
|
166
149
|
aria-label={name}
|
|
167
|
-
aria-labelledby={label ? `${nameId}-label` : null}
|
|
168
|
-
aria-describedby={ariaDescribedBy ? ariaDescribedBy : null}
|
|
169
150
|
checked={isOn}
|
|
170
151
|
onChange={disabled ? noop : onToggle}
|
|
171
152
|
disabled={disabled}
|
|
172
|
-
id={
|
|
153
|
+
id={`#toggle-${name}`}
|
|
173
154
|
isMobile={isMobile}
|
|
174
155
|
/>
|
|
175
156
|
<VisibleSwitch
|
|
157
|
+
name={name}
|
|
158
|
+
htmlFor={`#toggle-${name}`}
|
|
176
159
|
onClick={disabled ? noop : onToggle}
|
|
177
160
|
onKeyDown={disabled ? noop : handleKeyDown}
|
|
178
161
|
pose={isOn ? "on" : "off"}
|
|
@@ -180,30 +163,19 @@ const ToggleSwitch = ({
|
|
|
180
163
|
disabled={disabled}
|
|
181
164
|
isMobile={isMobile}
|
|
182
165
|
>
|
|
183
|
-
<ToggleSwitchRing
|
|
166
|
+
<ToggleSwitchRing />
|
|
184
167
|
</VisibleSwitch>
|
|
185
168
|
</Box>
|
|
186
169
|
</Cover>
|
|
187
170
|
{label && (
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
margin: 0 0 0 0.25rem;
|
|
194
|
-
position: relative;
|
|
195
|
-
bottom: 1px;
|
|
196
|
-
display: inline-block;
|
|
197
|
-
${labelStyles}`}
|
|
198
|
-
id={`${nameId}-label`}
|
|
199
|
-
htmlFor={labelAs === "label" ? nameId : null}
|
|
200
|
-
padding="0"
|
|
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}
|
|
201
176
|
>
|
|
202
|
-
{srOnlyLabel && (
|
|
203
|
-
<span style={SCREEN_READER_ONLY}>{srOnlyLabel}</span>
|
|
204
|
-
)}
|
|
205
177
|
{label}
|
|
206
|
-
</
|
|
178
|
+
</Heading>
|
|
207
179
|
)}
|
|
208
180
|
</Cluster>
|
|
209
181
|
</Center>
|