feat: update rate

pull/309/head
tangjinzhou 2018-12-10 22:38:49 +08:00
parent 1d72ddf6bc
commit e7319f3987
5 changed files with 63 additions and 77 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
import PropTypes from '../_util/vue-types'
import { initDefaultProps, getOptionProps } from '../_util/props-util'
import { initDefaultProps, getOptionProps, getComponentFromProp } from '../_util/props-util'
import VcRate from '../vc-rate'
import Icon from '../icon'
@ -34,27 +34,19 @@ const Rate = {
},
},
render () {
const { character, ...restProps } = getOptionProps(this)
const slotCharacter = this.$slots.character
const character = getComponentFromProp(this, 'character') || <Icon type='star' theme='filled' />
const rateProps = {
props: {
character,
...restProps,
...getOptionProps(this),
},
on: this.$listeners,
ref: 'refRate',
}
const slotCharacterHtml = slotCharacter !== undefined ? (
<template slot='character'>{slotCharacter}</template>
) : <Icon slot='character' type='star' />
return (
<VcRate
{...rateProps}
>
{
character === undefined ? slotCharacterHtml : null
}
</VcRate>
/>
)
},
}

View File

@ -1,7 +1,7 @@
import PropTypes from '../../_util/vue-types'
import classNames from 'classnames'
import KeyCode from '../../_util/KeyCode'
import { initDefaultProps, hasProp, getOptionProps } from '../../_util/props-util'
import { initDefaultProps, hasProp, getOptionProps, getComponentFromProp } from '../../_util/props-util'
import BaseMixin from '../../_util/BaseMixin'
import { getOffsetLeft } from './util'
import Star from './Star'
@ -169,13 +169,12 @@ export default {
allowHalf,
prefixCls,
disabled,
character,
tabIndex,
} = getOptionProps(this)
const { sValue, hoverValue, focused } = this
const stars = []
const disabledClass = disabled ? `${prefixCls}-disabled` : ''
const slotCharacter = this.$slots.character
const character = getComponentFromProp(this, 'character')
for (let index = 0; index < count; index++) {
const starProps = {
props: {
@ -185,7 +184,7 @@ export default {
prefixCls: `${prefixCls}-star`,
allowHalf,
value: hoverValue === undefined ? sValue : hoverValue,
character: slotCharacter === undefined ? character : undefined,
character,
focused,
},
on: {
@ -198,11 +197,7 @@ export default {
stars.push(
<Star
{...starProps}
>
{
slotCharacter !== undefined ? (<template slot='character'>{slotCharacter}</template>) : null
}
</Star>
/>
)
}
return (

View File

@ -1,5 +1,6 @@
import PropTypes from '../../_util/vue-types'
import BaseMixin from '../../_util/BaseMixin'
import { getComponentFromProp } from '../../_util/props-util'
function noop () {}
export default {
@ -52,10 +53,8 @@ export default {
},
render () {
const { onHover, onClick, onKeyDown, disabled, prefixCls, index, count, value } = this
let character = this.character
if (character === undefined) {
character = this.$slots.character
}
const character = getComponentFromProp(this, 'character')
return (
<li
class={this.getClassName()}