Merge pull request #2343 from QingWei-Li/feat-align-step

Steps: add center property, resolve #2315
pull/2369/head
baiyaaaaa 2017-01-12 12:36:48 +08:00 committed by GitHub
commit 7f30ad496d
6 changed files with 31 additions and 8 deletions

View File

@ -120,6 +120,7 @@ Vertical step bars.
| process-status | status of current step | string | wait/process/finish/error/success | process | | process-status | status of current step | string | wait/process/finish/error/success | process |
| finish-status | status of end step | string | wait/process/finish/error/success | finish | | finish-status | status of end step | string | wait/process/finish/error/success | finish |
| align-center | whether step description is centered | boolean | — | false | | align-center | whether step description is centered | boolean | — | false |
| center | center whole `Steps` component | boolean | - | false |
### Step Attributes ### Step Attributes
| Attribute | Description | Type | Accepted Values | Default | | Attribute | Description | Type | Accepted Values | Default |

View File

@ -113,7 +113,8 @@
| active | 设置当前激活步骤 | number | — | 0 | | active | 设置当前激活步骤 | number | — | 0 |
| process-status | 设置当前步骤的状态 | string | wait/process/finish/error/success | process | | process-status | 设置当前步骤的状态 | string | wait/process/finish/error/success | process |
| finish-status | 设置结束步骤的状态 | string | wait/process/finish/error/success | finish | | finish-status | 设置结束步骤的状态 | string | wait/process/finish/error/success | finish |
| align-center | 标题描述居中对齐 | boolean | false, true | false | | align-center | 标题描述居中对齐 | boolean | - | false |
| center | 组件居中显示 | boolean | - | false |
### Step Attributes ### Step Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 | | 参数 | 说明 | 类型 | 可选值 | 默认值 |

View File

@ -37,7 +37,7 @@ Vue.component('el-step', ElStep)
| active | 设置当前激活步骤 | number | — | 0 | | active | 设置当前激活步骤 | number | — | 0 |
| process-status | 设置当前步骤的状态 | string | wait/process/finish/error/success | process | | process-status | 设置当前步骤的状态 | string | wait/process/finish/error/success | process |
| finish-status | 设置结束步骤的状态 | string | wait/process/finish/error/success | finish | | finish-status | 设置结束步骤的状态 | string | wait/process/finish/error/success | finish |
| align-center | 标题描述居中对齐 | boolean | false, true | false | | align-center | 标题描述居中对齐 | boolean | - | false |
### Step Attributes ### Step Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 | | 参数 | 说明 | 类型 | 可选值 | 默认值 |

View File

@ -1,14 +1,15 @@
<template> <template>
<div <div
class="el-step" class="el-step"
:style="style" :style="[style, isLast ? '' : { marginRight: - $parent.stepOffset + 'px' }]"
:class="['is-' + $parent.direction]"> :class="['is-' + $parent.direction]">
<div <div
class="el-step__head" class="el-step__head"
:class="['is-' + currentStatus, { 'is-text': !icon }]"> :class="['is-' + currentStatus, { 'is-text': !icon }]">
<div <div
class="el-step__line" class="el-step__line"
:class="['is-' + $parent.direction,{ 'is-icon': icon }]"> :style="isLast ? '' : { marginRight: $parent.stepOffset + 'px' }"
:class="['is-' + $parent.direction, { 'is-icon': icon }]">
<i class="el-step__line-inner" :style="lineStyle"></i> <i class="el-step__line-inner" :style="lineStyle"></i>
</div> </div>
@ -63,6 +64,7 @@ export default {
style: {}, style: {},
lineStyle: {}, lineStyle: {},
mainOffset: 0, mainOffset: 0,
isLast: false,
currentStatus: this.status currentStatus: this.status
}; };
}, },
@ -103,22 +105,31 @@ export default {
: style.width = step + '%'; : style.width = step + '%';
this.lineStyle = style; this.lineStyle = style;
},
adjustPosition() {
this.style = {};
this.$parent.stepOffset = this.$el.getBoundingClientRect().width / (this.$parent.steps.length - 1);
} }
}, },
mounted() { mounted() {
const parent = this.$parent; const parent = this.$parent;
const isCenter = parent.center;
const len = parent.steps.length;
const isLast = this.isLast = parent.steps[parent.steps.length - 1] === this;
const space = parent.space const space = parent.space
? parent.space + 'px' ? parent.space + 'px'
: 100 / parent.steps.length + '%'; : 100 / (isCenter ? len - 1 : len) + '%';
if (parent.direction === 'horizontal') { if (parent.direction === 'horizontal') {
this.style = { width: space }; this.style = { width: space };
if (parent.alignCenter) { if (parent.alignCenter) {
this.mainOffset = -this.$refs.title.getBoundingClientRect().width / 2 + 16 + 'px'; this.mainOffset = -this.$refs.title.getBoundingClientRect().width / 2 + 16 + 'px';
} }
isCenter && isLast && this.adjustPosition();
} else { } else {
if (parent.steps[parent.steps.length - 1] !== this) { if (!isLast) {
this.style = { height: space }; this.style = { height: space };
} }
} }

View File

@ -1,5 +1,9 @@
<template> <template>
<div class="el-steps" :class="['is-' + direction]"><slot></slot></div> <div
class="el-steps"
:class="['is-' + direction, center ? 'is-center' : '']">
<slot></slot>
</div>
</template> </template>
<script> <script>
@ -14,6 +18,7 @@ export default {
default: 'horizontal' default: 'horizontal'
}, },
alignCenter: Boolean, alignCenter: Boolean,
center: Boolean,
finishStatus: { finishStatus: {
type: String, type: String,
default: 'finish' default: 'finish'
@ -26,7 +31,8 @@ export default {
data() { data() {
return { return {
steps: [] steps: [],
stepOffset: 0
}; };
}, },

View File

@ -11,6 +11,10 @@
@when horizontal { @when horizontal {
white-space: nowrap; white-space: nowrap;
@when center {
text-align: center;
}
} }
} }
} }