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.
ant-design-vue/components/rate/Star.vue

52 lines
1.2 KiB

7 years ago
<script>
7 years ago
import { cloneVNodes } from '../_util/vnode'
7 years ago
7 years ago
export default {
name: 'Star',
props: {
index: Number,
disabled: Boolean,
prefixCls: String,
allowHalf: Boolean,
value: Number,
},
7 years ago
computed: {
7 years ago
getClassName () {
const { prefixCls, index, value, allowHalf } = this
7 years ago
const starValue = index + 1
7 years ago
if (allowHalf && value + 0.5 === starValue) {
7 years ago
return `${prefixCls} ${prefixCls}-half ${prefixCls}-active`
7 years ago
}
7 years ago
return starValue <= value ? `${prefixCls} ${prefixCls}-full` : `${prefixCls} ${prefixCls}-zero`
7 years ago
},
7 years ago
},
methods: {
7 years ago
onClick (e) {
if (this.disabled) return
7 years ago
this.$emit('click', e, this.index)
7 years ago
},
7 years ago
onHover (e) {
if (this.disabled) return
7 years ago
this.$emit('hover', e, this.index)
7 years ago
},
},
7 years ago
render (createElement) {
7 years ago
const { getClassName, onClick, onHover, prefixCls } = this
7 years ago
return (
<li
7 years ago
class={getClassName}
onClick={onClick}
onMousemove={onHover}
7 years ago
>
7 years ago
<div class={`${prefixCls}-first`}>
7 years ago
{this.$slots.default}
</div>
7 years ago
<div class={`${prefixCls}-second`}>
7 years ago
{cloneVNodes(this.$slots.default, true)}
7 years ago
</div>
</li>
)
7 years ago
},
7 years ago
}
</script>