<template>
<view
v-if="show"
:class="[
disabled ? 'u-disabled' : '',
'u-size-' + size,
'u-shape-' + shape,
'u-mode-' + mode + '-' + type
]"
class="u-tag"
:style="[customStyle]"
@tap="clickTag"
>
{{text}}
<view class="u-icon-wrap" @tap.stop>
<u-icon
@click="close"
size="12"
v-if="closeable"
:color="closeIconColor"
name="close"
class="u-close-icon"
:style="[iconStyle]"
></u-icon>
</view>
</view>
</template>
<script>
export default {
name: 'u-tag',
props: {
type: {
type: String,
default: 'primary'
},
disabled: {
type: [Boolean, String],
default: false
},
size: {
type: String,
default: 'default'
},
shape: {
type: String,
default: 'square'
},
text: {
type: [String, Number],
default: ''
},
bgColor: {
type: String,
default: ''
},
color: {
type: String,
default: ''
},
borderColor: {
type: String,
default: ''
},
closeColor: {
type: String,
default: ''
},
index: {
type: [Number, String],
default: ''
},
mode: {
type: String,
default: 'light'
},
closeable: {
type: Boolean,
default: false
},
show: {
type: Boolean,
default: true
}
},
data() {
return {}
},
computed: {
customStyle() {
let style = {}
if (this.color) style.color = this.color + '!important'
if (this.bgColor) style.backgroundColor = this.bgColor + '!important'
if (this.mode == 'plain' && this.color && !this.borderColor)
style.borderColor = this.color
else style.borderColor = this.borderColor
return style
},
iconStyle() {
if (!this.closeable) return
let style = {}
if (this.size == 'mini') style.fontSize = '10rpx'
else style.fontSize = '12rpx'
if (this.mode == 'plain' || this.mode == 'light') style.color = this.type
else if (this.mode == 'dark') style.color = '#ffffff'
if (this.closeColor) style.color = this.closeColor
return style
},
closeIconColor() {
let color = ''
if (this.closeColor) return this.closeColor
else if (this.color) return this.color
else if (this.mode == 'dark') return '#ffffff'
else return this.type
}
},
methods: {
clickTag() {
if (this.disabled) return
this.$emit('click', this.index)
},
close() {
this.$emit('close', this.index)
}
}
}
</script>
<style lang="scss" scoped>
@import '../../libs/css/style.components.scss';
.u-tag {
box-sizing: border-box;
align-items: center;
border-radius: 3rpx;
display: inline-block;
line-height: 1;
}
.u-size-default {
font-size: 12rpx;
padding: 6rpx 12rpx;
}
.u-size-mini {
font-size: 10rpx;
padding: 3rpx 6rpx;
}
.u-mode-light-primary {
background-color: $u-type-primary-light;
color: $u-type-primary;
border: 1px solid $u-type-primary-disabled;
}
.u-mode-light-success {
background-color: $u-type-success-light;
color: $u-type-success;
border: 1px solid $u-type-success-disabled;
}
.u-mode-light-error {
background-color: $u-type-error-light;
color: $u-type-error;
border: 1px solid $u-type-error-disabled;
}
.u-mode-light-warning {
background-color: $u-type-warning-light;
color: $u-type-warning;
border: 1px solid $u-type-warning-disabled;
}
.u-mode-light-info {
background-color: $u-type-info-light;
color: $u-type-info;
border: 1px solid $u-type-info-disabled;
}
.u-mode-dark-primary {
background-color: $u-type-primary;
color: #ffffff;
}
.u-mode-dark-success {
background-color: $u-type-success;
color: #ffffff;
}
.u-mode-dark-error {
background-color: $u-type-error;
color: #ffffff;
}
.u-mode-dark-warning {
background-color: $u-type-warning;
color: #ffffff;
}
.u-mode-dark-info {
background-color: $u-type-info;
color: #ffffff;
}
.u-mode-plain-primary {
background-color: #ffffff;
color: $u-type-primary;
border: 1px solid $u-type-primary;
}
.u-mode-plain-success {
background-color: #ffffff;
color: $u-type-success;
border: 1px solid $u-type-success;
}
.u-mode-plain-error {
background-color: #ffffff;
color: $u-type-error;
border: 1px solid $u-type-error;
}
.u-mode-plain-warning {
background-color: #ffffff;
color: $u-type-warning;
border: 1px solid $u-type-warning;
}
.u-mode-plain-info {
background-color: #ffffff;
color: $u-type-info;
border: 1px solid $u-type-info;
}
.u-disabled {
opacity: 0.55;
}
.u-shape-circle {
border-radius: 50rpx;
}
.u-shape-circleRight {
border-radius: 0 50rpx 50rpx 0;
}
.u-shape-circleLeft {
border-radius: 20rpx 0 0 50rpx;
}
.u-close-icon {
margin-left: 7rpx;
font-size: 12rpx;
color: $u-type-success;
}
.u-icon-wrap {
display: inline-flex;
transform: scale(0.86);
}
</style>