Badge add new prop: color

This commit is contained in:
梁灏 2019-09-05 11:45:00 +08:00
parent b321e1abca
commit e3930b7ace
3 changed files with 50 additions and 3 deletions

View file

@ -3,8 +3,8 @@
<slot></slot>
<sup :class="dotClasses" :style="styles" v-show="badge"></sup>
</span>
<span v-else-if="status" :class="classes" class="ivu-badge-status" ref="badge">
<span :class="statusClasses"></span>
<span v-else-if="status || color" :class="classes" class="ivu-badge-status" ref="badge">
<span :class="statusClasses" :style="statusStyles"></span>
<span class="ivu-badge-status-text"><slot name="text">{{ text }}</slot></span>
</span>
<span v-else :class="classes" ref="badge">
@ -15,6 +15,7 @@
</template>
<script>
import { oneOf } from '../../utils/assist';
const initColorList = ['blue', 'green', 'red', 'yellow', 'pink', 'magenta', 'volcano', 'orange', 'gold', 'lime', 'cyan', 'geekblue', 'purple'];
const prefixCls = 'ivu-badge';
export default {
@ -50,6 +51,9 @@
},
offset: {
type: Array
},
color: {
type: String
}
},
computed: {
@ -82,10 +86,14 @@
return [
`${prefixCls}-status-dot`,
{
[`${prefixCls}-status-${this.status}`]: !!this.status
[`${prefixCls}-status-${this.status}`]: !!this.status,
[`${prefixCls}-status-${this.color}`]: !!this.color && oneOf(this.color, initColorList)
}
];
},
statusStyles () {
return oneOf(this.color, initColorList) ? {} : { backgroundColor: this.color};
},
styles () {
const style = {};
if (this.offset && this.offset.length === 2) {

View file

@ -127,6 +127,18 @@
font-size: @font-size-small;
margin-left: 6px;
}
@colors: pink, magenta, red, volcano, orange, yellow, gold, cyan, lime, green, blue, geekblue, purple;
.make-color-classes(@i: length(@colors)) when (@i > 0) {
.make-color-classes(@i - 1);
@color: extract(@colors, @i);
@darkColor: '@{color}-6';
&-@{color} {
background-color: @@darkColor;
}
}
.make-color-classes();
}
}