Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 1019664

Browse files
refactor(slider): Separate static styles to separate mixin in MDC slider
PiperOrigin-RevId: 465153708
1 parent 6683a36 commit 1019664

File tree

1 file changed

+86
-70
lines changed

1 file changed

+86
-70
lines changed

packages/mdc-slider/_slider.scss

Lines changed: 86 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,89 @@ $_track-inactive-height: 4px;
5555
// ripple-related styles from the other slider styles.
5656
// It is recommended that most users use `core-styles` instead.
5757
@mixin without-ripple($query: feature-targeting.all()) {
58+
$feat-color: feature-targeting.create-target($query, color);
59+
60+
@include static-styles($query: $query);
61+
62+
.mdc-slider {
63+
@include slider-theme.track-active-color(
64+
$color-or-map: (
65+
default: slider-theme.$color,
66+
disabled: slider-theme.$disabled-color,
67+
),
68+
$query: $query
69+
);
70+
71+
@include slider-theme.track-inactive-color(
72+
$color-or-map: (
73+
default: slider-theme.$color,
74+
disabled: slider-theme.$disabled-color,
75+
),
76+
$query: $query
77+
);
78+
79+
@include slider-theme.thumb-color(
80+
$color-or-map: (
81+
default: slider-theme.$color,
82+
disabled: slider-theme.$disabled-color,
83+
),
84+
$query: $query
85+
);
86+
87+
@include slider-theme.thumb-ripple-color(
88+
$color: slider-theme.$color,
89+
$query: $query
90+
);
91+
92+
@include slider-theme.tick-mark-active-color(
93+
$color-or-map: (
94+
default: slider-theme.$tick-mark-active-color,
95+
disabled: on-primary,
96+
),
97+
$query: $query
98+
);
99+
100+
@include slider-theme.tick-mark-inactive-color(
101+
$color-or-map: (
102+
default: slider-theme.$tick-mark-inactive-color,
103+
disabled: slider-theme.$disabled-color,
104+
),
105+
$query: $query
106+
);
107+
108+
@include slider-theme.value-indicator-color(
109+
$color: slider-theme.$value-indicator-color,
110+
$opacity: slider-theme.$value-indicator-opacity,
111+
$query: $query
112+
);
113+
114+
@include slider-theme.value-indicator-text-color(
115+
$color: slider-theme.$value-indicator-text-color,
116+
$query: $query
117+
);
118+
}
119+
120+
.mdc-slider--disabled {
121+
@include feature-targeting.targets($feat-color) {
122+
opacity: 0.38;
123+
}
124+
}
125+
}
126+
127+
// This API is intended for use by frameworks that may want to separate the
128+
// ripple-related styles from the other slider styles.
129+
// It is recommended that most users use `core-styles` instead.
130+
@mixin ripple($query: feature-targeting.all()) {
131+
@include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE
132+
133+
.mdc-slider__thumb {
134+
@include ripple.surface($query: $query);
135+
@include ripple.radius-unbounded($query: $query);
136+
@include ripple-theme.states($color: slider-theme.$color, $query: $query);
137+
}
138+
}
139+
140+
@mixin static-styles($query: feature-targeting.all()) {
58141
$feat-animation: feature-targeting.create-target($query, animation);
59142
$feat-color: feature-targeting.create-target($query, color);
60143
$feat-structure: feature-targeting.create-target($query, structure);
@@ -110,19 +193,6 @@ $_track-inactive-height: 4px;
110193
}
111194
}
112195

113-
// This API is intended for use by frameworks that may want to separate the
114-
// ripple-related styles from the other slider styles.
115-
// It is recommended that most users use `core-styles` instead.
116-
@mixin ripple($query: feature-targeting.all()) {
117-
@include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE
118-
119-
.mdc-slider__thumb {
120-
@include ripple.surface($query: $query);
121-
@include ripple.radius-unbounded($query: $query);
122-
@include ripple-theme.states($color: slider-theme.$color, $query: $query);
123-
}
124-
}
125-
126196
@mixin _track($query: feature-targeting.all()) {
127197
$feat-structure: feature-targeting.create-target($query, structure);
128198

@@ -153,6 +223,7 @@ $_track-inactive-height: 4px;
153223
// such that the track grows/shrinks as needed, but the border-radius
154224
// is not affected by the scaling.
155225
border-radius: 3px;
226+
//TODO(b/241274018): not static, move into themeable styles
156227
height: $_track-active-height;
157228
overflow: hidden;
158229
top: math.div($_track-inactive-height - $_track-active-height, 2);
@@ -193,21 +264,6 @@ $_track-inactive-height: 4px;
193264
top: 0;
194265
}
195266
}
196-
197-
@include slider-theme.track-active-color(
198-
$color-or-map: (
199-
default: slider-theme.$color,
200-
disabled: slider-theme.$disabled-color,
201-
),
202-
$query: $query
203-
);
204-
@include slider-theme.track-inactive-color(
205-
$color-or-map: (
206-
default: slider-theme.$color,
207-
disabled: slider-theme.$disabled-color,
208-
),
209-
$query: $query
210-
);
211267
}
212268

213269
@mixin _thumb($query: feature-targeting.all()) {
@@ -219,6 +275,7 @@ $_track-inactive-height: 4px;
219275
.mdc-slider__thumb {
220276
@include feature-targeting.targets($feat-structure) {
221277
display: flex;
278+
//TODO(b/241274018): not static, move (+ width) to themeable styles
222279
height: $_thumb-ripple-size;
223280
@include rtl.ignore-next-line();
224281
left: math.div(-$_thumb-ripple-size, 2);
@@ -262,18 +319,6 @@ $_track-inactive-height: 4px;
262319
width: $_thumb-size;
263320
}
264321
}
265-
266-
@include slider-theme.thumb-color(
267-
$color-or-map: (
268-
default: slider-theme.$color,
269-
disabled: slider-theme.$disabled-color,
270-
),
271-
$query: $query
272-
);
273-
@include slider-theme.thumb-ripple-color(
274-
$color: slider-theme.$color,
275-
$query: $query
276-
);
277322
}
278323

279324
@mixin _tick-marks($query: feature-targeting.all()) {
@@ -297,25 +342,11 @@ $_track-inactive-height: 4px;
297342
.mdc-slider__tick-mark--inactive {
298343
@include feature-targeting.targets($feat-structure) {
299344
border-radius: 50%;
345+
//TODO(b/241274018): not static, move (+ width) to themeable styles
300346
height: 2px;
301347
width: 2px;
302348
}
303349
}
304-
305-
@include slider-theme.tick-mark-active-color(
306-
$color-or-map: (
307-
default: slider-theme.$tick-mark-active-color,
308-
disabled: on-primary,
309-
),
310-
$query: $query
311-
);
312-
@include slider-theme.tick-mark-inactive-color(
313-
$color-or-map: (
314-
default: slider-theme.$tick-mark-inactive-color,
315-
disabled: slider-theme.$disabled-color,
316-
),
317-
$query: $query
318-
);
319350
}
320351

321352
@mixin _value-indicator($query: feature-targeting.all()) {
@@ -427,27 +458,12 @@ $_track-inactive-height: 4px;
427458
.mdc-slider__value-indicator-text {
428459
@include typography.typography(subtitle2, $query);
429460
}
430-
431-
@include slider-theme.value-indicator-color(
432-
$color: slider-theme.$value-indicator-color,
433-
$opacity: slider-theme.$value-indicator-opacity,
434-
$query: $query
435-
);
436-
@include slider-theme.value-indicator-text-color(
437-
$color: slider-theme.$value-indicator-text-color,
438-
$query: $query
439-
);
440461
}
441462

442463
// Styles for slider in disabled state.
443464
@mixin _disabled($query: feature-targeting.all()) {
444-
$feat-color: feature-targeting.create-target($query, color);
445465
$feat-structure: feature-targeting.create-target($query, structure);
446466

447-
@include feature-targeting.targets($feat-color) {
448-
opacity: 0.38;
449-
}
450-
451467
@include feature-targeting.targets($feat-structure) {
452468
cursor: auto;
453469
}

0 commit comments

Comments
 (0)