-
Notifications
You must be signed in to change notification settings - Fork 332
/
paper-progress-linear.js
84 lines (69 loc) · 2.26 KB
/
paper-progress-linear.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @module ember-paper
*/
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import Component from '@ember/component';
import { isPresent } from '@ember/utils';
import { htmlSafe } from '@ember/string';
import layout from '../templates/components/paper-progress-linear';
import ColorMixin from 'ember-paper/mixins/color-mixin';
function makeTransform(value) {
let scale = value / 100;
let translateX = (value - 100) / 2;
return `translateX(${translateX.toString()}%) scale(${scale.toString()}, 1)`;
}
const MODE_DETERMINATE = 'determinate';
const MODE_INDETERMINATE = 'indeterminate';
const MODE_BUFFER = 'buffer';
const MODE_QUERY = 'query';
/**
* @class PaperProgressLinear
* @extends Ember.Component
* @uses ColorMixin
*/
export default Component.extend(ColorMixin, {
layout,
tagName: 'md-progress-linear',
attributeBindings: ['mode:md-mode', 'bufferValue:md-buffer-value'],
classNames: ['md-default-theme'],
constants: service(),
mode: computed('value', function() {
let value = this.get('value');
let bufferValue = this.get('bufferValue');
if (isPresent(value)) {
if (isPresent(bufferValue)) {
return MODE_BUFFER;
} else {
return MODE_DETERMINATE;
}
} else {
return MODE_INDETERMINATE;
}
}),
queryModeClass: computed('mode', function() {
let mode = this.get('mode');
if ([MODE_QUERY, MODE_BUFFER, MODE_DETERMINATE, MODE_INDETERMINATE].includes(mode)) {
return `md-mode-${mode}`;
} else {
return '';
}
}),
bar1Style: computed('clampedBufferValue', function() {
return htmlSafe(`${this.get('constants.CSS.TRANSFORM')}: ${makeTransform(this.get('clampedBufferValue'))}`);
}),
bar2Style: computed('clampedValue', 'mode', function() {
if (this.get('mode') === MODE_QUERY) {
return htmlSafe('');
}
return htmlSafe(`${this.get('constants.CSS.TRANSFORM')}: ${makeTransform(this.get('clampedValue'))}`);
}),
clampedValue: computed('value', function() {
let value = this.get('value');
return Math.max(0, Math.min(value || 0, 100));
}),
clampedBufferValue: computed('bufferValue', function() {
let value = this.get('bufferValue');
return Math.max(0, Math.min(value || 0, 100));
})
});