1
1
import type { CSSProperties , ExtractPropTypes , PropType } from 'vue' ;
2
2
import {
3
- watch ,
4
3
defineComponent ,
5
4
nextTick ,
6
5
onBeforeUnmount ,
@@ -19,18 +18,11 @@ import getScroll from '../_util/getScroll';
19
18
import useConfigInject from '../config-provider/hooks/useConfigInject' ;
20
19
import useProvideAnchor from './context' ;
21
20
import useStyle from './style' ;
22
- import type { AnchorLinkProps } from './AnchorLink' ;
21
+ import type { AnchorLinkItemProps } from './AnchorLink' ;
23
22
import AnchorLink from './AnchorLink' ;
24
- import type { Key } from '../_util/type' ;
25
23
import PropTypes from '../_util/vue-types' ;
26
24
import devWarning from '../vc-util/devWarning' ;
27
-
28
- export interface AnchorLinkItemProps extends AnchorLinkProps {
29
- key : Key ;
30
- class ?: String ;
31
- style ?: CSSProperties ;
32
- children ?: AnchorLinkItemProps [ ] ;
33
- }
25
+ import { arrayType } from '../_util/type' ;
34
26
35
27
export type AnchorDirection = 'vertical' | 'horizontal' ;
36
28
@@ -76,10 +68,7 @@ export const anchorProps = () => ({
76
68
wrapperStyle : { type : Object as PropType < CSSProperties > , default : undefined as CSSProperties } ,
77
69
getCurrentAnchor : Function as PropType < ( activeLink : string ) => string > ,
78
70
targetOffset : Number ,
79
- items : {
80
- type : Array as PropType < AnchorLinkItemProps [ ] > ,
81
- default : undefined as AnchorLinkItemProps [ ] ,
82
- } ,
71
+ items : arrayType < AnchorLinkItemProps [ ] > ( ) ,
83
72
direction : PropTypes . oneOf ( [ 'vertical' , 'horizontal' ] as AnchorDirection [ ] ) . def ( 'vertical' ) ,
84
73
onChange : Function as PropType < ( currentActiveLink : string ) => void > ,
85
74
onClick : Function as PropType < ( e : MouseEvent , link : { title : any ; href : string } ) => void > ,
@@ -105,7 +94,7 @@ export default defineComponent({
105
94
106
95
if ( process . env . NODE_ENV !== 'production' ) {
107
96
devWarning (
108
- typeof slots . default !== 'function' ,
97
+ props . items && typeof slots . default !== 'function' ,
109
98
'Anchor' ,
110
99
'`Anchor children` is deprecated. Please use `items` instead.' ,
111
100
) ;
@@ -274,17 +263,25 @@ export default defineComponent({
274
263
updateInk ( ) ;
275
264
} ) ;
276
265
277
- watch ( [ anchorDirection , getCurrentAnchor , state . links , activeLink ] , ( ) => {
278
- updateInk ( ) ;
279
- } ) ;
280
-
281
266
const createNestedLink = ( options ?: AnchorLinkItemProps [ ] ) =>
282
267
Array . isArray ( options )
283
- ? options . map ( item => (
284
- < AnchorLink { ...item } key = { item . key } >
285
- { anchorDirection . value === 'vertical' ? createNestedLink ( item . children ) : null }
286
- </ AnchorLink >
287
- ) )
268
+ ? options . map ( option => {
269
+ const { children, key, href, target, class : cls , style, title } = option ;
270
+ return (
271
+ < AnchorLink
272
+ key = { key }
273
+ href = { href }
274
+ target = { target }
275
+ class = { cls }
276
+ style = { style }
277
+ title = { title }
278
+ customTitleProps = { option }
279
+ v-slots = { { customTitle : slots . customTitle } }
280
+ >
281
+ { anchorDirection . value === 'vertical' ? createNestedLink ( children ) : null }
282
+ </ AnchorLink >
283
+ ) ;
284
+ } )
288
285
: null ;
289
286
290
287
const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
0 commit comments