-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.jsx
92 lines (83 loc) · 2.07 KB
/
index.jsx
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
85
86
87
88
89
90
91
92
import {
Component,
h
} from 'skatejs';
import {define} from 'skateparkjs-core';
import styles from './styles';
class SKProgress extends Component {
static get props() {
return {
//TODO: Implement
type: {
attribute: true,
default: 'plain' //radial
},
value: {
attribute: true,
default: 0
},
color: {
attribute: true,
default: '#f80'
},
animated: {
attribute: true,
default: false
},
width: {
attribute: true,
default: 'inherit',
deserialize(value) {
return `${value}px`;
}
},
height: {
attribute: true,
default: '30px',
deserialize(value) {
return `${value}px`;
}
},
showPercentage: {
attribute: true,
default: false
}
};
}
connectedCallback() {
super.connectedCallback();
this.style.width = this.width;
this.style.height = this.height;
this.widthValue = this.getElementSize('width');
this.heightValue = this.getElementSize('height');
}
renderCallback() {
const width = this.widthValue;
const height = this.heightValue;
const progress = Math.min(width, (this.value * width) / 100);
const progressValue = this.showPercentage ? h('span', {class: 'percentage'}, `${Math.min(100, this.value)}%`) : null;
const mergedStyles = styles + `:host {--color: ${this.color};}`;
const animated = this.animated ? 'animated' : '';
return [
h('style', mergedStyles),
h('div', {
class: `wrapper ${animated}`
}, h('div', {
class: 'progress',
style: {
transform: `translateX(${progress}px)`
}
}), progressValue)
];
}
getElementSize(property) {
return isNaN(parseInt(this[property])) ?
this.parentElement.getClientRects()[0][property] :
parseInt(this[property]);
}
increment(increment) {
this.value = parseInt(this.value) + increment;
}
}
define('sk-progress', SKProgress);
export default SKProgress;