Browse Source

feat: update rate

pull/309/head
tangjinzhou 6 years ago
parent
commit
e7319f3987
  1. 2
      components/form/__tests__/__snapshots__/demo.test.js.snap
  2. 102
      components/rate/__tests__/__snapshots__/demo.test.js.snap
  3. 16
      components/rate/index.jsx
  4. 13
      components/vc-rate/src/Rate.jsx
  5. 7
      components/vc-rate/src/Star.jsx

2
components/form/__tests__/__snapshots__/demo.test.js.snap

File diff suppressed because one or more lines are too long

102
components/rate/__tests__/__snapshots__/demo.test.js.snap

File diff suppressed because one or more lines are too long

16
components/rate/index.jsx

@ -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>
/>
)
},
}

13
components/vc-rate/src/Rate.jsx

@ -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 (

7
components/vc-rate/src/Star.jsx

@ -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()}

Loading…
Cancel
Save