ant-design-vue/components/rate/Star.vue

52 lines
1.2 KiB
Vue
Raw Normal View History

2017-11-01 09:03:42 +00:00
<script>
2017-12-14 04:13:15 +00:00
import { cloneVNodes } from '../_util/vnode'
2017-12-13 09:58:05 +00:00
2017-11-01 09:03:42 +00:00
export default {
name: 'Star',
props: {
index: Number,
disabled: Boolean,
prefixCls: String,
allowHalf: Boolean,
value: Number,
},
2017-11-09 09:24:00 +00:00
computed: {
2017-11-02 07:05:31 +00:00
getClassName () {
const { prefixCls, index, value, allowHalf } = this
2017-11-09 09:24:00 +00:00
const starValue = index + 1
2017-11-01 09:03:42 +00:00
if (allowHalf && value + 0.5 === starValue) {
2017-11-02 07:05:31 +00:00
return `${prefixCls} ${prefixCls}-half ${prefixCls}-active`
2017-11-01 09:03:42 +00:00
}
2017-11-02 07:05:31 +00:00
return starValue <= value ? `${prefixCls} ${prefixCls}-full` : `${prefixCls} ${prefixCls}-zero`
2017-11-01 09:03:42 +00:00
},
2017-11-09 09:24:00 +00:00
},
methods: {
2017-11-02 07:05:31 +00:00
onClick (e) {
if (this.disabled) return
2017-11-09 09:24:00 +00:00
this.$emit('click', e, this.index)
2017-11-01 09:03:42 +00:00
},
2017-11-02 07:05:31 +00:00
onHover (e) {
if (this.disabled) return
2017-11-09 09:24:00 +00:00
this.$emit('hover', e, this.index)
2017-11-01 09:03:42 +00:00
},
},
2017-12-13 09:58:05 +00:00
render (createElement) {
2017-12-14 02:17:07 +00:00
const { getClassName, onClick, onHover, prefixCls } = this
2017-12-14 02:12:19 +00:00
return (
<li
2017-12-14 02:17:07 +00:00
class={getClassName}
onClick={onClick}
onMousemove={onHover}
2017-12-14 02:12:19 +00:00
>
2017-12-14 02:17:07 +00:00
<div class={`${prefixCls}-first`}>
2017-12-14 02:12:19 +00:00
{this.$slots.default}
</div>
2017-12-14 02:17:07 +00:00
<div class={`${prefixCls}-second`}>
2017-12-14 04:13:15 +00:00
{cloneVNodes(this.$slots.default, true)}
2017-12-14 02:12:19 +00:00
</div>
</li>
)
2017-12-13 09:58:05 +00:00
},
2017-11-01 09:03:42 +00:00
}
</script>