1- import type { CSSProperties , ExtractPropTypes } from 'vue' ;
1+ import type { ComponentPublicInstance , CSSProperties , ExtractPropTypes , PropType } from 'vue' ;
22import {
33 defineComponent ,
44 ref ,
@@ -10,7 +10,6 @@ import {
1010 onUnmounted ,
1111 onUpdated ,
1212} from 'vue' ;
13- import PropTypes from '../_util/vue-types' ;
1413import classNames from '../_util/classNames' ;
1514import ResizeObserver from '../vc-resize-observer' ;
1615import throttleByAnimationFrame from '../_util/throttleByAnimationFrame' ;
@@ -41,28 +40,41 @@ export interface AffixState {
4140}
4241
4342// Affix
44- export const affixProps = {
43+ export const affixProps = ( ) => ( {
4544 /**
4645 * 距离窗口顶部达到指定偏移量后触发
4746 */
48- offsetTop : PropTypes . number ,
47+ offsetTop : Number ,
4948 /** 距离窗口底部达到指定偏移量后触发 */
50- offsetBottom : PropTypes . number ,
49+ offsetBottom : Number ,
5150 /** 固定状态改变时触发的回调函数 */
5251 // onChange?: (affixed?: boolean) => void;
5352 /** 设置 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 ;
5867} ;
5968
60- export type AffixProps = Partial < ExtractPropTypes < typeof affixProps > > ;
69+ export type AffixExpose = {
70+ updatePosition : ( ...args : any [ ] ) => void ;
71+ lazyUpdatePosition : ( ...args : any [ ] ) => void ;
72+ } ;
6173
74+ export type AffixInstance = ComponentPublicInstance < AffixProps , AffixExpose > ;
6275const Affix = defineComponent ( {
6376 name : 'AAffix' ,
64- props : affixProps ,
65- emits : [ 'change' , 'testUpdatePosition' ] ,
77+ props : affixProps ( ) ,
6678 setup ( props , { slots, emit, expose } ) {
6779 const placeholderNode = ref ( ) ;
6880 const fixedNode = ref ( ) ;
@@ -222,7 +234,14 @@ const Affix = defineComponent({
222234 const className = classNames ( {
223235 [ prefixCls . value ] : affixStyle ,
224236 } ) ;
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+ ] ) ;
226245 return (
227246 < ResizeObserver onResize = { updatePosition } >
228247 < div { ...restProps } style = { placeholderStyle } ref = { placeholderNode } >
0 commit comments