From 1af834950421925563a7b82a50b0b47e4bd8218f Mon Sep 17 00:00:00 2001 From: wangxueliang Date: Mon, 18 Mar 2019 20:00:00 +0800 Subject: [PATCH] feat: radio && rate && spin --- components/radio/Group.jsx | 10 +++- components/radio/Radio.jsx | 8 +++- components/radio/RadioButton.jsx | 13 +++-- components/rate/demo/text.md | 5 +- components/rate/index.en-US.md | 1 + components/rate/index.jsx | 32 +++++++++++-- components/rate/index.zh-CN.md | 1 + components/spin/Spin.jsx | 63 +++++++++++-------------- components/spin/__tests__/index.test.js | 19 -------- 9 files changed, 83 insertions(+), 69 deletions(-) diff --git a/components/radio/Group.jsx b/components/radio/Group.jsx index f2415fc9d..5b27c4ebc 100644 --- a/components/radio/Group.jsx +++ b/components/radio/Group.jsx @@ -2,6 +2,7 @@ import classNames from 'classnames'; import PropTypes from '../_util/vue-types'; import Radio from './Radio'; import { getOptionProps, filterEmpty, hasProp } from '../_util/props-util'; +import { ConfigConsumerProps } from '../config-provider'; function noop() {} export default { @@ -11,7 +12,6 @@ export default { }, props: { prefixCls: { - default: 'ant-radio', type: String, }, defaultValue: PropTypes.any, @@ -41,6 +41,9 @@ export default { radioGroupContext: this, }; }, + inject: { + configProvider: { default: () => ({}) }, + }, computed: { radioOptions() { const { disabled } = this; @@ -79,7 +82,10 @@ export default { render() { const { mouseenter = noop, mouseleave = noop } = this.$listeners; const props = getOptionProps(this); - const { prefixCls, options, buttonStyle } = props; + const { prefixCls: customizePrefixCls, options, buttonStyle } = props; + const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls; + const prefixCls = getPrefixCls('radio', customizePrefixCls); + const groupPrefixCls = `${prefixCls}-group`; const classString = classNames(groupPrefixCls, `${groupPrefixCls}-${buttonStyle}`, { [`${groupPrefixCls}-${props.size}`]: props.size, diff --git a/components/radio/Radio.jsx b/components/radio/Radio.jsx index 35b3d1cd7..2ed44ca2b 100644 --- a/components/radio/Radio.jsx +++ b/components/radio/Radio.jsx @@ -2,6 +2,7 @@ import PropTypes from '../_util/vue-types'; import VcCheckbox from '../vc-checkbox'; import classNames from 'classnames'; import { getOptionProps, getAttrs } from '../_util/props-util'; +import { ConfigConsumerProps } from '../config-provider'; function noop() {} @@ -12,7 +13,6 @@ export default { }, props: { prefixCls: { - default: 'ant-radio', type: String, }, defaultChecked: Boolean, @@ -27,6 +27,7 @@ export default { }, inject: { radioGroupContext: { default: undefined }, + configProvider: { default: () => ({}) }, }, methods: { handleChange(event) { @@ -47,7 +48,10 @@ export default { const props = getOptionProps(this); const children = $slots.default; const { mouseenter = noop, mouseleave = noop, ...restListeners } = $listeners; - const { prefixCls, ...restProps } = props; + const { prefixCls: customizePrefixCls, ...restProps } = props; + const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls; + const prefixCls = getPrefixCls('radio', customizePrefixCls); + const radioProps = { props: { ...restProps, prefixCls }, on: restListeners, diff --git a/components/radio/RadioButton.jsx b/components/radio/RadioButton.jsx index 98d0d9d10..5c8f66cc4 100644 --- a/components/radio/RadioButton.jsx +++ b/components/radio/RadioButton.jsx @@ -1,21 +1,28 @@ import Radio from './Radio'; import { getOptionProps } from '../_util/props-util'; +import { ConfigConsumerProps } from '../config-provider'; export default { name: 'ARadioButton', props: { ...Radio.props, prefixCls: { - default: 'ant-radio-button', type: String, }, }, inject: { radioGroupContext: { default: undefined }, + configProvider: { default: () => ({}) }, }, render() { - const props = getOptionProps(this); - const radioProps = { props, on: { ...this.$listeners } }; + const {prefixCls: customizePrefixCls, ...otherProps} = getOptionProps(this); + const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls; + const prefixCls = getPrefixCls('radio-button', customizePrefixCls); + + const radioProps = { props: { + ...otherProps, + prefixCls, + }, on: { ...this.$listeners } }; if (this.radioGroupContext) { radioProps.on.change = this.radioGroupContext.onRadioChange; radioProps.props.checked = props.value === this.radioGroupContext.stateValue; diff --git a/components/rate/demo/text.md b/components/rate/demo/text.md index c97500985..49fa43b0e 100644 --- a/components/rate/demo/text.md +++ b/components/rate/demo/text.md @@ -11,8 +11,8 @@ Add copywriting in rate components. ```html