lulouis-vant
Version:
Lightweight Mobile UI Components built on Vue
83 lines (81 loc) • 1.93 kB
JavaScript
import { use, isDef } from '../utils';
import { BLUE, WHITE } from '../utils/color';
var _use = use('progress'),
sfc = _use[0],
bem = _use[1];
export default sfc({
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: BLUE
},
textColor: {
type: String,
default: WHITE
}
},
data: function data() {
return {
pivotWidth: 0,
progressWidth: 0
};
},
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;
}
},
render: function render(h) {
var pivotText = this.pivotText,
percentage = this.percentage;
var text = isDef(pivotText) ? pivotText : percentage + '%';
var showPivot = this.showPivot && text;
var background = this.inactive ? '#cacaca' : this.color;
var pivotStyle = {
color: this.textColor,
background: this.pivotColor || background
};
var portionStyle = {
background: background,
width: (this.progressWidth - this.pivotWidth) * percentage / 100 + 'px'
};
return h("div", {
"class": bem()
}, [h("span", {
"class": bem('portion', {
'with-pivot': showPivot
}),
"style": portionStyle
}, [showPivot && h("span", {
"ref": "pivot",
"style": pivotStyle,
"class": bem('pivot')
}, [text])])]);
}
});