This commit is contained in:
zhigang.li 2017-12-18 17:52:20 +08:00
parent e6508e277f
commit 7d4b325be8
3 changed files with 88 additions and 14 deletions

View file

@ -1,16 +1,17 @@
<template>
<transition name="fade">
<div :class="classes" @click.stop="check">
<span :class="dotClasses" v-if="showDot"></span><span :class="textClasses"><slot></slot></span><Icon v-if="closable" type="ios-close-empty" @click.native.stop="close"></Icon>
<div :class="classes" @click.stop="check" :style="wraperStyles">
<span :class="dotClasses" v-if="showDot" :style="bgColorStyle"></span>
<span :class="textClasses" :style="textColorStyle"><slot></slot></span>
<Icon v-if="closable" type="ios-close-empty" :color="lineColor" @click.native.stop="close"></Icon>
</div>
</transition>
</template>
<script>
import Icon from '../icon';
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-tag';
const initColorList = ['blue', 'green', 'red', 'yellow', 'default'];
export default {
name: 'Tag',
components: { Icon },
@ -28,9 +29,8 @@
default: true
},
color: {
validator (value) {
return oneOf(value, ['blue', 'green', 'red', 'yellow', 'default']);
}
type: String,
default: 'default'
},
type: {
validator (value) {
@ -58,14 +58,51 @@
}
];
},
wraperStyles () {
return oneOf(this.color, initColorList) ? {} : {background: this.defaultTypeColor, borderColor: this.lineColor, color: this.lineColor};
},
textClasses () {
return `${prefixCls}-text`;
return [
`${prefixCls}-text`,
this.type === 'border' ? (oneOf(this.color, initColorList) ? `${prefixCls}-color-${this.color}` : '') : '',
(this.type !== 'dot' && this.type !== 'border' && this.color !== 'default') ? `${prefixCls}-color-white` : ''
];
},
dotClasses () {
return `${prefixCls}-dot-inner`;
},
showDot () {
return !!this.type && this.type === 'dot';
},
lineColor () {
if (this.type === 'dot') {
return '';
} else if (this.type === 'border') {
return this.color !== undefined ? this.transferColor(this.color) : '';
} else {
return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : '';
}
},
borderColor () {
if (this.type === 'dot') {
return '';
} else if (this.type === 'border') {
return this.color !== undefined ? this.transferColor(this.color) : '';
} else {
return '';
}
},
textColorStyle () {
return oneOf(this.color, initColorList) ? {} : {color: this.lineColor};
},
mainColor () {
return this.color !== undefined ? this.transferColor(this.color) : '';
},
bgColorStyle () {
return oneOf(this.color, initColorList) ? {} : {background: this.mainColor};
},
defaultTypeColor () {
return (this.type !== 'dot' && this.type !== 'border') ? (this.color !== undefined ? this.transferColor(this.color) : '') : '';
}
},
methods: {
@ -85,7 +122,20 @@
} else {
this.$emit('on-change', checked, this.name);
}
},
transferColor (name) {
if (oneOf(name, initColorList)) {
switch (name) {
case 'red': return '#ed3f14';
case 'green': return '#19be6b';
case 'yellow': return '#ff9900';
case 'blue': return '#2d8cf0';
case 'default': return '';
}
} else {
return name;
}
}
}
};
</script>
</script>