3
3
@import ' ../core/style/elevation' ;
4
4
@import ' ../core/a11y/a11y' ;
5
5
6
-
7
- $mat-slide-toggle-width : 36px !default ;
8
- $mat-slide-toggle-height : 24px !default ;
9
- $mat-slide-toggle-bar-height : 14px !default ;
10
6
$mat-slide-toggle-thumb-size : 20px !default ;
7
+ $mat-slide-toggle-bar-border-radius : 8px !default ;
8
+ $mat-slide-toggle-height : 24px !default ;
11
9
$mat-slide-toggle-margin : 16px !default ;
12
10
$mat-slide-toggle-spacing : 8px !default ;
13
11
$mat-slide-toggle-ripple-radius : 23px !default ;
12
+ $mat-slide-toggle-bar-width : 36px !default ;
13
+ $mat-slide-toggle-bar-height : 14px !default ;
14
+ $mat-slide-toggle-bar-track-width : $mat-slide-toggle-bar-width - $mat-slide-toggle-thumb-size ;
14
15
15
16
16
17
.mat-slide-toggle {
@@ -30,13 +31,12 @@ $mat-slide-toggle-ripple-radius: 23px !default;
30
31
31
32
& .mat-checked {
32
33
.mat-slide-toggle-thumb-container {
33
- transform : translate3d (100 % , 0 , 0 );
34
+ transform : translate3d ($mat-slide-toggle-bar-track-width , 0 , 0 );
34
35
}
35
36
}
36
37
37
38
& .mat-disabled {
38
-
39
- .mat-slide-toggle-label , .mat-slide-toggle-container {
39
+ .mat-slide-toggle-label , .mat-slide-toggle-thumb-container {
40
40
cursor : default ;
41
41
}
42
42
}
@@ -55,69 +55,63 @@ $mat-slide-toggle-ripple-radius: 23px !default;
55
55
.mat-slide-toggle-label {
56
56
display : flex ;
57
57
flex : 1 ;
58
+ flex-direction : row ;
59
+ align-items : center ;
58
60
59
61
cursor : pointer ;
60
62
}
61
63
62
64
/* If the label should be placed before the thumb then we just change the orders. */
63
65
.mat-slide-toggle-label-before {
64
66
.mat-slide-toggle-label { order : 1 ; }
65
- .mat-slide-toggle-container { order : 2 ; }
66
- }
67
-
68
- // Container for the composition of the slide-toggle / switch indicator.
69
- .mat-slide-toggle-container {
70
- cursor : grab ;
71
- width : $mat-slide-toggle-width ;
72
- height : $mat-slide-toggle-height ;
73
-
74
- position : relative ;
67
+ .mat-slide-toggle-bar { order : 2 ; }
75
68
}
76
69
77
- /* Apply the margin for slide-toggles and revert it for RTL toggles with labelPosition before. */
78
- [dir = ' rtl' ] .mat-slide-toggle-label-before .mat-slide-toggle-container , .mat-slide-toggle-container {
70
+ // Apply the margin for slide-toggles and revert it for RTL toggles with labelPosition before.
71
+ [dir = ' rtl' ] .mat-slide-toggle-label-before .mat-slide-toggle-bar ,
72
+ .mat-slide-toggle-bar {
79
73
margin-right : $mat-slide-toggle-spacing ;
80
74
margin-left : 0 ;
81
75
}
82
76
83
- /* Switch the margins in RTL mode and also switch it if the labelPosition is set to before. */
84
- [dir = ' rtl' ], .mat-slide-toggle-label-before {
85
- .mat-slide-toggle-container {
77
+ // Switch the margins in RTL mode and also switch it if the labelPosition is set to before.
78
+ [dir = ' rtl' ],
79
+ .mat-slide-toggle-label-before {
80
+ .mat-slide-toggle-bar {
86
81
margin-left : $mat-slide-toggle-spacing ;
87
82
margin-right : 0 ;
88
83
}
89
84
}
90
85
91
86
// The thumb container is responsible for the dragging functionality.
92
- // It moves around and holds the actual circle as a thumb .
87
+ // The container includes the visual thumb and the ripple container element .
93
88
.mat-slide-toggle-thumb-container {
89
+ $thumb-bar-vertical-padding : ($mat-slide-toggle-thumb-size - $mat-slide-toggle-bar-height ) / 2 ;
90
+
94
91
position : absolute ;
95
- top : $mat-slide-toggle-height / 2 - $mat-slide-toggle-thumb-size / 2 ;
96
- left : 0 ;
97
92
z-index : 1 ;
98
93
99
- width : $mat-slide-toggle-width - $mat-slide-toggle-thumb-size ;
94
+ width : $mat-slide-toggle-thumb-size ;
95
+ height : $mat-slide-toggle-thumb-size ;
96
+ top : - $thumb-bar-vertical-padding ;
97
+ left : 0 ;
100
98
101
99
transform : translate3d (0 , 0 , 0 );
102
-
103
100
transition : $swift-linear ;
104
101
transition-property : transform ;
105
102
103
+ cursor : grab ;
104
+
106
105
// Once the thumb container is being dragged around, we remove the transition duration to
107
106
// make the drag feeling fast and not delayed.
108
107
& .mat-dragging {
109
108
transition-duration : 0ms ;
110
109
}
111
110
}
112
111
113
- // The thumb will be elevated from the slide-toggle bar.
114
- // Also the thumb is bound to its parent thumb-container, which manages the movement of the thumb.
112
+ // The visual thumb element that moves inside of the thumb bar.
113
+ // The parent thumb-container container is responsible for the movement of the visual thumb.
115
114
.mat-slide-toggle-thumb {
116
- position : absolute ;
117
- margin : 0 ;
118
- left : 0 ;
119
- top : 0 ;
120
-
121
115
height : $mat-slide-toggle-thumb-size ;
122
116
width : $mat-slide-toggle-thumb-size ;
123
117
border-radius : 50% ;
@@ -131,16 +125,14 @@ $mat-slide-toggle-ripple-radius: 23px !default;
131
125
}
132
126
133
127
// Horizontal bar for the slide-toggle.
134
- // The slide-toggle bar is shown behind the thumb container .
128
+ // The slide-toggle bar is shown behind the movable thumb element .
135
129
.mat-slide-toggle-bar {
136
- position : absolute ;
137
- left : 1px ;
138
- top : $mat-slide-toggle-height / 2 - $mat-slide-toggle-bar-height / 2 ;
130
+ position : relative ;
139
131
140
- width : $mat-slide-toggle-width - 2 px ;
132
+ width : $mat-slide-toggle-bar-width ;
141
133
height : $mat-slide-toggle-bar-height ;
142
134
143
- border-radius : 8 px ;
135
+ border-radius : $mat-slide-toggle-bar-border-radius ;
144
136
145
137
@include cdk-high-contrast {
146
138
background : #fff ;
@@ -173,4 +165,4 @@ $mat-slide-toggle-ripple-radius: 23px !default;
173
165
border-radius : 50% ;
174
166
z-index : 1 ;
175
167
pointer-events : none ;
176
- }
168
+ }
0 commit comments