@thecb/components 10.7.6 → 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/dist/index.cjs.js +72 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +72 -40
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/toggle-switch/ToggleSwitch.js +52 -29
package/package.json
CHANGED
|
@@ -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:
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
|
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={
|
|
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
|
-
<
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
extraStyles={`
|
|
175
|
-
|
|
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
|
-
</
|
|
201
|
+
</Box>
|
|
179
202
|
)}
|
|
180
203
|
</Cluster>
|
|
181
204
|
</Center>
|