You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.9 KiB
84 lines
1.9 KiB
7 years ago
|
|
||
7 years ago
|
import Icon from '../icon'
|
||
7 years ago
|
import getTransitionProps from '../_util/getTransitionProps'
|
||
|
import omit from 'omit.js'
|
||
7 years ago
|
|
||
|
export default {
|
||
|
name: 'Tag',
|
||
|
props: {
|
||
|
prefixCls: {
|
||
|
default: 'ant-tag',
|
||
|
type: String,
|
||
|
},
|
||
|
color: String,
|
||
|
closable: Boolean,
|
||
|
},
|
||
|
data () {
|
||
|
return {
|
||
|
closed: false,
|
||
|
}
|
||
|
},
|
||
|
computed: {
|
||
7 years ago
|
isPresetColor () {
|
||
|
const isPresetColor = (color) => {
|
||
|
if (!color) { return false }
|
||
|
return /^(pink|red|yellow|orange|cyan|green|blue|purple)(-inverse)?$/.test(color)
|
||
|
}
|
||
|
return isPresetColor(this.color)
|
||
|
},
|
||
7 years ago
|
classes () {
|
||
|
const { prefixCls, color, isPresetColor } = this
|
||
|
return {
|
||
|
[`${prefixCls}`]: true,
|
||
|
[`${prefixCls}-${color}`]: isPresetColor,
|
||
|
[`${prefixCls}-has-color`]: (color && !isPresetColor),
|
||
|
}
|
||
|
},
|
||
|
tagStyle () {
|
||
7 years ago
|
const { color, isPresetColor } = this
|
||
7 years ago
|
return {
|
||
|
backgroundColor: (color && !isPresetColor) ? color : null,
|
||
|
}
|
||
|
},
|
||
|
},
|
||
|
methods: {
|
||
|
animationEnd () {
|
||
7 years ago
|
this.$emit('afterClose')
|
||
7 years ago
|
},
|
||
|
close (e) {
|
||
|
this.$emit('close', e)
|
||
|
if (e.defaultPrevented) {
|
||
|
return
|
||
|
}
|
||
|
this.closed = true
|
||
|
},
|
||
|
},
|
||
7 years ago
|
render () {
|
||
|
const { prefixCls, animationEnd, classes, tagStyle, closable, close, closed, $slots, $listeners } = this
|
||
|
const transitionProps = getTransitionProps(`${prefixCls}-zoom`, {
|
||
|
afterLeave: animationEnd,
|
||
|
})
|
||
|
// const tagProps = {
|
||
|
// on
|
||
|
// }
|
||
|
return (
|
||
|
<transition
|
||
|
{...transitionProps}
|
||
|
>
|
||
|
{!closed
|
||
|
? <div
|
||
|
|
||
|
class={classes}
|
||
|
style={tagStyle}
|
||
|
{...{ on: omit($listeners, ['close', 'afterClose']) }}
|
||
|
>
|
||
|
{$slots.default}
|
||
|
{closable ? <Icon type='cross' onClick={close} /> : null}
|
||
|
</div> : null
|
||
|
}
|
||
|
</transition>
|
||
|
)
|
||
|
},
|
||
7 years ago
|
}
|
||
7 years ago
|
|