ant-design-vue/components/tag/Tag.jsx

84 lines
1.9 KiB
Vue
Raw Normal View History

2018-03-19 02:16:27 +00:00
2017-11-09 07:58:53 +00:00
import Icon from '../icon'
2018-02-05 11:12:41 +00:00
import getTransitionProps from '../_util/getTransitionProps'
import omit from 'omit.js'
2017-11-09 07:58:53 +00:00
export default {
2018-04-08 13:17:20 +00:00
name: 'ATag',
2017-11-09 07:58:53 +00:00
props: {
prefixCls: {
default: 'ant-tag',
type: String,
},
color: String,
closable: Boolean,
},
data () {
return {
closed: false,
}
},
computed: {
2018-02-05 11:12:41 +00:00
isPresetColor () {
const isPresetColor = (color) => {
if (!color) { return false }
return /^(pink|red|yellow|orange|cyan|green|blue|purple)(-inverse)?$/.test(color)
}
return isPresetColor(this.color)
},
2017-11-09 07:58:53 +00:00
classes () {
const { prefixCls, color, isPresetColor } = this
return {
[`${prefixCls}`]: true,
[`${prefixCls}-${color}`]: isPresetColor,
[`${prefixCls}-has-color`]: (color && !isPresetColor),
}
},
tagStyle () {
2018-02-05 11:12:41 +00:00
const { color, isPresetColor } = this
2017-11-09 07:58:53 +00:00
return {
backgroundColor: (color && !isPresetColor) ? color : null,
}
},
},
methods: {
animationEnd () {
2018-02-05 11:12:41 +00:00
this.$emit('afterClose')
2017-11-09 07:58:53 +00:00
},
close (e) {
this.$emit('close', e)
if (e.defaultPrevented) {
return
}
this.closed = true
},
},
2018-02-05 11:12:41 +00:00
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>
)
},
2017-11-09 07:58:53 +00:00
}
2018-03-19 02:16:27 +00:00