@hyphen/hyphen-components 4.13.0 → 5.1.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/dist/components/Formik/{FormikToggle/FormikToggle.d.ts → FormikSwitch/FormikSwitch.d.ts} +2 -2
- package/dist/components/Formik/FormikToggleGroup/FormikToggleGroup.d.ts +20 -0
- package/dist/components/Switch/Switch.d.ts +64 -0
- package/dist/components/Switch/Switch.stories.d.ts +12 -0
- package/dist/components/Toggle/Toggle.d.ts +7 -64
- package/dist/components/Toggle/Toggle.stories.d.ts +4 -5
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +19 -0
- package/dist/components/ToggleGroup/ToggleGroup.stories.d.ts +12 -0
- package/dist/css/index.css +3 -1
- package/dist/css/utilities.css +13 -1
- package/dist/css/variables.css +6 -2
- package/dist/hyphen-components.cjs.development.js +341 -239
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +1 -1
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +335 -239
- package/dist/hyphen-components.esm.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/lib/tokens.d.ts +1 -1
- package/package.json +18 -16
- package/src/components/Formik/Formik.stories.tsx +81 -2
- package/src/components/Formik/{FormikToggle/FormikToggle.test.tsx → FormikSwitch/FormikSwitch.test.tsx} +3 -3
- package/src/components/Formik/{FormikToggle/FormikToggle.tsx → FormikSwitch/FormikSwitch.tsx} +4 -4
- package/src/components/Formik/FormikToggleGroup/FormikToggleGroup.test.tsx +117 -0
- package/src/components/Formik/FormikToggleGroup/FormikToggleGroup.tsx +71 -0
- package/src/components/Switch/Switch.mdx +47 -0
- package/src/components/Switch/Switch.module.scss +294 -0
- package/src/components/Switch/Switch.stories.tsx +128 -0
- package/src/components/{Toggle/Toggle.test.tsx → Switch/Switch.test.tsx} +75 -75
- package/src/components/Switch/Switch.tsx +185 -0
- package/src/components/Toggle/Toggle.mdx +11 -31
- package/src/components/Toggle/Toggle.module.scss +28 -280
- package/src/components/Toggle/Toggle.stories.tsx +46 -111
- package/src/components/Toggle/Toggle.tsx +28 -180
- package/src/components/ToggleGroup/ToggleGroup.mdx +39 -0
- package/src/components/ToggleGroup/ToggleGroup.module.scss +42 -0
- package/src/components/ToggleGroup/ToggleGroup.stories.tsx +195 -0
- package/src/components/ToggleGroup/ToggleGroup.tsx +89 -0
- package/src/index.ts +4 -1
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
@import '@hyphen/hyphen-design-tokens/build/scss/variables';
|
|
2
|
+
|
|
3
|
+
@mixin thumb-size-sm {
|
|
4
|
+
width: calc(var(--size-spacing-2xl) - 4px);
|
|
5
|
+
height: calc(var(--size-spacing-2xl) - 4px);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
%thumb-size-sm {
|
|
9
|
+
@include thumb-size-sm;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.thumb-size-sm {
|
|
13
|
+
@extend %thumb-size-sm;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@mixin thumb-size-md {
|
|
17
|
+
width: calc(var(--size-spacing-3xl) - 4px);
|
|
18
|
+
height: calc(var(--size-spacing-3xl) - 4px);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
%thumb-size-md {
|
|
22
|
+
@include thumb-size-md;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.thumb-size-md {
|
|
26
|
+
@extend %thumb-size-md;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@mixin thumb-size-lg {
|
|
30
|
+
width: calc(var(--size-spacing-4xl) - 4px);
|
|
31
|
+
height: calc(var(--size-spacing-4xl) - 4px);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
%thumb-size-lg {
|
|
35
|
+
@include thumb-size-lg;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.thumb-size-lg {
|
|
39
|
+
@extend %thumb-size-lg;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@mixin track-size-sm {
|
|
43
|
+
min-width: 2rem;
|
|
44
|
+
width: 2rem;
|
|
45
|
+
height: var(--size-spacing-2xl);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
%track-size-sm {
|
|
49
|
+
@include track-size-sm;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.track-size-sm {
|
|
53
|
+
@extend %track-size-sm;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@mixin track-size-md {
|
|
57
|
+
min-width: 2.5rem;
|
|
58
|
+
width: 2.5rem;
|
|
59
|
+
height: var(--size-spacing-3xl);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
%track-size-md {
|
|
63
|
+
@include track-size-md;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.track-size-md {
|
|
67
|
+
@extend %track-size-md;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@mixin track-size-lg {
|
|
71
|
+
min-width: 3.5rem;
|
|
72
|
+
width: 3.5rem;
|
|
73
|
+
height: var(--size-spacing-4xl);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
%track-size-lg {
|
|
77
|
+
@include track-size-lg;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.track-size-lg {
|
|
81
|
+
@extend %track-size-lg;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@media (min-width: $size-breakpoint-tablet) {
|
|
85
|
+
.thumb-size-sm-tablet {
|
|
86
|
+
@include thumb-size-sm;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.thumb-size-md-tablet {
|
|
90
|
+
@include thumb-size-md;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.thumb-size-lg-tablet {
|
|
94
|
+
@include thumb-size-lg;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.track-size-sm-tablet {
|
|
98
|
+
@include track-size-sm;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.track-size-md-tablet {
|
|
102
|
+
@include track-size-md;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.track-size-lg-tablet {
|
|
106
|
+
@include track-size-lg;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@media (min-width: $size-breakpoint-desktop) {
|
|
111
|
+
.thumb-size-sm-desktop {
|
|
112
|
+
@include thumb-size-sm;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.thumb-size-md-desktop {
|
|
116
|
+
@include thumb-size-md;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.thumb-size-lg-desktop {
|
|
120
|
+
@include thumb-size-lg;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.track-size-sm-desktop {
|
|
124
|
+
@include track-size-sm;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.track-size-md-desktop {
|
|
128
|
+
@include track-size-md;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.track-size-lg-desktop {
|
|
132
|
+
@include track-size-lg;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@media (min-width: $size-breakpoint-hd) {
|
|
137
|
+
.thumb-size-sm-hd {
|
|
138
|
+
@include thumb-size-sm;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.thumb-size-md-hd {
|
|
142
|
+
@include thumb-size-md;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.thumb-size-lg-hd {
|
|
146
|
+
@include thumb-size-lg;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.track-size-sm-hd {
|
|
150
|
+
@include track-size-sm;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.track-size-md-hd {
|
|
154
|
+
@include track-size-md;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.track-size-lg-hd {
|
|
158
|
+
@include track-size-lg;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.disabled {
|
|
163
|
+
opacity: 0.4;
|
|
164
|
+
cursor: not-allowed;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.switch-thumb {
|
|
168
|
+
display: block;
|
|
169
|
+
transition: transform 0.25s ease;
|
|
170
|
+
border-radius: 50%;
|
|
171
|
+
box-shadow: 0 0 2px rgb(0 0 0 / 45%);
|
|
172
|
+
background-color: var(--color-base-white);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.switch-track {
|
|
176
|
+
display: block;
|
|
177
|
+
transition: background-color 0.25s ease;
|
|
178
|
+
border-radius: 9999em;
|
|
179
|
+
background-color: var(--switch-background-color, var(--color-base-grey-200));
|
|
180
|
+
cursor: pointer;
|
|
181
|
+
padding: 2px;
|
|
182
|
+
|
|
183
|
+
&.error {
|
|
184
|
+
background-color: var(
|
|
185
|
+
--switch-background-color-error,
|
|
186
|
+
var(--color-base-red-500)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//Hide the checkbox input (only needed for `:checked` property)
|
|
192
|
+
.switch-input {
|
|
193
|
+
position: absolute;
|
|
194
|
+
clip: rect(0, 0, 0, 0);
|
|
195
|
+
margin: -1px;
|
|
196
|
+
border: 0;
|
|
197
|
+
padding: 0;
|
|
198
|
+
width: 1px;
|
|
199
|
+
height: 1px;
|
|
200
|
+
overflow: hidden;
|
|
201
|
+
white-space: nowrap;
|
|
202
|
+
|
|
203
|
+
&:checked + .switch-track {
|
|
204
|
+
background-color: var(
|
|
205
|
+
--switch-background-color-checked,
|
|
206
|
+
var(--color-base-green-500)
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
&:checked + .switch-track.error {
|
|
211
|
+
background-color: var(
|
|
212
|
+
--switch-background-color-error,
|
|
213
|
+
var(--color-base-red-500)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
&:checked + .switch-track .switch-thumb.thumb-size-sm {
|
|
218
|
+
transform: translateX(0.75rem);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&:checked + .switch-track .switch-thumb.thumb-size-md {
|
|
222
|
+
transform: translateX(1rem);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
&:checked + .switch-track .switch-thumb.thumb-size-lg {
|
|
226
|
+
transform: translateX(1.5rem);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
@media (min-width: $size-breakpoint-tablet) {
|
|
230
|
+
&:checked + .switch-track .switch-thumb.thumb-size-sm-tablet {
|
|
231
|
+
transform: translateX(0.5rem);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
&:checked + .switch-track .switch-thumb.thumb-size-md-tablet {
|
|
235
|
+
transform: translateX(1rem);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
&:checked + .switch-track .switch-thumb.thumb-size-lg-tablet {
|
|
239
|
+
transform: translateX(1.5rem);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@media (min-width: $size-breakpoint-desktop) {
|
|
244
|
+
&:checked + .switch-track .switch-thumb.thumb-size-sm-desktop {
|
|
245
|
+
transform: translateX(0.5rem);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
&:checked + .switch-track .switch-thumb.thumb-size-md-desktop {
|
|
249
|
+
transform: translateX(1rem);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
&:checked + .switch-track .switch-thumb.thumb-size-lg-desktop {
|
|
253
|
+
transform: translateX(1.5rem);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@media (min-width: $size-breakpoint-hd) {
|
|
258
|
+
&:checked + .switch-track .switch-thumb.thumb-size-sm-hd {
|
|
259
|
+
transform: translateX(0.5rem);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
&:checked + .switch-track .switch-thumb.thumb-size-md-hd {
|
|
263
|
+
transform: translateX(1rem);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
&:checked + .switch-track .switch-thumb.thumb-size-lg-hd {
|
|
267
|
+
transform: translateX(1.5rem);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
&:focus + .switch-track {
|
|
272
|
+
outline: 0;
|
|
273
|
+
box-shadow: var(
|
|
274
|
+
--form-control-box-shadow-focus,
|
|
275
|
+
var(--INTERNAL_form-control-box-shadow-focus)
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Show focus styles on keyboard focus.
|
|
280
|
+
&:focus-visible + .switch-track {
|
|
281
|
+
outline: 0;
|
|
282
|
+
box-shadow: var(
|
|
283
|
+
--form-control-box-shadow-focus,
|
|
284
|
+
var(--INTERNAL_form-control-box-shadow-focus)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Hide focus styles if they are not needed, for example,
|
|
289
|
+
// when an element receives focus via the mouse.
|
|
290
|
+
&:focus:not(:focus-visible) + .switch-track {
|
|
291
|
+
outline: 0;
|
|
292
|
+
box-shadow: none;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Box } from '../Box/Box';
|
|
4
|
+
import type { Meta } from '@storybook/react';
|
|
5
|
+
import { Switch } from './Switch';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Switch> = {
|
|
8
|
+
title: 'Components/Switch',
|
|
9
|
+
component: Switch,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
|
|
14
|
+
export const Overview = () => (
|
|
15
|
+
<Switch id="example" label="Switch label" isChecked onChange={() => {}} />
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const Basic = () => {
|
|
19
|
+
const [value, setValue] = useState(false);
|
|
20
|
+
return (
|
|
21
|
+
<Switch
|
|
22
|
+
id="defaultStateIsUnchecked"
|
|
23
|
+
label="Switch label"
|
|
24
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
25
|
+
isChecked={value}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const HelpText = () => {
|
|
31
|
+
const [value, setValue] = useState(false);
|
|
32
|
+
return (
|
|
33
|
+
<Switch
|
|
34
|
+
id="helpText"
|
|
35
|
+
label="Switch label"
|
|
36
|
+
helpText="descriptive help text"
|
|
37
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
38
|
+
isChecked={value}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const HiddenLabel = () => {
|
|
44
|
+
const [value, setValue] = useState(false);
|
|
45
|
+
return (
|
|
46
|
+
<Switch
|
|
47
|
+
id="hiddenLabelSwitch"
|
|
48
|
+
label="Hidden Label"
|
|
49
|
+
helpText="hidden help text too"
|
|
50
|
+
hideLabel
|
|
51
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
52
|
+
isChecked={value}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const Sizes = () => {
|
|
58
|
+
const [value, setValue] = useState(true);
|
|
59
|
+
return (
|
|
60
|
+
<Box gap="md">
|
|
61
|
+
<Switch
|
|
62
|
+
id="smSwitch"
|
|
63
|
+
label="small Switch"
|
|
64
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
65
|
+
isChecked={value}
|
|
66
|
+
size="sm"
|
|
67
|
+
/>
|
|
68
|
+
<Switch
|
|
69
|
+
id="mediumSwitch"
|
|
70
|
+
label="medium Switch"
|
|
71
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
72
|
+
isChecked={value}
|
|
73
|
+
size="md"
|
|
74
|
+
/>
|
|
75
|
+
<Switch
|
|
76
|
+
id="largeSwitch"
|
|
77
|
+
label="large Switch"
|
|
78
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
79
|
+
isChecked={value}
|
|
80
|
+
size="lg"
|
|
81
|
+
/>
|
|
82
|
+
<Switch
|
|
83
|
+
id="responsiveSwitch"
|
|
84
|
+
label="responsive Switch"
|
|
85
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
86
|
+
isChecked={value}
|
|
87
|
+
size={{ base: 'sm', tablet: 'md', desktop: 'lg', hd: 'sm' }}
|
|
88
|
+
/>
|
|
89
|
+
</Box>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const Disabled = () => {
|
|
94
|
+
const [value, setValue] = useState(false);
|
|
95
|
+
return (
|
|
96
|
+
<Switch
|
|
97
|
+
id="disabledSwitch"
|
|
98
|
+
label="Label"
|
|
99
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
100
|
+
isChecked={value}
|
|
101
|
+
isDisabled
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const Error = () => {
|
|
107
|
+
const [value, setValue] = useState(false);
|
|
108
|
+
const [value2, setValue2] = useState(true);
|
|
109
|
+
return (
|
|
110
|
+
<Box gap="md">
|
|
111
|
+
<Switch
|
|
112
|
+
id="invalidSwitch"
|
|
113
|
+
label="Agree to Terms and Conditions"
|
|
114
|
+
isChecked={value}
|
|
115
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
116
|
+
isRequired
|
|
117
|
+
error="You must accept the Terms and Conditions"
|
|
118
|
+
/>
|
|
119
|
+
<Switch
|
|
120
|
+
id="invalidSwitch2"
|
|
121
|
+
label="Roof Replacement"
|
|
122
|
+
isChecked={value2}
|
|
123
|
+
onChange={(event) => setValue2(event.target.checked)}
|
|
124
|
+
error="Site Improvements can not be present with PPA"
|
|
125
|
+
/>
|
|
126
|
+
</Box>
|
|
127
|
+
);
|
|
128
|
+
};
|