11import type { CSSProperties , ExtractPropTypes , PropType } from 'vue' ;
22import {
3- watch ,
43 defineComponent ,
54 nextTick ,
65 onBeforeUnmount ,
@@ -19,18 +18,11 @@ import getScroll from '../_util/getScroll';
1918import useConfigInject from '../config-provider/hooks/useConfigInject' ;
2019import useProvideAnchor from './context' ;
2120import useStyle from './style' ;
22- import type { AnchorLinkProps } from './AnchorLink' ;
21+ import type { AnchorLinkItemProps } from './AnchorLink' ;
2322import AnchorLink from './AnchorLink' ;
24- import type { Key } from '../_util/type' ;
2523import PropTypes from '../_util/vue-types' ;
2624import 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' ;
3426
3527export type AnchorDirection = 'vertical' | 'horizontal' ;
3628
@@ -76,10 +68,7 @@ export const anchorProps = () => ({
7668 wrapperStyle : { type : Object as PropType < CSSProperties > , default : undefined as CSSProperties } ,
7769 getCurrentAnchor : Function as PropType < ( activeLink : string ) => string > ,
7870 targetOffset : Number ,
79- items : {
80- type : Array as PropType < AnchorLinkItemProps [ ] > ,
81- default : undefined as AnchorLinkItemProps [ ] ,
82- } ,
71+ items : arrayType < AnchorLinkItemProps [ ] > ( ) ,
8372 direction : PropTypes . oneOf ( [ 'vertical' , 'horizontal' ] as AnchorDirection [ ] ) . def ( 'vertical' ) ,
8473 onChange : Function as PropType < ( currentActiveLink : string ) => void > ,
8574 onClick : Function as PropType < ( e : MouseEvent , link : { title : any ; href : string } ) => void > ,
@@ -105,7 +94,7 @@ export default defineComponent({
10594
10695 if ( process . env . NODE_ENV !== 'production' ) {
10796 devWarning (
108- typeof slots . default !== 'function' ,
97+ props . items && typeof slots . default !== 'function' ,
10998 'Anchor' ,
11099 '`Anchor children` is deprecated. Please use `items` instead.' ,
111100 ) ;
@@ -274,17 +263,25 @@ export default defineComponent({
274263 updateInk ( ) ;
275264 } ) ;
276265
277- watch ( [ anchorDirection , getCurrentAnchor , state . links , activeLink ] , ( ) => {
278- updateInk ( ) ;
279- } ) ;
280-
281266 const createNestedLink = ( options ?: AnchorLinkItemProps [ ] ) =>
282267 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+ } )
288285 : null ;
289286
290287 const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
0 commit comments