UNPKG

9.71 kBSCSSView Raw
1//
2// Copyright 2020 Google Inc.
3//
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20// THE SOFTWARE.
21//
22
23// stylelint-disable selector-class-pattern --
24// Selector '.mdc-*' should only be used in this project.
25
26@use '@material/feature-targeting/feature-targeting';
27@use '@material/ripple/ripple-theme';
28@use '@material/theme/state';
29@use '@material/theme/theme';
30
31/// Default color for slider (track, thumb, ripple).
32$color: primary;
33$disabled-color: on-surface;
34
35// Thumb variables.
36$value-indicator-color: #000;
37$value-indicator-opacity: 0.6;
38$value-indicator-text-color: on-primary;
39
40// Track variables.
41$track-inactive-opacity: 0.24;
42$tick-mark-active-color: on-primary;
43$tick-mark-inactive-color: primary;
44$tick-mark-opacity: 0.6;
45
46/// Customizes active track color, using a Color or state Map.
47/// - To set only the default color, provide a single Color.
48/// - To set one or more state colors, provide a state Map with optional keys.
49/// - Supported state Map keys: `default`, `disabled`.
50///
51/// @example
52/// @include track-active-color(blue);
53/// @include track-active-color((disabled: gray));
54///
55/// @param {Color | Map} $color-or-map - The label's color or a state Map
56@mixin track-active-color($color-or-map, $query: feature-targeting.all()) {
57 @include _set-track-active-color(
58 state.get-default-state($color-or-map),
59 $query
60 );
61
62 $_disabled-color: state.get-disabled-state($color-or-map);
63 @if $_disabled-color {
64 &.mdc-slider--disabled {
65 @include _set-track-active-color($_disabled-color, $query);
66 }
67 }
68}
69
70@mixin _set-track-active-color($color, $query) {
71 $feat-color: feature-targeting.create-target($query, color);
72
73 .mdc-slider__track--active_fill {
74 @include feature-targeting.targets($feat-color) {
75 @include theme.property(border-color, $color);
76 }
77 }
78}
79
80/// Customizes inactive track color, using a Color or state Map.
81/// - To set only the default color, provide a single Color.
82/// - To set one or more state colors, provide a state Map with optional keys.
83/// - Supported state Map keys: `default`, `disabled`.
84///
85/// @example
86/// @include track-inactive-color(blue);
87/// @include track-inactive-color((disabled: gray));
88///
89/// @param {Color | Map} $color-or-map - The label's color or a state Map
90@mixin track-inactive-color(
91 $color-or-map,
92 $opacity: $track-inactive-opacity,
93 $query: feature-targeting.all()
94) {
95 @include _set-track-inactive-color(
96 state.get-default-state($color-or-map),
97 $opacity,
98 $query
99 );
100
101 $_disabled-color: state.get-disabled-state($color-or-map);
102 @if $_disabled-color {
103 &.mdc-slider--disabled {
104 @include _set-track-inactive-color($_disabled-color, $opacity, $query);
105 }
106 }
107}
108
109@mixin _set-track-inactive-color($color, $opacity, $query) {
110 $feat-color: feature-targeting.create-target($query, color);
111
112 .mdc-slider__track--inactive {
113 @include feature-targeting.targets($feat-color) {
114 @include theme.property(background-color, $color);
115
116 opacity: $opacity;
117 }
118 }
119}
120
121/// Customizes thumb color, using a Color or state Map.
122/// - To set only the default color, provide a single Color.
123/// - To set one or more state colors, provide a state Map with optional keys.
124/// - Supported state Map keys: `default`, `disabled`.
125///
126/// @example
127/// @include thumb-color(blue);
128/// @include thumb-color((disabled: gray));
129///
130/// @param {Color | Map} $color-or-map - The label's color or a state Map
131@mixin thumb-color($color-or-map, $query: feature-targeting.all()) {
132 @include _set-thumb-color(state.get-default-state($color-or-map), $query);
133
134 $_disabled-color: state.get-disabled-state($color-or-map);
135 @if $_disabled-color {
136 &.mdc-slider--disabled {
137 @include _set-thumb-color($_disabled-color, $query);
138 }
139 }
140}
141
142@mixin _set-thumb-color($color, $query) {
143 $feat-color: feature-targeting.create-target($query, color);
144
145 @include feature-targeting.targets($feat-color) {
146 .mdc-slider__thumb-knob {
147 @include theme.property(background-color, $color);
148 @include theme.property(border-color, $color);
149 }
150
151 .mdc-slider__thumb--top {
152 .mdc-slider__thumb-knob,
153 &.mdc-slider__thumb:hover .mdc-slider__thumb-knob,
154 &.mdc-slider__thumb--focused .mdc-slider__thumb-knob {
155 border-color: #fff;
156 }
157 }
158 }
159}
160
161///
162/// Customizes thumb ripple color.
163/// @param {Color | String} $color Either a valid color value or a key from
164/// `$theme-variables.property-values`.
165///
166@mixin thumb-ripple-color($color, $query: feature-targeting.all()) {
167 .mdc-slider__thumb {
168 @include ripple-theme.states($color: $color, $query: $query);
169 }
170}
171
172/// Customizes thumb color when thumb is activated (hover, focused, or pressed
173/// state).
174///
175/// @param {Color} $color - The thumb's color
176@mixin thumb-activated-color($color, $query: feature-targeting.all()) {
177 $feat-color: feature-targeting.create-target($query, color);
178
179 .mdc-slider__thumb:hover,
180 .mdc-slider__thumb--focused {
181 @include _set-thumb-color($color, $query);
182 }
183}
184
185/// Customizes color of active tick marks, using a Color or state Map.
186/// - To set only the default color, provide a single Color.
187/// - To set one or more state colors, provide a state Map with optional keys.
188/// - Supported state Map keys: `default`, `disabled`.
189///
190/// @example
191/// @include tick-mark-active-color(blue);
192/// @include tick-mark-active-color((disabled: gray));
193///
194/// @param {Color | Map} $color-or-map - The label's color or a state Map
195@mixin tick-mark-active-color(
196 $color-or-map,
197 $opacity: $tick-mark-opacity,
198 $query: feature-targeting.all()
199) {
200 @include _set-tick-mark-active-color(
201 state.get-default-state($color-or-map),
202 $opacity,
203 $query
204 );
205
206 $_disabled-color: state.get-disabled-state($color-or-map);
207 @if $_disabled-color {
208 &.mdc-slider--disabled {
209 @include _set-tick-mark-active-color($_disabled-color, $opacity, $query);
210 }
211 }
212}
213
214@mixin _set-tick-mark-active-color($color, $opacity, $query) {
215 $feat-color: feature-targeting.create-target($query, color);
216
217 .mdc-slider__tick-mark--active {
218 @include feature-targeting.targets($feat-color) {
219 @include theme.property(background-color, $color);
220
221 opacity: $opacity;
222 }
223 }
224}
225
226/// Customizes color of inactive tick marks, using a Color or state Map.
227/// - To set only the default color, provide a single Color.
228/// - To set one or more state colors, provide a state Map with optional keys.
229/// - Supported state Map keys: `default`, `disabled`.
230///
231/// @example
232/// @include tick-mark-inactive-color(blue);
233/// @include tick-mark-inactive-color((disabled: gray));
234///
235/// @param {Color | Map} $color-or-map - The label's color or a state Map
236@mixin tick-mark-inactive-color(
237 $color-or-map,
238 $opacity: $tick-mark-opacity,
239 $query: feature-targeting.all()
240) {
241 @include _set-tick-mark-inactive-color(
242 state.get-default-state($color-or-map),
243 $opacity,
244 $query
245 );
246
247 $_disabled-color: state.get-disabled-state($color-or-map);
248 @if $_disabled-color {
249 &.mdc-slider--disabled {
250 @include _set-tick-mark-inactive-color(
251 $_disabled-color,
252 $opacity,
253 $query
254 );
255 }
256 }
257}
258
259@mixin _set-tick-mark-inactive-color($color, $opacity, $query) {
260 $feat-color: feature-targeting.create-target($query, color);
261
262 .mdc-slider__tick-mark--inactive {
263 @include feature-targeting.targets($feat-color) {
264 @include theme.property(background-color, $color);
265
266 opacity: $opacity;
267 }
268 }
269}
270
271///
272/// Customizes color and opacity of the value indicator.
273/// @param {Color | String} $color Either a valid color value or a key from
274/// `$theme-variables.property-values`.
275/// @param {number} $opacity
276///
277@mixin value-indicator-color(
278 $color,
279 $opacity,
280 $query: feature-targeting.all()
281) {
282 $feat-color: feature-targeting.create-target($query, color);
283
284 .mdc-slider__value-indicator {
285 @include feature-targeting.targets($feat-color) {
286 @include theme.property(background-color, $color);
287
288 opacity: $opacity;
289 }
290 }
291
292 // Caret.
293 .mdc-slider__value-indicator::before {
294 @include feature-targeting.targets($feat-color) {
295 @include theme.property(border-top-color, $color);
296 }
297 }
298}
299
300///
301/// Customizes color of the value indicator text.
302/// @param {Color | String} $color Either a valid color value or a key from
303/// `$theme-variables.property-values`.
304///
305@mixin value-indicator-text-color($color, $query: feature-targeting.all()) {
306 $feat-color: feature-targeting.create-target($query, color);
307
308 .mdc-slider__value-indicator {
309 @include feature-targeting.targets($feat-color) {
310 @include theme.property(color, $color);
311 }
312 }
313}