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

Commit 31d9d7b

Browse files
authored
feat(linear-progress): Add color theme mixins and remove --accent (#1541)
BREAKING CHANGE: The `mdc-linear-progres--accent` modifier class has been removed. Use Sass color mixins instead. Resolves #1148
1 parent 28024e9 commit 31d9d7b

File tree

6 files changed

+87
-14
lines changed

6 files changed

+87
-14
lines changed

demos/linear-progress.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
</figure>
162162

163163
<figure class="linear-progress-demo">
164-
<div role="progressbar" class="mdc-linear-progress mdc-linear-progress--accent">
164+
<div role="progressbar" class="mdc-linear-progress demo-linear-progress--custom" data-buffer="true">
165165
<div class="mdc-linear-progress__buffering-dots"></div>
166166
<div class="mdc-linear-progress__buffer"></div>
167167
<div class="mdc-linear-progress__bar mdc-linear-progress__primary-bar">
@@ -171,7 +171,7 @@
171171
<span class="mdc-linear-progress__bar-inner"></span>
172172
</div>
173173
</div>
174-
<figcaption>Secondary Color</figcaption>
174+
<figcaption>Custom Colors with Buffer</figcaption>
175175
</figure>
176176

177177
</fieldset>

demos/linear-progress.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@
1717
@import "./common";
1818
@import "../packages/mdc-linear-progress/mdc-linear-progress";
1919
@import "../packages/mdc-typography/mdc-typography";
20+
@import "../packages/mdc-theme/color-palette";
21+
22+
.demo-linear-progress--custom {
23+
@include mdc-linear-progress-bar-color($material-color-red-500);
24+
@include mdc-linear-progress-buffer-color($material-color-red-100);
25+
}

packages/mdc-linear-progress/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ The provided modifiers are:
5959
| --------------------- | ------------------------------------------------------- |
6060
| `mdc-linear-progress--indeterminate` | Puts the linear progress indicator in an indeterminate state. |
6161
| `mdc-linear-progress--reversed` | Reverses the direction of the linear progress indicator. |
62-
| `mdc-linear-progress--accent` | Colors the linear progress indicator with the secondary color. |
62+
63+
### Sass Mixins
64+
65+
Mixin | Description
66+
--- | ---
67+
`mdc-linear-progress-bar-color($color)` | Sets the color of the progress bar
68+
`mdc-linear-progress-buffer-color($color)` | Sets the color of the buffer bar and dots
6369

6470
### Using the Foundation Class
6571

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2017 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
@import "@material/theme/mixins";
16+
@import "@material/theme/variables"; // for mdc-theme-prop-value
17+
18+
@mixin mdc-linear-progress-bar-color($color) {
19+
.mdc-linear-progress__bar-inner {
20+
@include mdc-theme-prop(background-color, $color);
21+
}
22+
}
23+
24+
@mixin mdc-linear-progress-buffer-color($color) {
25+
// We need to escape the '#' character as "%23" for SVG because '#' is a reserved character in URIs.
26+
$color-value-for-css: mdc-theme-prop-value($color);
27+
$color-value-for-svg: mdc-linear-progress-str-replace_(#{$color-value-for-css}, "#", "%23");
28+
29+
.mdc-linear-progress__buffering-dots {
30+
// SVG is optimized for data URI (https://codepen.io/tigt/post/optimizing-svgs-in-data-uris)
31+
// stylelint-disable-next-line function-url-quotes
32+
background-image: url("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' enable-background='new 0 0 5 2' xml:space='preserve' viewBox='0 0 5 2' preserveAspectRatio='none slice'%3E%3Ccircle cx='1' cy='1' r='1' fill='#{$color-value-for-svg}'/%3E%3C/svg%3E");
33+
}
34+
35+
.mdc-linear-progress__buffer {
36+
background-color: $color-value-for-css;
37+
}
38+
}
39+
40+
// Based on https://css-tricks.com/snippets/sass/str-replace-function/
41+
@function mdc-linear-progress-str-replace_($string, $search, $replace) {
42+
$index: str-index($string, $search);
43+
44+
@if $index {
45+
$head: str-slice($string, 1, $index - 1);
46+
$tail: mdc-linear-progress-str-replace_(str-slice($string, $index + str-length($search)), $search, $replace);
47+
48+
@return $head + $replace + $tail;
49+
}
50+
51+
@return $string;
52+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
$mdc-linear-progress-baseline-buffer-color: #e6e6e6;

packages/mdc-linear-progress/mdc-linear-progress.scss

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
// limitations under the License.
1414

1515
@import "@material/animation/functions";
16-
@import "@material/theme/mixins";
1716
@import "./keyframes";
17+
@import "./mixins";
18+
@import "./variables";
1819

1920
.mdc-linear-progress {
21+
@include mdc-linear-progress-bar-color(primary);
22+
@include mdc-linear-progress-buffer-color($mdc-linear-progress-baseline-buffer-color);
23+
2024
position: relative;
2125
width: 100%;
2226
height: 4px;
@@ -34,27 +38,18 @@
3438
}
3539

3640
&__bar-inner {
37-
@include mdc-theme-prop(background-color, primary);
38-
3941
display: inline-block;
4042
position: absolute;
4143
width: 100%;
4244
height: 100%;
4345
animation: none;
4446
}
4547

46-
&--accent .mdc-linear-progress__bar-inner {
47-
@include mdc-theme-prop(background-color, secondary);
48-
}
49-
5048
&__buffering-dots {
5149
position: absolute;
5250
width: 100%;
5351
height: 100%;
5452
animation: buffering 250ms infinite linear;
55-
// SVG is optimized for data URI (https://codepen.io/tigt/post/optimizing-svgs-in-data-uris)
56-
// stylelint-disable-next-line function-url-quotes
57-
background-image: url("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' enable-background='new 0 0 5 2' xml:space='preserve' viewBox='0 0 5 2' preserveAspectRatio='none slice'%3E%3Ccircle cx='1' cy='1' r='1' fill='%23e6e6e6'/%3E%3C/svg%3E");
5853
background-repeat: repeat-x;
5954
background-size: 10px 4px;
6055
}
@@ -65,7 +60,6 @@
6560
height: 100%;
6661
transform-origin: top left;
6762
transition: mdc-animation-exit-temporary(transform, 250ms);
68-
background-color: #e6e6e6;
6963
}
7064

7165
&__secondary-bar {

0 commit comments

Comments
 (0)