Skip to content

Commit 76a8d79

Browse files
crisbetotinayuangao
authored andcommitted
chore(progress-bar): DRY up the buffer background image (#1942)
* chore(progress-bar): DRY up the buffer background image The buffer background image is a long URL-encoded SVG, which was being repeated 3 times. This change moves it into a variable in order to reduce repetition. * fix: use a function to generate the background
1 parent cb0d6fc commit 76a8d79

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

src/lib/progress-bar/_progress-bar-theme.scss

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,32 @@
77
$accent: map-get($theme, accent);
88
$warn: map-get($theme, warn);
99

10-
// TODO(josephperrott): Find better way to inline svgs.
11-
// In buffer mode a repeated SVG object is used as a background.
12-
// Each of the following defines the SVG object for each of the class defined colors.
13-
//
14-
// Each string is a URL encoded version of:
15-
//
16-
// <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
17-
// version="1.1" x="0px" y="0px" enable-background="new 0 0 5 2"
18-
// xml:space="preserve" viewBox="0 0 5 2" preserveAspectRatio="none slice">
19-
// <circle cx="1" cy="1" r="1" fill="{INJECTED_COLOR}"/>
20-
// </svg>
21-
//
22-
$buffer-bubbles-primary-url: url(
23-
'data:image/svg+xml;charset=UTF-8,%3Csvg%20version%3D%271.1%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27' +
24-
'%20xmlns%3Axlink%3D%27http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%27%20x%3D%270px%27%20y%3D%270px%27%20enable-backgroun' +
25-
'd%3D%27new%200%200%205%202%27%20xml%3Aspace%3D%27preserve%27%20viewBox%3D%270%200%205%202%27%20preserveAspectRatio' +
26-
'%3D%27none%20slice%27%3E%3Ccircle%20cx%3D%271%27%20cy%3D%271%27%20r%3D%271%27%20fill%3D%27' +
27-
md-color($primary, 100) + '%27%2F%3E%3C%2Fsvg%3E') !default;
28-
$buffer-bubbles-accent-url: url(
29-
'data:image/svg+xml;charset=UTF-8,%3Csvg%20version%3D%271.1%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27' +
30-
'%20xmlns%3Axlink%3D%27http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%27%20x%3D%270px%27%20y%3D%270px%27%20enable-backgroun' +
31-
'd%3D%27new%200%200%205%202%27%20xml%3Aspace%3D%27preserve%27%20viewBox%3D%270%200%205%202%27%20preserveAspectRatio' +
32-
'%3D%27none%20slice%27%3E%3Ccircle%20cx%3D%271%27%20cy%3D%271%27%20r%3D%271%27%20fill%3D%27' +
33-
md-color($accent, 100) + '%27%2F%3E%3C%2Fsvg%3E') !default;
34-
$buffer-bubbles-warn-url: url(
35-
'data:image/svg+xml;charset=UTF-8,%3Csvg%20version%3D%271.1%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27' +
36-
'%20xmlns%3Axlink%3D%27http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%27%20x%3D%270px%27%20y%3D%270px%27%20enable-backgroun' +
37-
'd%3D%27new%200%200%205%202%27%20xml%3Aspace%3D%27preserve%27%20viewBox%3D%270%200%205%202%27%20preserveAspectRatio' +
38-
'%3D%27none%20slice%27%3E%3Ccircle%20cx%3D%271%27%20cy%3D%271%27%20r%3D%271%27%20fill%3D%27' +
39-
md-color($warn, 100) + '%27%2F%3E%3C%2Fsvg%3E') !default;
40-
4110
.md-progress-bar-background {
42-
background: $buffer-bubbles-primary-url;
11+
background: #{_md-progress-bar-buffer($primary, 100)};
4312
}
44-
13+
4514
.md-progress-bar-buffer {
4615
background-color: md-color($primary, 100);
4716
}
48-
17+
4918
md-progress-bar[color='accent'] {
5019
.md-progress-bar-background {
51-
background: $buffer-bubbles-accent-url;
20+
background: #{_md-progress-bar-buffer($accent, 100)};
5221
}
53-
22+
5423
.md-progress-bar-buffer {
5524
background-color: md-color($accent, 100);
5625
}
5726
.md-progress-bar-fill::after {
5827
background-color: md-color($accent, 600);
5928
}
6029
}
61-
30+
6231
md-progress-bar[color='warn'] {
6332
.md-progress-bar-background {
64-
background: $buffer-bubbles-warn-url;
33+
background: #{_md-progress-bar-buffer($warn, 100)};
6534
}
66-
35+
6736
.md-progress-bar-buffer {
6837
background-color: md-color($warn, 100);
6938
}
@@ -76,3 +45,26 @@
7645
background-color: md-color($primary, 600);
7746
}
7847
}
48+
49+
// TODO(josephperrott): Find better way to inline svgs.
50+
// In buffer mode a repeated SVG object is used as a background.
51+
// Each of the following defines the SVG object for each of the class defined colors.
52+
//
53+
// The string is a URL encoded version of:
54+
//
55+
// <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
56+
// version="1.1" x="0px" y="0px" enable-background="new 0 0 5 2"
57+
// xml:space="preserve" viewBox="0 0 5 2" preserveAspectRatio="none slice">
58+
// <circle cx="1" cy="1" r="1" fill="{INJECTED_COLOR}"/>
59+
// </svg>
60+
@function _md-progress-bar-buffer($palette, $hue) {
61+
$result: '' +
62+
'data:image/svg+xml;charset=UTF-8,%3Csvg%20version%3D%271.1%27%20xmlns%3D%27http%3A%2F%2F' +
63+
'www.w3.org%2F2000%2Fsvg%27%20xmlns%3Axlink%3D%27http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%2' +
64+
'7%20x%3D%270px%27%20y%3D%270px%27%20enable-background%3D%27new%200%200%205%202%27%20xml%' +
65+
'3Aspace%3D%27preserve%27%20viewBox%3D%270%200%205%202%27%20preserveAspectRatio%3D%27none' +
66+
'%20slice%27%3E%3Ccircle%20cx%3D%271%27%20cy%3D%271%27%20r%3D%271%27%20fill%3D%27' +
67+
md-color($palette, $hue) + '%27%2F%3E%3C%2Fsvg%3E';
68+
69+
@return url($result);
70+
}

0 commit comments

Comments
 (0)