Skip to content

Commit e6cc39d

Browse files
committed
Remove data url from progress-bar.
1 parent b488b39 commit e6cc39d

File tree

4 files changed

+41
-49
lines changed

4 files changed

+41
-49
lines changed

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

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$warn: map-get($theme, warn);
99

1010
.mat-progress-bar-background {
11-
background-image: #{_mat-progress-bar-buffer($primary, lighter)};
11+
fill: mat-color($primary, lighter);
1212
}
1313

1414
.mat-progress-bar-buffer {
@@ -21,7 +21,7 @@
2121

2222
.mat-progress-bar.mat-accent {
2323
.mat-progress-bar-background {
24-
background-image: #{_mat-progress-bar-buffer($accent, lighter)};
24+
fill: mat-color($accent, lighter);
2525
}
2626

2727
.mat-progress-bar-buffer {
@@ -35,7 +35,7 @@
3535

3636
.mat-progress-bar.mat-warn {
3737
.mat-progress-bar-background {
38-
background-image: #{_mat-progress-bar-buffer($warn, lighter)};
38+
fill: mat-color($warn, lighter);
3939
}
4040

4141
.mat-progress-bar-buffer {
@@ -50,33 +50,3 @@
5050

5151
@mixin mat-progress-bar-typography($config) { }
5252

53-
// TODO(josephperrott): Find better way to inline svgs.
54-
// In buffer mode a repeated SVG object is used as a background.
55-
// Each of the following defines the SVG object for each of the class defined colors.
56-
//
57-
// The string is a URL encoded version of:
58-
//
59-
// <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
60-
// version="1.1" x="0px" y="0px" enable-background="new 0 0 5 2"
61-
// xml:space="preserve" viewBox="0 0 5 2" preserveAspectRatio="none slice">
62-
// <circle cx="1" cy="1" r="1" fill="{INJECTED_COLOR}"/>
63-
// </svg>
64-
@function _mat-progress-bar-buffer($palette, $hue) {
65-
$color: mat-color($palette, $hue) + '';
66-
67-
// We also need to escape the hash in hex colors,
68-
// otherwise IE will throw an XML error.
69-
@if str-index($color, '#') == 1 {
70-
$color: '%23' + str-slice($color, 2);
71-
}
72-
73-
$result: '' +
74-
'data:image/svg+xml;charset=UTF-8,%3Csvg%20version%3D%271.1%27%20xmlns%3D%27http%3A%2F%2F' +
75-
'www.w3.org%2F2000%2Fsvg%27%20xmlns%3Axlink%3D%27http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%2' +
76-
'7%20x%3D%270px%27%20y%3D%270px%27%20enable-background%3D%27new%200%200%205%202%27%20xml%' +
77-
'3Aspace%3D%27preserve%27%20viewBox%3D%270%200%205%202%27%20preserveAspectRatio%3D%27none' +
78-
'%20slice%27%3E%3Ccircle%20cx%3D%271%27%20cy%3D%271%27%20r%3D%271%27%20fill%3D%27' +
79-
$color + '%27%2F%3E%3C%2Fsvg%3E';
80-
81-
@return url($result);
82-
}
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
<!-- The background div is named as such because it appears below the other divs and is not sized based on values. -->
2-
<div class="mat-progress-bar-background mat-progress-bar-element"></div>
1+
<!--
2+
The background div is named as such because it appears below the other divs and is not sized based
3+
on values.
4+
-->
5+
<div class="mat-progress-bar-background mat-progress-bar-element">
6+
<svg width="100%" height="5">
7+
<defs>
8+
<pattern id="{{progressbarId}}" x="5" y="0" width="10" height="5" patternUnits="userSpaceOnUse">
9+
<circle cx="2.5" cy="2.5" r="2.5"/>
10+
</pattern>
11+
</defs>
12+
<rect [attr.fill]="'url(#' + progressbarId + ')'" width="100%" height="100%"/>
13+
</svg>
14+
</div>
315
<div class="mat-progress-bar-buffer mat-progress-bar-element" [ngStyle]="_bufferTransform()"></div>
416
<div class="mat-progress-bar-primary mat-progress-bar-fill mat-progress-bar-element" [ngStyle]="_primaryTransform()"></div>
517
<div class="mat-progress-bar-secondary mat-progress-bar-fill mat-progress-bar-element"></div>

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
2626
// The progress bar background is used to show the bubble animation scrolling behind a
2727
// buffering progress bar.
2828
.mat-progress-bar-background {
29-
background-repeat: repeat-x;
30-
background-size: 10px 4px;
31-
display: none;
29+
svg {
30+
position: absolute;
31+
// The width is set to be 10px longer than the container as it will be translated 10px
32+
// during the background scroll animation.
33+
width: calc(100% + 10px);
34+
}
3235
}
3336

3437
// The progress bar buffer is the bar indicator showing the buffer value and is only visible
@@ -104,7 +107,6 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
104107
.mat-progress-bar-background {
105108
animation: mat-progress-bar-background-scroll
106109
$mat-progress-bar-piece-animation-duration infinite linear;
107-
display: block;
108110
}
109111
}
110112
}

src/lib/progress-bar/progress-bar.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import {
9+
Component,
10+
ChangeDetectionStrategy,
11+
Input,
12+
ViewEncapsulation,
13+
ElementRef
14+
} from '@angular/core';
15+
import {ThemePalette} from '../core/common-behaviors/color';
816

9-
import {Component, ChangeDetectionStrategy, Input, ViewEncapsulation} from '@angular/core';
10-
11-
// TODO(josephperrott): Benchpress tests.
12-
// TODO(josephperrott): Add ARIA attributes for progressbar "for".
13-
17+
/** Counter used to generate unique IDs for progress bars. */
18+
let progressbarId = 0;
1419

1520
/**
1621
* <mat-progress-bar> component.
@@ -38,21 +43,19 @@ import {Component, ChangeDetectionStrategy, Input, ViewEncapsulation} from '@ang
3843
})
3944
export class MatProgressBar {
4045
/** Color of the progress bar. */
41-
@Input() color: 'primary' | 'accent' | 'warn' = 'primary';
42-
43-
private _value: number = 0;
46+
@Input() color: ThemePalette = 'primary';
4447

4548
/** Value of the progressbar. Defaults to zero. Mirrored to aria-valuenow. */
4649
@Input()
4750
get value() { return this._value; }
4851
set value(v: number) { this._value = clamp(v || 0); }
49-
50-
private _bufferValue: number = 0;
52+
private _value: number = 0;
5153

5254
/** Buffer value of the progress bar. Defaults to zero. */
5355
@Input()
5456
get bufferValue() { return this._bufferValue; }
5557
set bufferValue(v: number) { this._bufferValue = clamp(v || 0); }
58+
private _bufferValue: number = 0;
5659

5760
/**
5861
* Mode of the progress bar.
@@ -63,6 +66,11 @@ export class MatProgressBar {
6366
*/
6467
@Input() mode: 'determinate' | 'indeterminate' | 'buffer' | 'query' = 'determinate';
6568

69+
/** The id of the progress bar. */
70+
progressbarId = `mat-progress-bar-${progressbarId++}`;
71+
72+
constructor(private el: ElementRef) {}
73+
6674
/** Gets the current transform value for the progress bar's primary indicator. */
6775
_primaryTransform() {
6876
let scale = this.value / 100;

0 commit comments

Comments
 (0)