diff --git a/components/back-top/backTopTypes.js b/components/back-top/backTopTypes.js new file mode 100644 index 0000000000..b8cbd4ed32 --- /dev/null +++ b/components/back-top/backTopTypes.js @@ -0,0 +1,9 @@ +import PropTypes from '../_util/vue-types'; +export default () => ({ + visibilityHeight: PropTypes.number, + // onClick?: React.MouseEventHandler; + target: PropTypes.func, + prefixCls: PropTypes.string, + onClick: PropTypes.func, + // visible: PropTypes.bool, // Only for test. Don't use it. +}); diff --git a/components/back-top/index.jsx b/components/back-top/index.jsx index cd491ed63e..6a6c3718b8 100644 --- a/components/back-top/index.jsx +++ b/components/back-top/index.jsx @@ -1,34 +1,30 @@ import PropTypes from '../_util/vue-types'; +import backTopTypes from './backTopTypes'; import addEventListener from '../vc-util/Dom/addEventListener'; import getScroll from '../_util/getScroll'; import BaseMixin from '../_util/BaseMixin'; import getTransitionProps from '../_util/getTransitionProps'; import { ConfigConsumerProps } from '../config-provider'; -import Base from '../base'; -import { getListeners } from '../_util/props-util'; import scrollTo from '../_util/scrollTo'; +import { inject } from 'vue'; function getDefaultTarget() { return window; } -const BackTopProps = { - visibilityHeight: PropTypes.number, - // onClick?: React.MouseEventHandler; - target: PropTypes.func, - prefixCls: PropTypes.string, - // visible: PropTypes.bool, // Only for test. Don't use it. -}; +const props = backTopTypes(); const BackTop = { name: 'ABackTop', mixins: [BaseMixin], props: { - ...BackTopProps, + ...props, visibilityHeight: PropTypes.number.def(400), }, - inject: { - configProvider: { default: () => ConfigConsumerProps }, + setup() { + return { + configProvider: inject('configProvider', ConfigConsumerProps), + }; }, data() { this.scrollEvent = null; @@ -88,15 +84,12 @@ const BackTop = { ); const divProps = { - on: { - ...getListeners(this), - click: this.scrollToTop, - }, + onClick: this.scrollToTop, class: prefixCls, }; const backTopBtn = this.visible ? ( -
{$slots.default || defaultElement}
+
{($slots.default && $slots.default()) || defaultElement}
) : null; const transitionProps = getTransitionProps('fade'); return {backTopBtn}; @@ -104,9 +97,8 @@ const BackTop = { }; /* istanbul ignore next */ -BackTop.install = function(Vue) { - Vue.use(Base); - Vue.component(BackTop.name, BackTop); +BackTop.install = function(app) { + app.component(BackTop.name, BackTop); }; export default BackTop; diff --git a/examples/index.js b/examples/index.js index e475fc1e8b..07f78a009c 100644 --- a/examples/index.js +++ b/examples/index.js @@ -21,6 +21,7 @@ import Col from 'ant-design-vue/col'; import Row from 'ant-design-vue/row'; import Tooltip from 'ant-design-vue/tooltip'; import Descriptions from 'ant-design-vue/descriptions'; +import BackTop from 'ant-design-vue/back-top'; import Tag from 'ant-design-vue/tag'; import 'ant-design-vue/style.js'; @@ -45,5 +46,6 @@ createApp(App) .use(Row) .use(Tooltip) .use(Descriptions) + .use(BackTop) .use(Tag) .mount('#app');