Skip to content

Commit ff2e89b

Browse files
feat(switch): implement component validation (#12761)
* feat(switch): implement component validation --------- Co-authored-by: Simeon Simeonoff <[email protected]>
1 parent 622faad commit ff2e89b

File tree

9 files changed

+564
-141
lines changed

9 files changed

+564
-141
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ All notable changes for each version of this project will be documented in this
3030
- **Behavioral Change** - When selected row is deleted from the grid component `rowSelectionChanging` event will no longer be emitted.
3131
- `IgxCarousel`
3232
- **Breaking Change** The `onSlideChanged`, `onSlideAdded`, `onSlideRemoved`, `onCarouselPaused` and `onCarouselPlaying` outputs have been renamed to `slideChanged`, `slideAdded`, `slideRemoved`, `carouselPaused` and `carouselPlaying` to not violate the no on-prefixed outputs convention. Automatic migrations are available and will be applied on `ng update`.
33-
- `IgxRadio`, `IgxRadioGroup`
33+
- `IgxRadio`, `IgxRadioGroup`, `IgxCheckbox`, `IgxSwitch`
3434
- Added component validation along with styles for invalid state
3535
- `igxMask` directive
3636
- Added the capability to escape mask pattern literals.

projects/igniteui-angular/src/lib/core/styles/components/switch/_switch-component.scss

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
@extend %switch-ripple--hover !optional;
1919
@extend %switch-ripple--hover-unchecked !optional;
2020
}
21+
22+
@include e(composite) {
23+
@extend %switch-composite--hover !optional;
24+
}
2125
}
2226

2327
&:active {
@@ -84,6 +88,10 @@
8488
@extend %switch-ripple--hover !optional;
8589
@extend %switch-ripple--hover-checked !optional;
8690
}
91+
92+
@include e(composite) {
93+
@extend %switch-composite--x--hover !optional;
94+
}
8795
}
8896

8997
&:active {
@@ -95,6 +103,39 @@
95103
}
96104
}
97105

106+
@include m(invalid) {
107+
@include e(composite) {
108+
@extend %switch-composite--invalid !optional;
109+
}
110+
111+
&:hover {
112+
@include e(ripple) {
113+
@extend %switch-ripple--hover !optional;
114+
@extend %switch-ripple--hover-invalid !optional;
115+
}
116+
117+
@include e(composite) {
118+
@extend %switch-composite--invalid--hover !optional;
119+
}
120+
}
121+
122+
&:active {
123+
@include e(ripple) {
124+
@extend %switch-ripple--hover !optional;
125+
@extend %switch-ripple--hover-invalid !optional;
126+
@extend %switch-ripple--pressed !optional;
127+
}
128+
}
129+
130+
@include e(label) {
131+
@extend %switch-label--invalid !optional;
132+
}
133+
134+
@include e(composite-thumb) {
135+
@extend %switch-composite-thumb--invalid !optional;
136+
}
137+
}
138+
98139
@include m(disabled) {
99140
@extend %switch-display--disabled !optional;
100141

@@ -121,5 +162,14 @@
121162
@extend %switch-ripple--focused-checked !optional;
122163
}
123164
}
165+
166+
@include mx(focused, invalid) {
167+
@include e(ripple) {
168+
@extend %switch-ripple--focused !optional;
169+
@extend %switch-ripple--focused-invalid !optional;
170+
}
171+
172+
@extend %igx-switch--focused--invalid !optional;
173+
}
124174
}
125175
}

projects/igniteui-angular/src/lib/core/styles/components/switch/_switch-theme.scss

Lines changed: 101 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
////
1515

1616
/// @param {Map} $schema [$light-schema] - The schema used as basis for styling the component.
17-
///
1817
/// @param {Color} $thumb-on-color [null] - The color of the thumb when the switch is on.
1918
/// @param {Color} $track-on-color [null] - The color of the track when the switch is on.
2019
/// @param {Color} $track-on-hover-color [null] - The color of the track when the switch is on and hovered.
@@ -29,7 +28,6 @@
2928
/// @param {box-shadow} $resting-shadow [null] - The shadow used for the thumb in resting state of the switch.
3029
/// @param {box-shadow} $hover-shadow [null] - The shadow used for the thumb in hover state of the switch.
3130
/// @param {box-shadow} $disabled-shadow [null] - The shadow used for the thumb in disable state of the switch.
32-
///
3331
/// @param {border-radius} $border-radius-track [null] - The border radius used for switch track.
3432
/// @param {border-radius} $border-radius-thumb [null] - The border radius used for switch thumb.
3533
/// @param {border-radius} $border-radius-ripple [null] - The border radius used for switch ripple.
@@ -41,11 +39,12 @@
4139
/// @param {Color} $focus-outline-color [null] - The focus outlined color.
4240
/// @param {Color} $focus-outline-color-focused [null] - The focus outlined color for focused state.
4341
/// @param {Color} $focus-fill-color [null] - The focus fill color.
44-
///
42+
/// @param {Color} $label-invalid-color [null] - The color of the switch label in invalid state.
43+
/// @param {Color} $track-error-color [null] - The color of the track in invalid state when the switch is off.
44+
/// @param {Color} $error-color [null] - The border and fill colors in invalid state.
45+
/// @param {Color} $error-color-hover [null] - The border and fill colors in invalid state on hover.
4546
/// @requires $light-schema
4647
///
47-
///
48-
///
4948
/// @example scss Set custom track and thumb on colors
5049
/// $my-switch-theme: switch-theme($thumb-on-color: black, $track-on-color: yellow);
5150
/// // Pass the theme to the css-vars() mixin
@@ -67,6 +66,7 @@
6766
6867
$label-color: null,
6968
$label-disabled-color: null,
69+
$label-invalid-color: null,
7070
7171
$resting-shadow: null,
7272
$hover-shadow: null,
@@ -82,7 +82,10 @@
8282
$border-on-hover-color: null,
8383
$focus-outline-color: null,
8484
$focus-outline-color-focused: null,
85-
$focus-fill-color: null
85+
$focus-fill-color: null,
86+
$track-error-color: null,
87+
$error-color: null,
88+
$error-color-hover: null,
8689
) {
8790
$name: 'igx-switch';
8891
$switch-schema: ();
@@ -139,6 +142,7 @@
139142

140143
label-color: $label-color,
141144
label-disabled-color: $label-disabled-color,
145+
label-invalid-color: $label-invalid-color,
142146

143147
resting-shadow: $resting-shadow,
144148
hover-shadow: $hover-shadow,
@@ -154,7 +158,10 @@
154158
border-on-hover-color: $border-on-hover-color,
155159
focus-outline-color: $focus-outline-color,
156160
focus-outline-color-focused: $focus-outline-color-focused,
157-
focus-fill-color: $focus-fill-color
161+
focus-fill-color: $focus-fill-color,
162+
track-error-color: $track-error-color,
163+
error-color: $error-color,
164+
error-color-hover: $error-color-hover,
158165
));
159166
}
160167

@@ -165,6 +172,7 @@
165172
@include css-vars($theme);
166173
@include scale-in-out($start-scale: .9);
167174

175+
$type: map.get($theme, type);
168176
$variant: map.get($theme, variant);
169177

170178
$switch-width: map.get((
@@ -232,7 +240,7 @@
232240

233241
$switch-thumb-height: $switch-thumb-width;
234242

235-
$ripple-size: rem(48px);
243+
$ripple-size: rem(40px);
236244
$ripple-radius: math.div($ripple-size, 2);
237245

238246
$label-margin: rem(8px);
@@ -276,39 +284,58 @@
276284
@if $variant == 'indigo-design' {
277285
border: rem(2px) solid var-get($theme, 'border-color');
278286
}
287+
}
279288

280-
@if $variant != 'bootstrap' {
281-
&:hover,
282-
&:focus {
283-
border-color: var-get($theme, 'border-hover-color');
289+
%switch-composite--hover {
290+
@if $variant == 'material' or $variant == 'fluent' {
291+
border-color: var-get($theme, 'border-hover-color');
292+
}
293+
294+
@if $variant == 'fluent' {
295+
%switch-composite-thumb {
296+
background: var-get($theme, 'border-hover-color');
297+
}
298+
299+
%switch-composite-thumb--x {
300+
background: var-get($theme, 'thumb-on-color');
284301
}
285302
}
303+
}
304+
305+
%switch-composite--invalid {
306+
border-color: var-get($theme, 'error-color');
307+
308+
@if $variant == 'material' {
309+
border-color: var-get($theme, 'track-error-color');
310+
background: var-get($theme, 'track-error-color');
311+
}
312+
}
286313

314+
%switch-composite--invalid--hover {
287315
@if $variant == 'fluent' {
288-
&:hover {
289-
%switch-composite-thumb {
290-
background: var-get($theme, 'border-hover-color');
291-
}
316+
border-color: var-get($theme, 'error-color-hover');
292317

293-
%switch-composite-thumb--x {
294-
background: var-get($theme, 'thumb-on-color');
295-
}
318+
%switch-composite-thumb {
319+
background: var-get($theme, 'error-color-hover');
296320
}
297321
}
298322
}
299323

300324
%switch-composite--x {
301325
background: var-get($theme, 'track-on-color');
302326
border-color: var-get($theme, 'border-on-color');
327+
}
303328

304-
&:hover,
305-
&:focus {
329+
%switch-composite--x--hover {
330+
@if $variant != 'bootstrap' {
306331
border-color: var-get($theme, 'border-on-hover-color');
307332
}
308333

309334
@if $variant == 'fluent' {
310-
&:hover {
311-
background: var-get($theme, 'track-on-hover-color');
335+
background: var-get($theme, 'track-on-hover-color');
336+
337+
%switch-composite-thumb {
338+
background: var-get($theme, 'thumb-on-color');
312339
}
313340
}
314341
}
@@ -350,6 +377,10 @@
350377
}
351378
}
352379

380+
%switch-composite-thumb--invalid {
381+
background: var-get($theme, 'error-color');
382+
}
383+
353384
%switch-composite-thumb--disabled {
354385
background: var-get($theme, 'thumb-disabled-color');
355386
box-shadow: $thumb-disabled-shadow;
@@ -392,7 +423,7 @@
392423
@if $variant == 'bootstrap' {
393424
%switch-composite {
394425
border-color: var-get($theme, 'focus-fill-color');
395-
box-shadow: 0 0 0 rem(4px) var-get($theme, 'focus-outline-color');
426+
box-shadow: 0 0 0 rem(2px) var-get($theme, 'focus-outline-color');
396427
}
397428

398429
%switch-composite-thumb {
@@ -408,6 +439,25 @@
408439
}
409440
}
410441

442+
%igx-switch--focused--invalid {
443+
@if $variant == 'bootstrap' {
444+
%switch-composite {
445+
border-color: var-get($theme, 'error-color');
446+
box-shadow: 0 0 0 rem(2px) var-get($theme, 'error-color-hover');
447+
}
448+
449+
%switch-composite-thumb {
450+
background: var-get($theme, 'error-color');
451+
}
452+
}
453+
454+
@if $variant == 'indigo-design' {
455+
%switch-composite {
456+
box-shadow: 0 0 0 rem(3px) var-get($theme, 'error-color-hover');
457+
}
458+
}
459+
}
460+
411461
%igx-switch--focused-checked {
412462
@if $variant == 'bootstrap' {
413463
%switch-composite {
@@ -448,12 +498,20 @@
448498
background: var-get($theme, 'track-off-color');
449499
transition: background .2s $ease-out-quad;
450500
opacity: .12;
501+
502+
@if $type == 'dark' {
503+
opacity: .24;
504+
}
451505
}
452506

453507
%switch-ripple--focused-checked {
454508
background: var-get($theme, 'thumb-on-color');
455509
}
456510

511+
%switch-ripple--focused-invalid {
512+
background: var-get($theme, 'error-color-hover');
513+
}
514+
457515
%switch-label {
458516
display: inline-block;
459517
color: var-get($theme, 'label-color');
@@ -486,12 +544,20 @@
486544
color: var-get($theme, 'label-disabled-color');
487545
}
488546

547+
%switch-label--invalid {
548+
color: var-get($theme, 'label-invalid-color');
549+
}
550+
489551
%switch-ripple--hover {
490552
&::after {
491553
position: absolute;
492554
content: '';
493555
opacity: .06;
494556
inset: 0;
557+
558+
@if $type == 'dark' {
559+
opacity: .12;
560+
}
495561
}
496562
}
497563

@@ -507,14 +573,24 @@
507573
}
508574
}
509575

576+
%switch-ripple--hover-invalid {
577+
&::after {
578+
background: var-get($theme, 'error-color-hover');
579+
}
580+
}
581+
510582
%switch-ripple--pressed {
511583
&::after {
512584
opacity: .12;
585+
586+
@if $type == 'dark' {
587+
opacity: .24;
588+
}
513589
}
514590
}
515591
}
516592

517-
/// Adds typography styles for the igx-checkbox component.
593+
/// Adds typography styles for the igx-switch component.
518594
/// Uses the 'subtitle-1' category from the typographic scale.
519595
/// @group typography
520596
/// @param {Map} $categories [(label: 'subtitle-1')] - The categories from the typographic scale used for type styles.

0 commit comments

Comments
 (0)