@aristobyte-ui/switch 2.4.0 → 2.5.1
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/es/src/main/components/Switch/Switch.scss +486 -0
- package/es/src/main/components/Switch/index.d.ts +33 -0
- package/es/src/main/components/Switch/index.d.ts.map +1 -0
- package/es/src/main/components/Switch/index.js +45 -0
- package/es/src/main/components/index.d.ts +2 -0
- package/es/src/main/components/index.d.ts.map +1 -0
- package/es/src/main/components/index.js +1 -1
- package/es/src/main/index.d.ts +2 -0
- package/es/src/main/index.d.ts.map +1 -0
- package/lib/src/main/components/Switch/Switch.scss +486 -0
- package/lib/src/main/components/Switch/index.d.ts +33 -0
- package/lib/src/main/components/Switch/index.d.ts.map +1 -0
- package/lib/src/main/components/{Switch.js → Switch/index.js} +9 -18
- package/lib/src/main/components/index.d.ts +2 -0
- package/lib/src/main/components/index.d.ts.map +1 -0
- package/lib/src/main/index.d.ts +2 -0
- package/lib/src/main/index.d.ts.map +1 -0
- package/package.json +7 -2
- package/es/src/main/components/Switch.js +0 -54
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
@use '@aristobyte-ui/utils/styles' as *;
|
|
2
|
+
|
|
3
|
+
.switch {
|
|
4
|
+
align-items: center;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
display: flex;
|
|
7
|
+
gap: 10px;
|
|
8
|
+
max-width: max-content;
|
|
9
|
+
user-select: none;
|
|
10
|
+
position: relative;
|
|
11
|
+
|
|
12
|
+
&-align-label {
|
|
13
|
+
&--horizontal {
|
|
14
|
+
flex-direction: row;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&--vertical {
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&--disabled {
|
|
23
|
+
opacity: 0.5;
|
|
24
|
+
cursor: not-allowed;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&-size {
|
|
28
|
+
&--xsm {
|
|
29
|
+
.switch {
|
|
30
|
+
&__track {
|
|
31
|
+
height: 1rem;
|
|
32
|
+
width: 1.8rem;
|
|
33
|
+
|
|
34
|
+
&-icon {
|
|
35
|
+
height: calc(0.8rem - 0.16rem * 2);
|
|
36
|
+
width: calc(0.8rem - 0.16rem * 2);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&__thumb {
|
|
41
|
+
border-radius: calc(0.8rem / 2);
|
|
42
|
+
height: 0.8rem;
|
|
43
|
+
left: 0.16rem;
|
|
44
|
+
width: 0.8rem;
|
|
45
|
+
|
|
46
|
+
&-icon {
|
|
47
|
+
height: 0.6rem;
|
|
48
|
+
width: 0.6rem;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&__label {
|
|
53
|
+
color: $white;
|
|
54
|
+
font-size: 0.625rem; // 10px
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
input {
|
|
59
|
+
+ .switch__track .switch__track-icon {
|
|
60
|
+
&--checked {
|
|
61
|
+
left: -2rem;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&--unchecked {
|
|
65
|
+
right: 0.18rem;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&:checked + .switch__track {
|
|
70
|
+
.switch__track-icon {
|
|
71
|
+
&--checked {
|
|
72
|
+
left: 0.18rem;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&--unchecked {
|
|
76
|
+
right: -2rem;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.switch__thumb {
|
|
81
|
+
transform: translate(calc(1.8rem - 0.8rem - 0.16rem * 2), -50%);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&:active {
|
|
86
|
+
+ .switch__track .switch__thumb {
|
|
87
|
+
width: 1rem;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
&:checked + .switch__track .switch__thumb {
|
|
91
|
+
transform: translate(calc(0.8rem / 2 + 0.08rem), -50%);
|
|
92
|
+
width: 1rem;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&--sm {
|
|
99
|
+
.switch {
|
|
100
|
+
&__track {
|
|
101
|
+
height: 1.4rem;
|
|
102
|
+
width: 2.6rem;
|
|
103
|
+
|
|
104
|
+
&-icon {
|
|
105
|
+
height: calc(1.2rem - 0.2rem * 2);
|
|
106
|
+
width: calc(1.2rem - 0.2rem * 2);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
&__thumb {
|
|
111
|
+
border-radius: calc(1rem / 2);
|
|
112
|
+
height: 1rem;
|
|
113
|
+
left: 0.2rem;
|
|
114
|
+
width: 1rem;
|
|
115
|
+
|
|
116
|
+
&-icon {
|
|
117
|
+
height: 0.8rem;
|
|
118
|
+
width: 0.8rem;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
&__label {
|
|
123
|
+
color: $white;
|
|
124
|
+
font-size: 0.75rem; // 12px
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
input {
|
|
129
|
+
+ .switch__track .switch__track-icon {
|
|
130
|
+
&--checked {
|
|
131
|
+
left: -2rem;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
&--unchecked {
|
|
135
|
+
right: 0.24rem;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
&:checked + .switch__track {
|
|
140
|
+
.switch__track-icon {
|
|
141
|
+
&--checked {
|
|
142
|
+
left: 0.24rem;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
&--unchecked {
|
|
146
|
+
right: -2rem;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.switch__thumb {
|
|
151
|
+
transform: translate(calc(2.6rem - 1rem - 0.2rem * 2), -50%);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
&:active {
|
|
156
|
+
+ .switch__track .switch__thumb {
|
|
157
|
+
width: 1.3rem;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&:checked + .switch__track .switch__thumb {
|
|
161
|
+
transform: translate(calc(1.3rem / 2 + 0.25rem), -50%);
|
|
162
|
+
width: 1.3rem;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&--md {
|
|
169
|
+
.switch {
|
|
170
|
+
&__track {
|
|
171
|
+
height: 1.6rem;
|
|
172
|
+
width: 3rem;
|
|
173
|
+
|
|
174
|
+
&-icon {
|
|
175
|
+
height: calc(1.4rem - 0.2rem * 2);
|
|
176
|
+
width: calc(1.4rem - 0.2rem * 2);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
&__thumb {
|
|
181
|
+
border-radius: calc(1.2rem / 2);
|
|
182
|
+
height: 1.2rem;
|
|
183
|
+
left: 0.2rem;
|
|
184
|
+
width: 1.2rem;
|
|
185
|
+
|
|
186
|
+
&-icon {
|
|
187
|
+
height: 0.9rem;
|
|
188
|
+
width: 0.9rem;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
&__label {
|
|
193
|
+
color: $white;
|
|
194
|
+
font-size: 0.875rem; // 14px
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
input {
|
|
199
|
+
+ .switch__track .switch__track-icon {
|
|
200
|
+
&--checked {
|
|
201
|
+
left: -2rem;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
&--unchecked {
|
|
205
|
+
right: 0.3rem;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
&:checked + .switch__track {
|
|
210
|
+
.switch__track-icon {
|
|
211
|
+
&--checked {
|
|
212
|
+
left: 0.3rem;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
&--unchecked {
|
|
216
|
+
right: -2rem;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.switch__thumb {
|
|
221
|
+
transform: translate(calc(3rem - 1.2rem - 0.2rem * 2), -50%);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
&:active {
|
|
225
|
+
+ .switch__track .switch__thumb {
|
|
226
|
+
width: 1.5rem;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
&:checked + .switch__track .switch__thumb {
|
|
230
|
+
transform: translate(calc(1.5rem / 2 + 0.3rem), -50%);
|
|
231
|
+
width: 1.5rem;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
&--lg {
|
|
238
|
+
.switch {
|
|
239
|
+
&__track {
|
|
240
|
+
height: 1.8rem;
|
|
241
|
+
width: 3.4rem;
|
|
242
|
+
|
|
243
|
+
&-icon {
|
|
244
|
+
height: calc(1.6rem - 0.3rem * 2);
|
|
245
|
+
width: calc(1.6rem - 0.3rem * 2);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
&__thumb {
|
|
250
|
+
border-radius: calc(1.4rem / 2);
|
|
251
|
+
height: 1.4rem;
|
|
252
|
+
left: 0.3rem;
|
|
253
|
+
width: 1.4rem;
|
|
254
|
+
|
|
255
|
+
&-icon {
|
|
256
|
+
height: 1rem;
|
|
257
|
+
width: 1rem;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
&__label {
|
|
262
|
+
color: $white;
|
|
263
|
+
font-size: 1rem; // 16px
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
input {
|
|
268
|
+
+ .switch__track .switch__track-icon {
|
|
269
|
+
&--checked {
|
|
270
|
+
left: -2rem;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
&--unchecked {
|
|
274
|
+
right: 0.34rem;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
&:checked + .switch__track {
|
|
279
|
+
.switch__track-icon {
|
|
280
|
+
&--checked {
|
|
281
|
+
left: 0.34rem;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
&--unchecked {
|
|
285
|
+
right: -2rem;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.switch__thumb {
|
|
290
|
+
transform: translate(calc(3.4rem - 1.4rem - 0.3rem * 2 + 0.05rem), -50%);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
&:active {
|
|
295
|
+
+ .switch__track .switch__thumb {
|
|
296
|
+
width: 1.8rem;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
&:checked + .switch__track .switch__thumb {
|
|
300
|
+
transform: translate(calc(1.8rem / 2 + 0.2rem - 0.05rem), -50%);
|
|
301
|
+
width: 1.8rem;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
&--xlg {
|
|
308
|
+
.switch {
|
|
309
|
+
&__track {
|
|
310
|
+
height: 2rem;
|
|
311
|
+
width: 3.8rem;
|
|
312
|
+
|
|
313
|
+
&-icon {
|
|
314
|
+
height: calc(1.8rem - 0.3rem * 2);
|
|
315
|
+
width: calc(1.8rem - 0.3rem * 2);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
&__thumb {
|
|
320
|
+
border-radius: calc(1.6rem / 2);
|
|
321
|
+
height: 1.6rem;
|
|
322
|
+
left: 0.3rem;
|
|
323
|
+
width: 1.6rem;
|
|
324
|
+
|
|
325
|
+
&-icon {
|
|
326
|
+
height: 1.2rem;
|
|
327
|
+
width: 1.2rem;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
&__label {
|
|
332
|
+
color: $white;
|
|
333
|
+
font-size: 1.125rem; // 18px
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
input {
|
|
338
|
+
+ .switch__track .switch__track-icon {
|
|
339
|
+
&--checked {
|
|
340
|
+
left: -2rem;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
&--unchecked {
|
|
344
|
+
right: 0.38rem;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
&:checked + .switch__track {
|
|
349
|
+
.switch__track-icon {
|
|
350
|
+
&--checked {
|
|
351
|
+
left: 0.38rem;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
&--unchecked {
|
|
355
|
+
right: -2rem;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.switch__thumb {
|
|
360
|
+
transform: translate(calc(3.8rem - 1.6rem - 0.3rem * 2), -50%);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
&:active {
|
|
365
|
+
+ .switch__track .switch__thumb {
|
|
366
|
+
width: 2rem;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
&:checked + .switch__track .switch__thumb {
|
|
370
|
+
transform: translate(calc(2rem / 2 + 0.22rem), -50%);
|
|
371
|
+
width: 2rem;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
&-variant--default input:checked + &__track {
|
|
379
|
+
background-color: $grey-500;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
&-variant--primary input:checked + &__track {
|
|
383
|
+
background-color: $color-primary;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
&-variant--secondary input:checked + &__track {
|
|
387
|
+
background-color: $color-secondary;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
&-variant--success input:checked + &__track {
|
|
391
|
+
background-color: $color-success;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
&-variant--error input:checked + &__track {
|
|
395
|
+
background-color: $color-error;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
&-variant--warning input:checked + &__track {
|
|
399
|
+
background-color: $color-warning;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
input {
|
|
403
|
+
display: none;
|
|
404
|
+
|
|
405
|
+
+ .switch__track .switch__track-icon {
|
|
406
|
+
&--checked {
|
|
407
|
+
opacity: 0;
|
|
408
|
+
transform: translate(0, -50%) scale(0.55);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
&--unchecked {
|
|
412
|
+
opacity: 1;
|
|
413
|
+
transform: translate(0, -50%) scale(1);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
&:checked {
|
|
418
|
+
+ .switch__track .switch__track-icon {
|
|
419
|
+
&--checked {
|
|
420
|
+
opacity: 1;
|
|
421
|
+
transform: translate(0, -50%) scale(1);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
&--unchecked {
|
|
425
|
+
opacity: 0;
|
|
426
|
+
transform: translate(0, -50%) scale(0.55);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
&__track {
|
|
433
|
+
position: relative;
|
|
434
|
+
background-color: $grey-700;
|
|
435
|
+
border-radius: 999px;
|
|
436
|
+
overflow: hidden;
|
|
437
|
+
position: relative;
|
|
438
|
+
transition: background-color 0.3s ease;
|
|
439
|
+
|
|
440
|
+
&-icon {
|
|
441
|
+
align-items: center;
|
|
442
|
+
display: flex;
|
|
443
|
+
justify-content: center;
|
|
444
|
+
position: absolute;
|
|
445
|
+
top: 50%;
|
|
446
|
+
transition:
|
|
447
|
+
transform 120ms ease-out,
|
|
448
|
+
left 200ms ease-out,
|
|
449
|
+
right 200ms ease-out,
|
|
450
|
+
opacity 100ms ease-out;
|
|
451
|
+
z-index: 0;
|
|
452
|
+
|
|
453
|
+
svg {
|
|
454
|
+
height: 100%;
|
|
455
|
+
width: 100%;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
&__thumb {
|
|
461
|
+
align-items: center;
|
|
462
|
+
background-color: white;
|
|
463
|
+
display: flex;
|
|
464
|
+
justify-content: center;
|
|
465
|
+
position: absolute;
|
|
466
|
+
top: 50%;
|
|
467
|
+
transform: translate(0, -50%);
|
|
468
|
+
transition: all 200ms ease-out;
|
|
469
|
+
z-index: 1;
|
|
470
|
+
|
|
471
|
+
&-icon {
|
|
472
|
+
align-items: center;
|
|
473
|
+
display: flex;
|
|
474
|
+
justify-content: center;
|
|
475
|
+
|
|
476
|
+
svg {
|
|
477
|
+
height: 100%;
|
|
478
|
+
width: 100%;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
&__label {
|
|
484
|
+
color: $white;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type IconPropsType } from '@aristobyte-ui/utils';
|
|
3
|
+
import './Switch.scss';
|
|
4
|
+
export interface ISwitch {
|
|
5
|
+
onChange?: () => void;
|
|
6
|
+
label?: string;
|
|
7
|
+
alignLabel?: 'horizontal' | 'vertical';
|
|
8
|
+
switchSize?: 'xsm' | 'sm' | 'md' | 'lg' | 'xlg';
|
|
9
|
+
variant?: 'default' | 'primary' | 'secondary' | 'success' | 'error' | 'warning';
|
|
10
|
+
trackIcon?: {
|
|
11
|
+
checked?: {
|
|
12
|
+
component: (props: IconPropsType) => React.JSX.Element;
|
|
13
|
+
size?: number;
|
|
14
|
+
color?: string;
|
|
15
|
+
};
|
|
16
|
+
unchecked?: {
|
|
17
|
+
component: (props: IconPropsType) => React.JSX.Element;
|
|
18
|
+
size?: number;
|
|
19
|
+
color?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
thumbIcon?: {
|
|
23
|
+
component: (props: IconPropsType) => React.JSX.Element;
|
|
24
|
+
size?: number;
|
|
25
|
+
color?: string;
|
|
26
|
+
};
|
|
27
|
+
checked?: boolean;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
className?: string;
|
|
30
|
+
style?: React.CSSProperties;
|
|
31
|
+
}
|
|
32
|
+
export declare const Switch: React.FC<ISwitch>;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/switch/src/main/components/Switch/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,eAAe,CAAC;AAEvB,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACvC,UAAU,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;IAChD,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAChF,SAAS,CAAC,EAAE;QACV,OAAO,CAAC,EAAE;YACR,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;YACvD,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;QACF,SAAS,CAAC,EAAE;YACV,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;YACvD,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;KACH,CAAC;IACF,SAAS,CAAC,EAAE;QACV,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;QACvD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAGD,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CA4DpC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
import './Switch.scss';
|
|
20
|
+
export var Switch = function (_a) {
|
|
21
|
+
var onChange = _a.onChange, label = _a.label, _b = _a.alignLabel, alignLabel = _b === void 0 ? 'vertical' : _b, checked = _a.checked, _c = _a.switchSize, switchSize = _c === void 0 ? 'md' : _c, _d = _a.variant, variant = _d === void 0 ? 'default' : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, trackIcon = _a.trackIcon, thumbIcon = _a.thumbIcon, _f = _a.className, className = _f === void 0 ? '' : _f, _g = _a.style, style = _g === void 0 ? {} : _g;
|
|
22
|
+
var id = React.useId();
|
|
23
|
+
var _h = __read(React.useState(!!checked), 2), isChecked = _h[0], setIsChecked = _h[1];
|
|
24
|
+
var handleChange = function () {
|
|
25
|
+
setIsChecked(function (prev) { return !prev; });
|
|
26
|
+
if (onChange)
|
|
27
|
+
onChange();
|
|
28
|
+
};
|
|
29
|
+
return (React.createElement("label", { htmlFor: id, className: "switch ".concat("switch-size--".concat(switchSize), " ").concat("switch-variant--".concat(variant), " ").concat("switch-align-label--".concat(alignLabel), " ").concat(disabled ? 'switch--disabled' : '', " ").concat(className), style: style },
|
|
30
|
+
React.createElement("input", { id: id, type: "checkbox", disabled: disabled, checked: isChecked, onChange: handleChange }),
|
|
31
|
+
React.createElement("span", { className: "switch__track" },
|
|
32
|
+
trackIcon && trackIcon.checked && (React.createElement("span", { className: "switch__track-icon ".concat('switch__track-icon--checked') }, trackIcon.checked.component({
|
|
33
|
+
size: trackIcon.checked.size,
|
|
34
|
+
color: trackIcon.checked.color,
|
|
35
|
+
}))),
|
|
36
|
+
React.createElement("span", { className: 'switch__thumb' }, thumbIcon && (React.createElement("span", { className: 'switch__thumb-icon' }, thumbIcon.component({
|
|
37
|
+
size: thumbIcon.size,
|
|
38
|
+
color: thumbIcon.color,
|
|
39
|
+
})))),
|
|
40
|
+
trackIcon && trackIcon.unchecked && (React.createElement("span", { className: "".concat('switch__track-icon', " ").concat('switch__track-icon--unchecked') }, trackIcon.unchecked.component({
|
|
41
|
+
size: trackIcon.unchecked.size,
|
|
42
|
+
color: trackIcon.unchecked.color,
|
|
43
|
+
})))),
|
|
44
|
+
label && React.createElement("span", { className: 'switch__label' }, label)));
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/switch/src/main/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './Switch';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/switch/src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
@use '@aristobyte-ui/utils/styles' as *;
|
|
2
|
+
|
|
3
|
+
.switch {
|
|
4
|
+
align-items: center;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
display: flex;
|
|
7
|
+
gap: 10px;
|
|
8
|
+
max-width: max-content;
|
|
9
|
+
user-select: none;
|
|
10
|
+
position: relative;
|
|
11
|
+
|
|
12
|
+
&-align-label {
|
|
13
|
+
&--horizontal {
|
|
14
|
+
flex-direction: row;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&--vertical {
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&--disabled {
|
|
23
|
+
opacity: 0.5;
|
|
24
|
+
cursor: not-allowed;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&-size {
|
|
28
|
+
&--xsm {
|
|
29
|
+
.switch {
|
|
30
|
+
&__track {
|
|
31
|
+
height: 1rem;
|
|
32
|
+
width: 1.8rem;
|
|
33
|
+
|
|
34
|
+
&-icon {
|
|
35
|
+
height: calc(0.8rem - 0.16rem * 2);
|
|
36
|
+
width: calc(0.8rem - 0.16rem * 2);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&__thumb {
|
|
41
|
+
border-radius: calc(0.8rem / 2);
|
|
42
|
+
height: 0.8rem;
|
|
43
|
+
left: 0.16rem;
|
|
44
|
+
width: 0.8rem;
|
|
45
|
+
|
|
46
|
+
&-icon {
|
|
47
|
+
height: 0.6rem;
|
|
48
|
+
width: 0.6rem;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&__label {
|
|
53
|
+
color: $white;
|
|
54
|
+
font-size: 0.625rem; // 10px
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
input {
|
|
59
|
+
+ .switch__track .switch__track-icon {
|
|
60
|
+
&--checked {
|
|
61
|
+
left: -2rem;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&--unchecked {
|
|
65
|
+
right: 0.18rem;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&:checked + .switch__track {
|
|
70
|
+
.switch__track-icon {
|
|
71
|
+
&--checked {
|
|
72
|
+
left: 0.18rem;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&--unchecked {
|
|
76
|
+
right: -2rem;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.switch__thumb {
|
|
81
|
+
transform: translate(calc(1.8rem - 0.8rem - 0.16rem * 2), -50%);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&:active {
|
|
86
|
+
+ .switch__track .switch__thumb {
|
|
87
|
+
width: 1rem;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
&:checked + .switch__track .switch__thumb {
|
|
91
|
+
transform: translate(calc(0.8rem / 2 + 0.08rem), -50%);
|
|
92
|
+
width: 1rem;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&--sm {
|
|
99
|
+
.switch {
|
|
100
|
+
&__track {
|
|
101
|
+
height: 1.4rem;
|
|
102
|
+
width: 2.6rem;
|
|
103
|
+
|
|
104
|
+
&-icon {
|
|
105
|
+
height: calc(1.2rem - 0.2rem * 2);
|
|
106
|
+
width: calc(1.2rem - 0.2rem * 2);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
&__thumb {
|
|
111
|
+
border-radius: calc(1rem / 2);
|
|
112
|
+
height: 1rem;
|
|
113
|
+
left: 0.2rem;
|
|
114
|
+
width: 1rem;
|
|
115
|
+
|
|
116
|
+
&-icon {
|
|
117
|
+
height: 0.8rem;
|
|
118
|
+
width: 0.8rem;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
&__label {
|
|
123
|
+
color: $white;
|
|
124
|
+
font-size: 0.75rem; // 12px
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
input {
|
|
129
|
+
+ .switch__track .switch__track-icon {
|
|
130
|
+
&--checked {
|
|
131
|
+
left: -2rem;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
&--unchecked {
|
|
135
|
+
right: 0.24rem;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
&:checked + .switch__track {
|
|
140
|
+
.switch__track-icon {
|
|
141
|
+
&--checked {
|
|
142
|
+
left: 0.24rem;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
&--unchecked {
|
|
146
|
+
right: -2rem;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.switch__thumb {
|
|
151
|
+
transform: translate(calc(2.6rem - 1rem - 0.2rem * 2), -50%);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
&:active {
|
|
156
|
+
+ .switch__track .switch__thumb {
|
|
157
|
+
width: 1.3rem;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&:checked + .switch__track .switch__thumb {
|
|
161
|
+
transform: translate(calc(1.3rem / 2 + 0.25rem), -50%);
|
|
162
|
+
width: 1.3rem;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&--md {
|
|
169
|
+
.switch {
|
|
170
|
+
&__track {
|
|
171
|
+
height: 1.6rem;
|
|
172
|
+
width: 3rem;
|
|
173
|
+
|
|
174
|
+
&-icon {
|
|
175
|
+
height: calc(1.4rem - 0.2rem * 2);
|
|
176
|
+
width: calc(1.4rem - 0.2rem * 2);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
&__thumb {
|
|
181
|
+
border-radius: calc(1.2rem / 2);
|
|
182
|
+
height: 1.2rem;
|
|
183
|
+
left: 0.2rem;
|
|
184
|
+
width: 1.2rem;
|
|
185
|
+
|
|
186
|
+
&-icon {
|
|
187
|
+
height: 0.9rem;
|
|
188
|
+
width: 0.9rem;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
&__label {
|
|
193
|
+
color: $white;
|
|
194
|
+
font-size: 0.875rem; // 14px
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
input {
|
|
199
|
+
+ .switch__track .switch__track-icon {
|
|
200
|
+
&--checked {
|
|
201
|
+
left: -2rem;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
&--unchecked {
|
|
205
|
+
right: 0.3rem;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
&:checked + .switch__track {
|
|
210
|
+
.switch__track-icon {
|
|
211
|
+
&--checked {
|
|
212
|
+
left: 0.3rem;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
&--unchecked {
|
|
216
|
+
right: -2rem;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.switch__thumb {
|
|
221
|
+
transform: translate(calc(3rem - 1.2rem - 0.2rem * 2), -50%);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
&:active {
|
|
225
|
+
+ .switch__track .switch__thumb {
|
|
226
|
+
width: 1.5rem;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
&:checked + .switch__track .switch__thumb {
|
|
230
|
+
transform: translate(calc(1.5rem / 2 + 0.3rem), -50%);
|
|
231
|
+
width: 1.5rem;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
&--lg {
|
|
238
|
+
.switch {
|
|
239
|
+
&__track {
|
|
240
|
+
height: 1.8rem;
|
|
241
|
+
width: 3.4rem;
|
|
242
|
+
|
|
243
|
+
&-icon {
|
|
244
|
+
height: calc(1.6rem - 0.3rem * 2);
|
|
245
|
+
width: calc(1.6rem - 0.3rem * 2);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
&__thumb {
|
|
250
|
+
border-radius: calc(1.4rem / 2);
|
|
251
|
+
height: 1.4rem;
|
|
252
|
+
left: 0.3rem;
|
|
253
|
+
width: 1.4rem;
|
|
254
|
+
|
|
255
|
+
&-icon {
|
|
256
|
+
height: 1rem;
|
|
257
|
+
width: 1rem;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
&__label {
|
|
262
|
+
color: $white;
|
|
263
|
+
font-size: 1rem; // 16px
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
input {
|
|
268
|
+
+ .switch__track .switch__track-icon {
|
|
269
|
+
&--checked {
|
|
270
|
+
left: -2rem;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
&--unchecked {
|
|
274
|
+
right: 0.34rem;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
&:checked + .switch__track {
|
|
279
|
+
.switch__track-icon {
|
|
280
|
+
&--checked {
|
|
281
|
+
left: 0.34rem;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
&--unchecked {
|
|
285
|
+
right: -2rem;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.switch__thumb {
|
|
290
|
+
transform: translate(calc(3.4rem - 1.4rem - 0.3rem * 2 + 0.05rem), -50%);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
&:active {
|
|
295
|
+
+ .switch__track .switch__thumb {
|
|
296
|
+
width: 1.8rem;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
&:checked + .switch__track .switch__thumb {
|
|
300
|
+
transform: translate(calc(1.8rem / 2 + 0.2rem - 0.05rem), -50%);
|
|
301
|
+
width: 1.8rem;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
&--xlg {
|
|
308
|
+
.switch {
|
|
309
|
+
&__track {
|
|
310
|
+
height: 2rem;
|
|
311
|
+
width: 3.8rem;
|
|
312
|
+
|
|
313
|
+
&-icon {
|
|
314
|
+
height: calc(1.8rem - 0.3rem * 2);
|
|
315
|
+
width: calc(1.8rem - 0.3rem * 2);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
&__thumb {
|
|
320
|
+
border-radius: calc(1.6rem / 2);
|
|
321
|
+
height: 1.6rem;
|
|
322
|
+
left: 0.3rem;
|
|
323
|
+
width: 1.6rem;
|
|
324
|
+
|
|
325
|
+
&-icon {
|
|
326
|
+
height: 1.2rem;
|
|
327
|
+
width: 1.2rem;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
&__label {
|
|
332
|
+
color: $white;
|
|
333
|
+
font-size: 1.125rem; // 18px
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
input {
|
|
338
|
+
+ .switch__track .switch__track-icon {
|
|
339
|
+
&--checked {
|
|
340
|
+
left: -2rem;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
&--unchecked {
|
|
344
|
+
right: 0.38rem;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
&:checked + .switch__track {
|
|
349
|
+
.switch__track-icon {
|
|
350
|
+
&--checked {
|
|
351
|
+
left: 0.38rem;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
&--unchecked {
|
|
355
|
+
right: -2rem;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.switch__thumb {
|
|
360
|
+
transform: translate(calc(3.8rem - 1.6rem - 0.3rem * 2), -50%);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
&:active {
|
|
365
|
+
+ .switch__track .switch__thumb {
|
|
366
|
+
width: 2rem;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
&:checked + .switch__track .switch__thumb {
|
|
370
|
+
transform: translate(calc(2rem / 2 + 0.22rem), -50%);
|
|
371
|
+
width: 2rem;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
&-variant--default input:checked + &__track {
|
|
379
|
+
background-color: $grey-500;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
&-variant--primary input:checked + &__track {
|
|
383
|
+
background-color: $color-primary;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
&-variant--secondary input:checked + &__track {
|
|
387
|
+
background-color: $color-secondary;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
&-variant--success input:checked + &__track {
|
|
391
|
+
background-color: $color-success;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
&-variant--error input:checked + &__track {
|
|
395
|
+
background-color: $color-error;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
&-variant--warning input:checked + &__track {
|
|
399
|
+
background-color: $color-warning;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
input {
|
|
403
|
+
display: none;
|
|
404
|
+
|
|
405
|
+
+ .switch__track .switch__track-icon {
|
|
406
|
+
&--checked {
|
|
407
|
+
opacity: 0;
|
|
408
|
+
transform: translate(0, -50%) scale(0.55);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
&--unchecked {
|
|
412
|
+
opacity: 1;
|
|
413
|
+
transform: translate(0, -50%) scale(1);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
&:checked {
|
|
418
|
+
+ .switch__track .switch__track-icon {
|
|
419
|
+
&--checked {
|
|
420
|
+
opacity: 1;
|
|
421
|
+
transform: translate(0, -50%) scale(1);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
&--unchecked {
|
|
425
|
+
opacity: 0;
|
|
426
|
+
transform: translate(0, -50%) scale(0.55);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
&__track {
|
|
433
|
+
position: relative;
|
|
434
|
+
background-color: $grey-700;
|
|
435
|
+
border-radius: 999px;
|
|
436
|
+
overflow: hidden;
|
|
437
|
+
position: relative;
|
|
438
|
+
transition: background-color 0.3s ease;
|
|
439
|
+
|
|
440
|
+
&-icon {
|
|
441
|
+
align-items: center;
|
|
442
|
+
display: flex;
|
|
443
|
+
justify-content: center;
|
|
444
|
+
position: absolute;
|
|
445
|
+
top: 50%;
|
|
446
|
+
transition:
|
|
447
|
+
transform 120ms ease-out,
|
|
448
|
+
left 200ms ease-out,
|
|
449
|
+
right 200ms ease-out,
|
|
450
|
+
opacity 100ms ease-out;
|
|
451
|
+
z-index: 0;
|
|
452
|
+
|
|
453
|
+
svg {
|
|
454
|
+
height: 100%;
|
|
455
|
+
width: 100%;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
&__thumb {
|
|
461
|
+
align-items: center;
|
|
462
|
+
background-color: white;
|
|
463
|
+
display: flex;
|
|
464
|
+
justify-content: center;
|
|
465
|
+
position: absolute;
|
|
466
|
+
top: 50%;
|
|
467
|
+
transform: translate(0, -50%);
|
|
468
|
+
transition: all 200ms ease-out;
|
|
469
|
+
z-index: 1;
|
|
470
|
+
|
|
471
|
+
&-icon {
|
|
472
|
+
align-items: center;
|
|
473
|
+
display: flex;
|
|
474
|
+
justify-content: center;
|
|
475
|
+
|
|
476
|
+
svg {
|
|
477
|
+
height: 100%;
|
|
478
|
+
width: 100%;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
&__label {
|
|
484
|
+
color: $white;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type IconPropsType } from '@aristobyte-ui/utils';
|
|
3
|
+
import './Switch.scss';
|
|
4
|
+
export interface ISwitch {
|
|
5
|
+
onChange?: () => void;
|
|
6
|
+
label?: string;
|
|
7
|
+
alignLabel?: 'horizontal' | 'vertical';
|
|
8
|
+
switchSize?: 'xsm' | 'sm' | 'md' | 'lg' | 'xlg';
|
|
9
|
+
variant?: 'default' | 'primary' | 'secondary' | 'success' | 'error' | 'warning';
|
|
10
|
+
trackIcon?: {
|
|
11
|
+
checked?: {
|
|
12
|
+
component: (props: IconPropsType) => React.JSX.Element;
|
|
13
|
+
size?: number;
|
|
14
|
+
color?: string;
|
|
15
|
+
};
|
|
16
|
+
unchecked?: {
|
|
17
|
+
component: (props: IconPropsType) => React.JSX.Element;
|
|
18
|
+
size?: number;
|
|
19
|
+
color?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
thumbIcon?: {
|
|
23
|
+
component: (props: IconPropsType) => React.JSX.Element;
|
|
24
|
+
size?: number;
|
|
25
|
+
color?: string;
|
|
26
|
+
};
|
|
27
|
+
checked?: boolean;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
className?: string;
|
|
30
|
+
style?: React.CSSProperties;
|
|
31
|
+
}
|
|
32
|
+
export declare const Switch: React.FC<ISwitch>;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/switch/src/main/components/Switch/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,eAAe,CAAC;AAEvB,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACvC,UAAU,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;IAChD,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAChF,SAAS,CAAC,EAAE;QACV,OAAO,CAAC,EAAE;YACR,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;YACvD,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;QACF,SAAS,CAAC,EAAE;YACV,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;YACvD,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;KACH,CAAC;IACF,SAAS,CAAC,EAAE;QACV,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;QACvD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAGD,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CA4DpC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
'use client';
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -52,8 +52,9 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.Switch = void 0;
|
|
54
54
|
var React = __importStar(require("react"));
|
|
55
|
+
require("./Switch.scss");
|
|
55
56
|
var Switch = function (_a) {
|
|
56
|
-
var onChange = _a.onChange, label = _a.label, _b = _a.alignLabel, alignLabel = _b === void 0 ?
|
|
57
|
+
var onChange = _a.onChange, label = _a.label, _b = _a.alignLabel, alignLabel = _b === void 0 ? 'vertical' : _b, checked = _a.checked, _c = _a.switchSize, switchSize = _c === void 0 ? 'md' : _c, _d = _a.variant, variant = _d === void 0 ? 'default' : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, trackIcon = _a.trackIcon, thumbIcon = _a.thumbIcon, _f = _a.className, className = _f === void 0 ? '' : _f, _g = _a.style, style = _g === void 0 ? {} : _g;
|
|
57
58
|
var id = React.useId();
|
|
58
59
|
var _h = __read(React.useState(!!checked), 2), isChecked = _h[0], setIsChecked = _h[1];
|
|
59
60
|
var handleChange = function () {
|
|
@@ -61,31 +62,21 @@ var Switch = function (_a) {
|
|
|
61
62
|
if (onChange)
|
|
62
63
|
onChange();
|
|
63
64
|
};
|
|
64
|
-
|
|
65
|
-
"switch",
|
|
66
|
-
"switch-size-".concat(switchSize),
|
|
67
|
-
"switch-variant-".concat(variant),
|
|
68
|
-
"switch-align-label-".concat(alignLabel),
|
|
69
|
-
disabled && "switch--disabled",
|
|
70
|
-
className,
|
|
71
|
-
]
|
|
72
|
-
.filter(Boolean)
|
|
73
|
-
.join(" ");
|
|
74
|
-
return (React.createElement("label", { htmlFor: id, className: baseClasses, style: style },
|
|
65
|
+
return (React.createElement("label", { htmlFor: id, className: "switch ".concat("switch-size--".concat(switchSize), " ").concat("switch-variant--".concat(variant), " ").concat("switch-align-label--".concat(alignLabel), " ").concat(disabled ? 'switch--disabled' : '', " ").concat(className), style: style },
|
|
75
66
|
React.createElement("input", { id: id, type: "checkbox", disabled: disabled, checked: isChecked, onChange: handleChange }),
|
|
76
|
-
React.createElement("span", { className: "switch__track
|
|
77
|
-
|
|
67
|
+
React.createElement("span", { className: "switch__track" },
|
|
68
|
+
trackIcon && trackIcon.checked && (React.createElement("span", { className: "switch__track-icon ".concat('switch__track-icon--checked') }, trackIcon.checked.component({
|
|
78
69
|
size: trackIcon.checked.size,
|
|
79
70
|
color: trackIcon.checked.color,
|
|
80
71
|
}))),
|
|
81
|
-
React.createElement("span", { className:
|
|
72
|
+
React.createElement("span", { className: 'switch__thumb' }, thumbIcon && (React.createElement("span", { className: 'switch__thumb-icon' }, thumbIcon.component({
|
|
82
73
|
size: thumbIcon.size,
|
|
83
74
|
color: thumbIcon.color,
|
|
84
75
|
})))),
|
|
85
|
-
|
|
76
|
+
trackIcon && trackIcon.unchecked && (React.createElement("span", { className: "".concat('switch__track-icon', " ").concat('switch__track-icon--unchecked') }, trackIcon.unchecked.component({
|
|
86
77
|
size: trackIcon.unchecked.size,
|
|
87
78
|
color: trackIcon.unchecked.color,
|
|
88
79
|
})))),
|
|
89
|
-
label && React.createElement("span", { className:
|
|
80
|
+
label && React.createElement("span", { className: 'switch__label' }, label)));
|
|
90
81
|
};
|
|
91
82
|
exports.Switch = Switch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/switch/src/main/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/switch/src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aristobyte-ui/switch",
|
|
3
3
|
"description": "A fully typed, customizable Switch/toggle component for React with multiple sizes, variants, label alignments, and optional icons. Built to integrate seamlessly with AristoByteUI design tokens and SCSS modules.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.5.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "AristoByte <info@aristobyte.com>",
|
|
@@ -41,8 +41,13 @@
|
|
|
41
41
|
},
|
|
42
42
|
"main": "lib/src/main/index.js",
|
|
43
43
|
"module": "es/src/main/index.js",
|
|
44
|
+
"types": "es/src/main/index.d.ts",
|
|
44
45
|
"peerDependencies": {
|
|
45
46
|
"react": "^19.1.0",
|
|
46
|
-
"react-dom": "^19.1.0"
|
|
47
|
+
"react-dom": "^19.1.0",
|
|
48
|
+
"sass": "^1.97.3"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@aristobyte-ui/utils": "2.5.1"
|
|
47
52
|
}
|
|
48
53
|
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
import * as React from "react";
|
|
19
|
-
export var Switch = function (_a) {
|
|
20
|
-
var onChange = _a.onChange, label = _a.label, _b = _a.alignLabel, alignLabel = _b === void 0 ? "vertical" : _b, checked = _a.checked, _c = _a.switchSize, switchSize = _c === void 0 ? "md" : _c, _d = _a.variant, variant = _d === void 0 ? "default" : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, trackIcon = _a.trackIcon, thumbIcon = _a.thumbIcon, _f = _a.className, className = _f === void 0 ? "" : _f, _g = _a.style, style = _g === void 0 ? {} : _g;
|
|
21
|
-
var id = React.useId();
|
|
22
|
-
var _h = __read(React.useState(!!checked), 2), isChecked = _h[0], setIsChecked = _h[1];
|
|
23
|
-
var handleChange = function () {
|
|
24
|
-
setIsChecked(function (prev) { return !prev; });
|
|
25
|
-
if (onChange)
|
|
26
|
-
onChange();
|
|
27
|
-
};
|
|
28
|
-
var baseClasses = [
|
|
29
|
-
"switch",
|
|
30
|
-
"switch-size-".concat(switchSize),
|
|
31
|
-
"switch-variant-".concat(variant),
|
|
32
|
-
"switch-align-label-".concat(alignLabel),
|
|
33
|
-
disabled && "switch--disabled",
|
|
34
|
-
className,
|
|
35
|
-
]
|
|
36
|
-
.filter(Boolean)
|
|
37
|
-
.join(" ");
|
|
38
|
-
return (React.createElement("label", { htmlFor: id, className: baseClasses, style: style },
|
|
39
|
-
React.createElement("input", { id: id, type: "checkbox", disabled: disabled, checked: isChecked, onChange: handleChange }),
|
|
40
|
-
React.createElement("span", { className: "switch__track relative rounded-full overflow-hidden transition-colors duration-300 ease-in-out" },
|
|
41
|
-
(trackIcon === null || trackIcon === void 0 ? void 0 : trackIcon.checked) && (React.createElement("span", { className: "switch__track-icon switch__track-icon--checked absolute top-1/2 flex items-center justify-center transition-all duration-200 ease-out z-0" }, trackIcon.checked.component({
|
|
42
|
-
size: trackIcon.checked.size,
|
|
43
|
-
color: trackIcon.checked.color,
|
|
44
|
-
}))),
|
|
45
|
-
React.createElement("span", { className: "switch__thumb absolute top-1/2 left-0 bg-white rounded-full transform -translate-y-1/2 transition-all duration-200 ease-out flex items-center justify-center z-10" }, thumbIcon && (React.createElement("span", { className: "switch__thumb-icon flex items-center justify-center" }, thumbIcon.component({
|
|
46
|
-
size: thumbIcon.size,
|
|
47
|
-
color: thumbIcon.color,
|
|
48
|
-
})))),
|
|
49
|
-
(trackIcon === null || trackIcon === void 0 ? void 0 : trackIcon.unchecked) && (React.createElement("span", { className: "switch__track-icon switch__track-icon--unchecked absolute top-1/2 flex items-center justify-center transition-all duration-200 ease-out z-0" }, trackIcon.unchecked.component({
|
|
50
|
-
size: trackIcon.unchecked.size,
|
|
51
|
-
color: trackIcon.unchecked.color,
|
|
52
|
-
})))),
|
|
53
|
-
label && React.createElement("span", { className: "switch__label ml-2" }, label)));
|
|
54
|
-
};
|