Skip to content

Commit 9e40ba6

Browse files
committed
feat: update BackTop
1 parent 237d55a commit 9e40ba6

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

components/back-top/backTopTypes.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import PropTypes from '../_util/vue-types';
2+
export default () => ({
3+
visibilityHeight: PropTypes.number,
4+
// onClick?: React.MouseEventHandler<any>;
5+
target: PropTypes.func,
6+
prefixCls: PropTypes.string,
7+
onClick: PropTypes.func,
8+
// visible: PropTypes.bool, // Only for test. Don't use it.
9+
});

components/back-top/index.jsx

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
import PropTypes from '../_util/vue-types';
2+
import backTopTypes from './backTopTypes';
23
import addEventListener from '../vc-util/Dom/addEventListener';
34
import getScroll from '../_util/getScroll';
45
import BaseMixin from '../_util/BaseMixin';
56
import getTransitionProps from '../_util/getTransitionProps';
67
import { ConfigConsumerProps } from '../config-provider';
7-
import Base from '../base';
8-
import { getListeners } from '../_util/props-util';
98
import scrollTo from '../_util/scrollTo';
9+
import { inject } from 'vue';
1010

1111
function getDefaultTarget() {
1212
return window;
1313
}
1414

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();
2216

2317
const BackTop = {
2418
name: 'ABackTop',
2519
mixins: [BaseMixin],
2620
props: {
27-
...BackTopProps,
21+
...props,
2822
visibilityHeight: PropTypes.number.def(400),
2923
},
30-
inject: {
31-
configProvider: { default: () => ConfigConsumerProps },
24+
setup() {
25+
return {
26+
configProvider: inject('configProvider', ConfigConsumerProps),
27+
};
3228
},
3329
data() {
3430
this.scrollEvent = null;
@@ -88,25 +84,21 @@ const BackTop = {
8884
</div>
8985
);
9086
const divProps = {
91-
on: {
92-
...getListeners(this),
93-
click: this.scrollToTop,
94-
},
87+
onClick: this.scrollToTop,
9588
class: prefixCls,
9689
};
9790

9891
const backTopBtn = this.visible ? (
99-
<div {...divProps}>{$slots.default || defaultElement}</div>
92+
<div {...divProps}>{($slots.default && $slots.default()) || defaultElement}</div>
10093
) : null;
10194
const transitionProps = getTransitionProps('fade');
10295
return <transition {...transitionProps}>{backTopBtn}</transition>;
10396
},
10497
};
10598

10699
/* 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);
110102
};
111103

112104
export default BackTop;

examples/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Col from 'ant-design-vue/col';
2121
import Row from 'ant-design-vue/row';
2222
import Tooltip from 'ant-design-vue/tooltip';
2323
import Descriptions from 'ant-design-vue/descriptions';
24+
import BackTop from 'ant-design-vue/back-top';
2425
import 'ant-design-vue/style.js';
2526

2627
createApp(App)
@@ -44,4 +45,5 @@ createApp(App)
4445
.use(Row)
4546
.use(Tooltip)
4647
.use(Descriptions)
48+
.use(BackTop)
4749
.mount('#app');

0 commit comments

Comments
 (0)