From e7319f3987aba3a31f7df2eb692dbfc29899d6fa Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Mon, 10 Dec 2018 22:38:49 +0800 Subject: [PATCH] feat: update rate --- .../__tests__/__snapshots__/demo.test.js.snap | 2 +- .../__tests__/__snapshots__/demo.test.js.snap | 102 +++++++++--------- components/rate/index.jsx | 16 +-- components/vc-rate/src/Rate.jsx | 13 +-- components/vc-rate/src/Star.jsx | 7 +- 5 files changed, 63 insertions(+), 77 deletions(-) diff --git a/components/form/__tests__/__snapshots__/demo.test.js.snap b/components/form/__tests__/__snapshots__/demo.test.js.snap index 99969e364..f66e09653 100644 --- a/components/form/__tests__/__snapshots__/demo.test.js.snap +++ b/components/form/__tests__/__snapshots__/demo.test.js.snap @@ -573,7 +573,7 @@ exports[`renders ./components/form/demo/validate-other.vue correctly 1`] = `
-
+
diff --git a/components/rate/__tests__/__snapshots__/demo.test.js.snap b/components/rate/__tests__/__snapshots__/demo.test.js.snap index 95871acda..bd976d3d2 100644 --- a/components/rate/__tests__/__snapshots__/demo.test.js.snap +++ b/components/rate/__tests__/__snapshots__/demo.test.js.snap @@ -4,42 +4,42 @@ exports[`renders ./components/rate/demo/basic.md correctly 1`] = ` @@ -141,42 +141,42 @@ exports[`renders ./components/rate/demo/clear.md correctly 1`] = ` allowClear: true @@ -184,42 +184,42 @@ exports[`renders ./components/rate/demo/clear.md correctly 1`] = ` allowClear: false @@ -231,42 +231,42 @@ exports[`renders ./components/rate/demo/disabled.md correctly 1`] = ` @@ -276,45 +276,45 @@ exports[`renders ./components/rate/demo/half.md correctly 1`] = ` `; -exports[`renders ./components/rate/demo/text.md correctly 1`] = `
3 stars
`; +exports[`renders ./components/rate/demo/text.md correctly 1`] = `
3 stars
`; diff --git a/components/rate/index.jsx b/components/rate/index.jsx index 7903e9230..231e3289d 100644 --- a/components/rate/index.jsx +++ b/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') || const rateProps = { props: { character, - ...restProps, + ...getOptionProps(this), }, on: this.$listeners, ref: 'refRate', } - const slotCharacterHtml = slotCharacter !== undefined ? ( - - ) : return ( - { - character === undefined ? slotCharacterHtml : null - } - + /> ) }, } diff --git a/components/vc-rate/src/Rate.jsx b/components/vc-rate/src/Rate.jsx index 8d8de709a..d15b34af3 100644 --- a/components/vc-rate/src/Rate.jsx +++ b/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( - { - slotCharacter !== undefined ? () : null - } - + /> ) } return ( diff --git a/components/vc-rate/src/Star.jsx b/components/vc-rate/src/Star.jsx index 7405ea6de..1a5c4152b 100644 --- a/components/vc-rate/src/Star.jsx +++ b/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 (