feat: 添加progress

This commit is contained in:
jiangruowei
2017-03-13 21:12:02 +08:00
parent a2a62c89f1
commit 5f7e98a547
15 changed files with 349 additions and 10 deletions

View File

@@ -0,0 +1,26 @@
# @youzan/<%= name %>
!!! 请在此处填写你的文档最简单描述 !!!
[![version][version-image]][download-url]
[![download][download-image]][download-url]
[version-image]: http://npm.qima-inc.com/badge/v/@youzan/<%= name %>.svg?style=flat-square
[download-image]: http://npm.qima-inc.com/badge/d/@youzan/<%= name %>.svg?style=flat-square
[download-url]: http://npm.qima-inc.com/package/@youzan/<%= name %>
## Demo
## Usage
## API
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
| className | 自定义额外类名 | string | '' | '' |
## License
[MIT](https://opensource.org/licenses/MIT)

View File

@@ -0,0 +1,3 @@
import Progress from './src/progress';
export default Progress;

View File

@@ -0,0 +1,10 @@
{
"name": "@youzan/zan-switch",
"version": "0.0.1",
"description": "progress component",
"main": "./index.js",
"author": "jiangruowei",
"license": "MIT",
"devDependencies": {},
"dependencies": {}
}

View File

@@ -0,0 +1,84 @@
<template>
<div class="zan-progress">
<div class="zan-progress__bar">
<span class="zan-progress__bar__finished-portion" :style="{backgroundColor: componentColor, width: percentage + '%'}"></span>
<span class="zan-progress__bar__pivot" :style="pivotStyle">
{{pivotText}}
</span>
</div>
</div>
</template>
<script>
/**
* zan-progress
* @module components/progress
* @desc 开关
* @param {boolean} [inactive=false] - 是否置灰
* @param {number} [percentage=0] - 进度百分比
* @param {string} [pivotText=percentage] - 进度条显示文字
* @param {string} [color='#38f'] - 进度条颜色
* @param {string} [textColor='#fff'] - 进度条文字颜色
*
* @example
* <zan-switch checked="true" disabled="false"></zan-switch>
*/
export default {
name: 'zan-progress',
props: {
percentage: {
type: Number,
default: 0,
validate(value) {
return value <= 100 && value >= 0;
}
},
inactive: {
type: Boolean,
default: false
},
pivotText: {
type: String,
default: function() {
return this.percentage.toString() + '%';
}
},
color: {
type: String,
default: '#38f'
},
textColor: {
type: String,
default: '#fff'
}
},
computed: {
componentColor() {
return this.inactive ? '#cacaca' : this.color;
},
pivotStyle() {
let pivotStyle = {
backgroundColor: this.componentColor,
color: this.textColor,
left: this.percentage + '%',
marginLeft: '-14px'
}
console.log(this.percentage);
if (this.percentage <= 5) {
pivotStyle.left = '0%';
pivotStyle.marginLeft = '0';
} else if (this.percentage >= 95) {
pivotStyle.left = '100%';
pivotStyle.marginLeft = '-28px';
} else {
pivotStyle.left = this.percentage + '%';
pivotStyle.marginLeft = '-14px';
}
return pivotStyle;
}
}
};
</script>