vuetify
Version:
Vue.js 2 Semantic Component Framework
148 lines (126 loc) • 3.55 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
require('../../../src/stylus/components/_progress-circular.styl');
var _colorable = require('../../mixins/colorable');
var _colorable2 = _interopRequireDefault(_colorable);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
name: 'v-progress-circular',
mixins: [_colorable2.default],
props: {
button: Boolean,
indeterminate: Boolean,
rotate: {
type: Number,
default: 0
},
size: {
type: [Number, String],
default: 32
},
width: {
type: Number,
default: 4
},
value: {
type: Number,
default: 0
}
},
computed: {
calculatedSize: function calculatedSize() {
var size = Number(this.size);
if (this.button) {
size += 8;
}
return size;
},
circumference: function circumference() {
return 2 * Math.PI * this.radius;
},
classes: function classes() {
return this.addTextColorClassChecks({
'progress-circular': true,
'progress-circular--indeterminate': this.indeterminate,
'progress-circular--button': this.button
});
},
cxy: function cxy() {
return this.indeterminate && !this.button ? 50 : this.calculatedSize / 2;
},
normalizedValue: function normalizedValue() {
if (this.value < 0) {
return 0;
}
if (this.value > 100) {
return 100;
}
return this.value;
},
radius: function radius() {
return this.indeterminate && !this.button ? 20 : (this.calculatedSize - this.width) / 2;
},
strokeDashArray: function strokeDashArray() {
return Math.round(this.circumference * 1000) / 1000;
},
strokeDashOffset: function strokeDashOffset() {
return (100 - this.normalizedValue) / 100 * this.circumference + 'px';
},
styles: function styles() {
return {
height: this.calculatedSize + 'px',
width: this.calculatedSize + 'px'
};
},
svgSize: function svgSize() {
return this.indeterminate ? false : this.calculatedSize;
},
svgStyles: function svgStyles() {
return {
transform: 'rotate(' + this.rotate + 'deg)'
};
},
viewBox: function viewBox() {
return this.indeterminate ? '25 25 50 50' : false;
}
},
methods: {
genCircle: function genCircle(h, name, offset) {
return h('circle', {
class: 'progress-circular__' + name,
attrs: {
fill: 'transparent',
cx: this.cxy,
cy: this.cxy,
r: this.radius,
'stroke-width': this.width,
'stroke-dasharray': this.strokeDashArray,
'stroke-dashoffset': offset
}
});
},
genSvg: function genSvg(h) {
var children = [!this.indeterminate && this.genCircle(h, 'underlay', 0), this.genCircle(h, 'overlay', this.strokeDashOffset)];
return h('svg', {
style: this.svgStyles,
attrs: {
xmlns: 'http://www.w3.org/2000/svg',
height: this.svgSize,
width: this.svgSize,
viewBox: this.viewBox
}
}, children);
}
},
render: function render(h) {
var info = h('div', { class: 'progress-circular__info' }, [this.$slots.default]);
var svg = this.genSvg(h);
return h('div', {
class: this.classes,
style: this.styles,
on: this.$listeners
}, [svg, info]);
}
};