vant-fork
Version:
Lightweight Mobile UI Components built on Vue
101 lines (93 loc) • 2.33 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _create = _interopRequireDefault(require("../utils/create"));
var _default = (0, _create.default)({
render: function render() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('div', {
class: _vm.b()
}, [_c('span', {
class: _vm.b('portion', {
'with-pivot': _vm.showPivot && _vm.text
}),
style: _vm.portionStyle
}, [_vm.showPivot && _vm.text ? _c('span', {
ref: "pivot",
class: _vm.b('pivot'),
style: _vm.pivotStyle
}, [_vm._v(_vm._s(_vm.text))]) : _vm._e()])]);
},
name: 'progress',
props: {
inactive: Boolean,
pivotText: String,
pivotColor: String,
percentage: {
type: Number,
required: true,
validator: function validator(value) {
return value >= 0 && value <= 100;
}
},
showPivot: {
type: Boolean,
default: true
},
color: {
type: String,
default: '#38f'
},
textColor: {
type: String,
default: '#fff'
}
},
data: function data() {
return {
pivotWidth: 0,
progressWidth: 0
};
},
computed: {
text: function text() {
return this.isDef(this.pivotText) ? this.pivotText : this.percentage + '%';
},
currentColor: function currentColor() {
return this.inactive ? '#cacaca' : this.color;
},
pivotStyle: function pivotStyle() {
return {
color: this.textColor,
background: this.pivotColor || this.currentColor
};
},
portionStyle: function portionStyle() {
return {
width: (this.progressWidth - this.pivotWidth) * this.percentage / 100 + 'px',
background: this.currentColor
};
}
},
mounted: function mounted() {
this.getWidth();
},
watch: {
showPivot: function showPivot() {
this.getWidth();
},
pivotText: function pivotText() {
this.getWidth();
}
},
methods: {
getWidth: function getWidth() {
this.progressWidth = this.$el.offsetWidth;
this.pivotWidth = this.$refs.pivot ? this.$refs.pivot.offsetWidth : 0;
}
}
});
exports.default = _default;