1- import React , { MouseEvent , useCallback } from 'react' ;
1+ import React , { MouseEvent , useCallback , useRef } from 'react' ;
22
33import { Pin , PinFill } from '@gravity-ui/icons' ;
44import { Button , Icon } from '@gravity-ui/uikit' ;
55
6- import { MenuItem } from '../../types' ;
6+ import { MakeItemParams , MenuItem } from '../../types' ;
77import { block } from '../../utils/cn' ;
88
99import './AllPagesListItem.scss' ;
@@ -21,6 +21,8 @@ interface AllPagesListItemProps {
2121
2222export const AllPagesListItem : React . FC < AllPagesListItemProps > = ( props ) => {
2323 const { item, editMode, onToggle} = props ;
24+ const ref = useRef < HTMLAnchorElement & HTMLButtonElement > ( null ) ;
25+
2426 const onPinButtonClick = useCallback (
2527 ( e : MouseEvent < HTMLButtonElement | HTMLAnchorElement > ) => {
2628 e . stopPropagation ( ) ;
@@ -39,20 +41,36 @@ export const AllPagesListItem: React.FC<AllPagesListItemProps> = (props) => {
3941
4042 const [ Tag , tagProps ] = item . link ? [ 'a' as const , { href : item . link } ] : [ 'button' as const , { } ] ;
4143
42- return (
43- < Tag { ...tagProps } className = { b ( ) } onClick = { onItemClick } >
44- { item . icon ? (
45- < Icon className = { b ( 'icon' ) } data = { item . icon } size = { item . iconSize } />
46- ) : null }
47- < span className = { b ( 'text' ) } > { item . title } </ span >
48- { editMode && ! item . preventUserRemoving && (
49- < Button
50- onClick = { onPinButtonClick }
51- view = { item . hidden ? 'flat-secondary' : 'flat-action' }
52- >
53- < Button . Icon > { item . hidden ? < Pin /> : < PinFill /> } </ Button . Icon >
54- </ Button >
55- ) }
56- </ Tag >
44+ const makeNode = useCallback (
45+ ( params : MakeItemParams ) => {
46+ return (
47+ < Tag { ...tagProps } className = { b ( ) } onClick = { onItemClick } ref = { ref } >
48+ { params . icon }
49+ < span className = { b ( 'text' ) } > { params . title } </ span >
50+ { editMode && ! item . preventUserRemoving && (
51+ < Button
52+ onClick = { onPinButtonClick }
53+ view = { item . hidden ? 'flat-secondary' : 'flat-action' }
54+ >
55+ < Button . Icon > { item . hidden ? < Pin /> : < PinFill /> } </ Button . Icon >
56+ </ Button >
57+ ) }
58+ </ Tag >
59+ ) ;
60+ } ,
61+ [ Tag , tagProps , onItemClick , editMode , item , onPinButtonClick ] ,
5762 ) ;
63+
64+ const iconNode = item . icon ? (
65+ < Icon className = { b ( 'icon' ) } data = { item . icon } size = { item . iconSize } />
66+ ) : null ;
67+ const titleNode = item . title ;
68+ const params : MakeItemParams = { icon : iconNode , title : titleNode } ;
69+ const opts = { collapsed : false , compact : false , item, ref} ;
70+
71+ if ( typeof item . itemWrapper === 'function' ) {
72+ return item . itemWrapper ( params , makeNode , opts ) as React . ReactElement ;
73+ }
74+
75+ return makeNode ( params ) ;
5876} ;
0 commit comments