|
1 | 1 | import PropTypes from '../_util/vue-types';
|
| 2 | +import backTopTypes from './backTopTypes'; |
2 | 3 | import addEventListener from '../vc-util/Dom/addEventListener';
|
3 | 4 | import getScroll from '../_util/getScroll';
|
4 | 5 | import BaseMixin from '../_util/BaseMixin';
|
5 | 6 | import getTransitionProps from '../_util/getTransitionProps';
|
6 | 7 | import { ConfigConsumerProps } from '../config-provider';
|
7 |
| -import Base from '../base'; |
8 |
| -import { getListeners } from '../_util/props-util'; |
9 | 8 | import scrollTo from '../_util/scrollTo';
|
| 9 | +import { inject } from 'vue'; |
10 | 10 |
|
11 | 11 | function getDefaultTarget() {
|
12 | 12 | return window;
|
13 | 13 | }
|
14 | 14 |
|
15 |
| -const BackTopProps = { |
16 |
| - visibilityHeight: PropTypes.number, |
17 |
| - // onClick?: React.MouseEventHandler<any>; |
18 |
| - target: PropTypes.func, |
19 |
| - prefixCls: PropTypes.string, |
20 |
| - // visible: PropTypes.bool, // Only for test. Don't use it. |
21 |
| -}; |
| 15 | +const props = backTopTypes(); |
22 | 16 |
|
23 | 17 | const BackTop = {
|
24 | 18 | name: 'ABackTop',
|
25 | 19 | mixins: [BaseMixin],
|
26 | 20 | props: {
|
27 |
| - ...BackTopProps, |
| 21 | + ...props, |
28 | 22 | visibilityHeight: PropTypes.number.def(400),
|
29 | 23 | },
|
30 |
| - inject: { |
31 |
| - configProvider: { default: () => ConfigConsumerProps }, |
| 24 | + setup() { |
| 25 | + return { |
| 26 | + configProvider: inject('configProvider', ConfigConsumerProps), |
| 27 | + }; |
32 | 28 | },
|
33 | 29 | data() {
|
34 | 30 | this.scrollEvent = null;
|
@@ -88,25 +84,21 @@ const BackTop = {
|
88 | 84 | </div>
|
89 | 85 | );
|
90 | 86 | const divProps = {
|
91 |
| - on: { |
92 |
| - ...getListeners(this), |
93 |
| - click: this.scrollToTop, |
94 |
| - }, |
| 87 | + onClick: this.scrollToTop, |
95 | 88 | class: prefixCls,
|
96 | 89 | };
|
97 | 90 |
|
98 | 91 | const backTopBtn = this.visible ? (
|
99 |
| - <div {...divProps}>{$slots.default || defaultElement}</div> |
| 92 | + <div {...divProps}>{($slots.default && $slots.default()) || defaultElement}</div> |
100 | 93 | ) : null;
|
101 | 94 | const transitionProps = getTransitionProps('fade');
|
102 | 95 | return <transition {...transitionProps}>{backTopBtn}</transition>;
|
103 | 96 | },
|
104 | 97 | };
|
105 | 98 |
|
106 | 99 | /* istanbul ignore next */
|
107 |
| -BackTop.install = function(Vue) { |
108 |
| - Vue.use(Base); |
109 |
| - Vue.component(BackTop.name, BackTop); |
| 100 | +BackTop.install = function(app) { |
| 101 | + app.component(BackTop.name, BackTop); |
110 | 102 | };
|
111 | 103 |
|
112 | 104 | export default BackTop;
|
0 commit comments