1+ @import " ../../core/style/variables" ;
2+ @import " ../../core/style/mixins" ;
3+ @import " ../../core/style/elevation" ;
4+
5+ // TODO(): remove the default theme.
6+ @import " ../../core/style/default-theme" ;
7+
8+ $md-slide-toggle-width : 36px !default ;
9+ $md-slide-toggle-height : 24px !default ;
10+ $md-slide-toggle-bar-height : 14px !default ;
11+ $md-slide-toggle-thumb-size : 20px !default ;
12+ $md-slide-toggle-margin : 16px !default ;
13+
14+ @mixin md-switch-checked ($palette ) {
15+ .md-slide-toggle-thumb {
16+ background-color : md-color ($palette );
17+ }
18+
19+ .md-slide-toggle-bar {
20+ background-color : md-color ($palette , 0.5 );
21+ }
22+ }
23+
24+ :host {
25+ display : flex ;
26+ height : $md-slide-toggle-height ;
27+
28+ margin : $md-slide-toggle-margin 0 ;
29+ line-height : $md-slide-toggle-height ;
30+
31+ white-space : nowrap ;
32+ user-select : none ;
33+
34+ outline : none ;
35+
36+ & .md-checked {
37+ @include md-switch-checked ($md-accent );
38+
39+ & .md-primary {
40+ @include md-switch-checked ($md-primary );
41+ }
42+
43+ & .md-warn {
44+ @include md-switch-checked ($md-warn );
45+ }
46+
47+ .md-slide-toggle-thumb-container {
48+ transform : translate3d (100% , 0 , 0 );
49+ }
50+ }
51+
52+ & .md-disabled {
53+
54+ .md-slide-toggle-label , .md-slide-toggle-container {
55+ cursor : default ;
56+ }
57+
58+ .md-slide-toggle-thumb {
59+ // The thumb of the slide-toggle always uses the hue 400 of the grey palette in dark or light themes.
60+ // Since this is very specific to the slide-toggle component, we're not providing
61+ // it in the background palette.
62+ background-color : md-color ($md-grey , 400 );
63+ }
64+ .md-slide-toggle-bar {
65+ background-color : md-color ($md-foreground , divider );
66+ }
67+ }
68+ }
69+
70+ // The label is our root container for the slide-toggle / switch indicator and label text.
71+ // It has to be a label, to support accessibility for the visual hidden input.
72+ .md-slide-toggle-label {
73+ display : flex ;
74+ flex : 1 ;
75+
76+ cursor : pointer ;
77+ }
78+
79+ // Container for the composition of the slide-toggle / switch indicator.
80+ .md-slide-toggle-container {
81+ cursor : grab ;
82+ width : $md-slide-toggle-width ;
83+ height : $md-slide-toggle-height ;
84+
85+ position : relative ;
86+ user-select : none ;
87+
88+ margin-right : 8px ;
89+ }
90+
91+ // The thumb container is responsible for the dragging functionality.
92+ // It moves around and holds the actual circle as a thumb.
93+ .md-slide-toggle-thumb-container {
94+ position : absolute ;
95+ top : $md-slide-toggle-height / 2 - $md-slide-toggle-thumb-size / 2 ;
96+ left : 0 ;
97+ z-index : 1 ;
98+
99+ width : $md-slide-toggle-width - $md-slide-toggle-thumb-size ;
100+
101+ transform : translate3d (0 , 0 , 0 );
102+
103+ transition : $swift-linear ;
104+ transition-property : transform ;
105+ }
106+
107+ // The thumb will be elevated from the slide-toggle bar.
108+ // Also the thumb is bound to its parent thumb-container, which manages the movement of the thumb.
109+ .md-slide-toggle-thumb {
110+ position : absolute ;
111+ margin : 0 ;
112+ left : 0 ;
113+ top : 0 ;
114+
115+ height : $md-slide-toggle-thumb-size ;
116+ width : $md-slide-toggle-thumb-size ;
117+ border-radius : 50% ;
118+
119+ background-color : md-color ($md-background , background );
120+ @include md-elevation (1 );
121+ }
122+
123+ // Horizontal bar for the slide-toggle.
124+ // The slide-toggle bar is shown behind the thumb container.
125+ .md-slide-toggle-bar {
126+ position : absolute ;
127+ left : 1px ;
128+ top : $md-slide-toggle-height / 2 - $md-slide-toggle-bar-height / 2 ;
129+
130+ width : $md-slide-toggle-width - 2px ;
131+ height : $md-slide-toggle-bar-height ;
132+
133+ // The bar of the slide-toggle always uses the hue 500 of the grey palette in dark or light themes.
134+ // Since this is very specific to the slide-toggle component, we're not providing
135+ // it in the background palette.
136+ background-color : md-color ($md-grey , 500 );
137+
138+ border-radius : 8px ;
139+ }
140+
141+ // The slide toggle shows a visually hidden checkbox inside of the component.
142+ // This checkbox allows us to take advantage of the browsers support.
143+ // Like accessibility and keyboard interaction.
144+ .md-slide-toggle-checkbox {
145+ @include md-visually-hidden ();
146+ }
147+
148+ .md-slide-toggle-bar ,
149+ .md-slide-toggle-thumb {
150+ transition : $swift-linear ;
151+ transition-property : background-color ;
152+ transition-delay : 0.05s ;
153+ }
0 commit comments