-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
/
VProgressCircular.ts
150 lines (124 loc) Β· 3.34 KB
/
VProgressCircular.ts
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import '../../stylus/components/_progress-circular.styl'
// Mixins
import Colorable from '../../mixins/colorable'
import mixins from '../../util/mixins'
// Types
import { CreateElement, VNode, VNodeChildrenArrayContents } from 'vue'
/* @vue/component */
export default mixins(Colorable).extend({
name: 'v-progress-circular',
props: {
button: Boolean,
indeterminate: Boolean,
rotate: {
type: Number,
default: 0
},
size: {
type: [Number, String],
default: 32
},
width: {
type: Number,
default: 4
},
value: {
type: [Number, String],
default: 0
}
},
computed: {
calculatedSize (): number {
return Number(this.size) + (this.button ? 8 : 0)
},
circumference (): number {
return 2 * Math.PI * this.radius
},
classes (): object {
return {
'v-progress-circular--indeterminate': this.indeterminate,
'v-progress-circular--button': this.button
}
},
normalizedValue (): number {
if (this.value < 0) {
return 0
}
if (this.value > 100) {
return 100
}
return parseFloat(this.value)
},
radius (): number {
return 20
},
strokeDashArray (): number {
return Math.round(this.circumference * 1000) / 1000
},
strokeDashOffset (): string {
return ((100 - this.normalizedValue) / 100) * this.circumference + 'px'
},
strokeWidth (): number {
return this.width / +this.size * this.viewBoxSize * 2
},
styles (): object {
return {
height: `${this.calculatedSize}px`,
width: `${this.calculatedSize}px`
}
},
svgStyles (): object {
return {
transform: `rotate(${this.rotate}deg)`
}
},
viewBoxSize (): number {
return this.radius / (1 - this.width / +this.size)
}
},
methods: {
genCircle (h: CreateElement, name: string, offset: string | number): VNode {
return h('circle', {
class: `v-progress-circular__${name}`,
attrs: {
fill: 'transparent',
cx: 2 * this.viewBoxSize,
cy: 2 * this.viewBoxSize,
r: this.radius,
'stroke-width': this.strokeWidth,
'stroke-dasharray': this.strokeDashArray,
'stroke-dashoffset': offset
}
})
},
genSvg (h: CreateElement): VNode {
const children = [
this.indeterminate || this.genCircle(h, 'underlay', 0),
this.genCircle(h, 'overlay', this.strokeDashOffset)
] as VNodeChildrenArrayContents
return h('svg', {
style: this.svgStyles,
attrs: {
xmlns: 'http://www.w3.org/2000/svg',
viewBox: `${this.viewBoxSize} ${this.viewBoxSize} ${2 * this.viewBoxSize} ${2 * this.viewBoxSize}`
}
}, children)
}
},
render (h): VNode {
const info = h('div', { staticClass: 'v-progress-circular__info' }, this.$slots.default)
const svg = this.genSvg(h)
return h('div', this.setTextColor(this.color, {
staticClass: 'v-progress-circular',
attrs: {
'role': 'progressbar',
'aria-valuemin': 0,
'aria-valuemax': 100,
'aria-valuenow': this.indeterminate ? undefined : this.normalizedValue
},
class: this.classes,
style: this.styles,
on: this.$listeners
}), [svg, info])
}
})