1
- import type { CSSProperties , ExtractPropTypes } from 'vue' ;
1
+ import type { ComponentPublicInstance , CSSProperties , ExtractPropTypes , PropType } from 'vue' ;
2
2
import {
3
3
defineComponent ,
4
4
ref ,
@@ -10,7 +10,6 @@ import {
10
10
onUnmounted ,
11
11
onUpdated ,
12
12
} from 'vue' ;
13
- import PropTypes from '../_util/vue-types' ;
14
13
import classNames from '../_util/classNames' ;
15
14
import ResizeObserver from '../vc-resize-observer' ;
16
15
import throttleByAnimationFrame from '../_util/throttleByAnimationFrame' ;
@@ -41,28 +40,41 @@ export interface AffixState {
41
40
}
42
41
43
42
// Affix
44
- export const affixProps = {
43
+ export const affixProps = ( ) => ( {
45
44
/**
46
45
* 距离窗口顶部达到指定偏移量后触发
47
46
*/
48
- offsetTop : PropTypes . number ,
47
+ offsetTop : Number ,
49
48
/** 距离窗口底部达到指定偏移量后触发 */
50
- offsetBottom : PropTypes . number ,
49
+ offsetBottom : Number ,
51
50
/** 固定状态改变时触发的回调函数 */
52
51
// onChange?: (affixed?: boolean) => void;
53
52
/** 设置 Affix 需要监听其滚动事件的元素,值为一个返回对应 DOM 元素的函数 */
54
- target : PropTypes . func . def ( getDefaultTarget ) ,
55
- prefixCls : PropTypes . string ,
56
- onChange : PropTypes . func ,
57
- onTestUpdatePosition : PropTypes . func ,
53
+ target : {
54
+ type : Function as PropType < ( ) => Window | HTMLElement | null > ,
55
+ default : getDefaultTarget ,
56
+ } ,
57
+ prefixCls : String ,
58
+ onChange : Function as PropType < AffixEmits [ 'change' ] > ,
59
+ onTestUpdatePosition : Function as PropType < AffixEmits [ 'testUpdatePosition' ] > ,
60
+ } ) ;
61
+
62
+ export type AffixProps = Partial < ExtractPropTypes < ReturnType < typeof affixProps > > > ;
63
+
64
+ export type AffixEmits = {
65
+ change : ( lastAffix : boolean ) => boolean ;
66
+ testUpdatePosition : ( ) => boolean ;
58
67
} ;
59
68
60
- export type AffixProps = Partial < ExtractPropTypes < typeof affixProps > > ;
69
+ export type AffixExpose = {
70
+ updatePosition : ( ...args : any [ ] ) => void ;
71
+ lazyUpdatePosition : ( ...args : any [ ] ) => void ;
72
+ } ;
61
73
74
+ export type AffixInstance = ComponentPublicInstance < AffixProps , AffixExpose > ;
62
75
const Affix = defineComponent ( {
63
76
name : 'AAffix' ,
64
- props : affixProps ,
65
- emits : [ 'change' , 'testUpdatePosition' ] ,
77
+ props : affixProps ( ) ,
66
78
setup ( props , { slots, emit, expose } ) {
67
79
const placeholderNode = ref ( ) ;
68
80
const fixedNode = ref ( ) ;
@@ -222,7 +234,14 @@ const Affix = defineComponent({
222
234
const className = classNames ( {
223
235
[ prefixCls . value ] : affixStyle ,
224
236
} ) ;
225
- const restProps = omit ( props , [ 'prefixCls' , 'offsetTop' , 'offsetBottom' , 'target' ] ) ;
237
+ const restProps = omit ( props , [
238
+ 'prefixCls' ,
239
+ 'offsetTop' ,
240
+ 'offsetBottom' ,
241
+ 'target' ,
242
+ 'onChange' ,
243
+ 'onTestUpdatePosition' ,
244
+ ] ) ;
226
245
return (
227
246
< ResizeObserver onResize = { updatePosition } >
228
247
< div { ...restProps } style = { placeholderStyle } ref = { placeholderNode } >
0 commit comments