diff --git a/components/_util/props-util.js b/components/_util/props-util.js index d98722fc2..68e8f97b2 100644 --- a/components/_util/props-util.js +++ b/components/_util/props-util.js @@ -18,5 +18,13 @@ const getOptionProps = (instance) => { return filterProps($props, $options.propsData) } -export { hasProp, filterProps, getOptionProps } +const getComponentFromProp = (instance, h, prop) => { + const temp = instance[prop] + if (temp !== undefined) { + return typeof temp === 'function' ? temp(h) : temp + } + return instance.$slots[prop] +} + +export { hasProp, filterProps, getOptionProps, getComponentFromProp } export default hasProp diff --git a/components/button/button.vue b/components/button/button.vue index 39b78a8d0..e82a87c07 100644 --- a/components/button/button.vue +++ b/components/button/button.vue @@ -2,40 +2,13 @@ import Icon from '../icon' const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/ const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar) +import buttonTypes from './buttonTypes' export default { name: 'Button', __ANT_BUTTON: true, components: { Icon }, props: { - prefixCls: { - default: 'ant-btn', - type: String, - }, - type: { - validator (value) { - return ['primary', 'danger', 'dashed', 'ghost', 'default'].includes(value) - }, - }, - htmlType: { - default: 'button', - validator (value) { - return ['button', 'submit', 'reset'].includes(value) - }, - }, - icon: String, - shape: { - validator (value) { - return ['circle', 'circle-outline'].includes(value) - }, - }, - size: { - validator (value) { - return ['small', 'large', 'default'].includes(value) - }, - }, - loading: [Boolean, Object], - disabled: Boolean, - ghost: Boolean, + ...buttonTypes, }, data () { return { diff --git a/components/button/buttonTypes.js b/components/button/buttonTypes.js new file mode 100644 index 000000000..2104f1aa7 --- /dev/null +++ b/components/button/buttonTypes.js @@ -0,0 +1,12 @@ +import PropTypes from '../_util/vue-types' +export default { + prefixCls: PropTypes.string.def('ant-btn'), + type: PropTypes.oneOf(['primary', 'danger', 'dashed', 'ghost', 'default']).def('default'), + htmlType: PropTypes.oneOf(['button', 'submit', 'reset']).def('button'), + icon: PropTypes.string, + shape: PropTypes.oneOf(['circle', 'circle-outline']), + size: PropTypes.oneOf(['small', 'large', 'default']).def('default'), + loading: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]), + disabled: PropTypes.bool, + ghost: PropTypes.bool, +} diff --git a/components/index.js b/components/index.js index 3b8f554d7..18db6ca7d 100644 --- a/components/index.js +++ b/components/index.js @@ -29,3 +29,5 @@ export { default as Tabs } from './tabs' export { default as Input } from './input' export { default as Popover } from './popover' + +export { default as Popconfirm } from './popconfirm' diff --git a/components/popconfirm/demo/basic.vue b/components/popconfirm/demo/basic.vue new file mode 100644 index 000000000..95f6bbb29 --- /dev/null +++ b/components/popconfirm/demo/basic.vue @@ -0,0 +1,29 @@ + + + diff --git a/components/popconfirm/index.vue b/components/popconfirm/index.vue index e69de29bb..9807ce386 100644 --- a/components/popconfirm/index.vue +++ b/components/popconfirm/index.vue @@ -0,0 +1,118 @@ + diff --git a/components/popconfirm/index.zh-CN.md b/components/popconfirm/index.zh-CN.md index bbdf06f3a..9442b1fac 100644 --- a/components/popconfirm/index.zh-CN.md +++ b/components/popconfirm/index.zh-CN.md @@ -17,8 +17,8 @@ title: Popconfirm | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | -| cancelText | 取消按钮文字 | string | 取消 | -| okText | 确认按钮文字 | string | 确定 | +| cancelText | 取消按钮文字 | string\|function\|slot | 取消 | +| okText | 确认按钮文字 | string\|function\|slot | 确定 | | okType | 确认按钮类型 | string | primary | | title | 确认框的描述 | string\|function\|slot | 无 | diff --git a/components/popover/index.vue b/components/popover/index.vue index da31a1806..1089d6f0f 100644 --- a/components/popover/index.vue +++ b/components/popover/index.vue @@ -2,7 +2,7 @@ import Tooltip from '../tooltip' import abstractTooltipProps from '../tooltip/abstractTooltipProps' import PropTypes from '../_util/vue-types' -import { getOptionProps } from '../_util/props-util' +import { getOptionProps, getComponentFromProp } from '../_util/props-util' export default { name: 'popover', @@ -21,26 +21,10 @@ export default { getPopupDomNode () { return this.$refs.tooltip.getPopupDomNode() }, - getOverlay (h) { - const { title, prefixCls, content, $slots } = this - return ( -
- {(title || $slots.title) && -
- {typeof title === 'function' ? title(h) : title} - {$slots.title} -
- } -
- {typeof content === 'function' ? content(h) : content} - {$slots.content} -
-
- ) - }, }, render (h) { + const { title, prefixCls, content, $slots } = this const props = getOptionProps(this) delete props.title delete props.content @@ -56,7 +40,16 @@ export default { {...tooltipProps} > {this.$slots.default} diff --git a/components/style.js b/components/style.js index 82780a16e..108572eed 100644 --- a/components/style.js +++ b/components/style.js @@ -12,5 +12,6 @@ import './tabs/style' import './input/style' import './tooltip/style' import './popover/style' +import './popconfirm/style' import './menu/style' diff --git a/contributors.md b/contributors.md index a87464170..483bcb023 100644 --- a/contributors.md +++ b/contributors.md @@ -9,7 +9,7 @@ Tabs | done Tag | done ToolTip | done Popconfirm -Popover +Popover | done Menu Carousel Mention