1- import React , { MouseEventHandler , useCallback , useRef } from 'react' ;
1+ import React from 'react' ;
22
3- import { Popup , Portal } from '@gravity-ui/uikit' ;
3+ import { Portal } from '@gravity-ui/uikit' ;
44
55import Foldable from '../../../components/Foldable/Foldable' ;
6- import { NavigationDropdownItem , NavigationItemModel , NavigationItemType } from '../../../models' ;
6+ import { NavigationItemModel } from '../../../models' ;
77import { block } from '../../../utils' ;
88import { ItemColumnName } from '../../constants' ;
99import { getItemClickHandler } from '../../utils' ;
@@ -13,42 +13,7 @@ import './MobileNavigation.scss';
1313
1414const b = block ( 'mobile-navigation' ) ;
1515
16- // interface MobileNavigationDropdownProps {
17- // data: NavigationDropdownItem;
18- // isOpened?: boolean;
19- // onItemClick?: MouseEventHandler;
20- // onToggle?: MouseEventHandler;
21- // }
22-
23- // const MobileNavigationDropdown: React.FC<MobileNavigationDropdownProps> = ({
24- // data,
25- // onItemClick,
26- // onToggle,
27- // isOpened = false,
28- // }) => {
29- // const ref = useRef(null);
30-
31- // return (
32- // <div ref={ref} className={b('dropdown')}>
33- // <NavigationItem data={data} onClick={onToggle} isOpened={isOpened} />
34- // {isOpened && (
35- // <Popup anchorRef={ref} open={isOpened} className={b('popup')}>
36- // {data.items.map((item) => (
37- // <NavigationItem
38- // key={item.text}
39- // data={item}
40- // className={b('dropdown-item')}
41- // onClick={onItemClick}
42- // />
43- // ))}
44- // </Popup>
45- // )}
46- // </div>
47- // );
48- // };
49-
50- interface MobileNavigationItemProps
51- extends Pick < MobileNavigationProps , 'onActiveItemChange' | 'onClose' > {
16+ interface MobileNavigationItemProps extends Pick < MobileNavigationProps , 'onActiveItemChange' > {
5217 item : NavigationItemModel ;
5318 column : ItemColumnName ;
5419 index : number ;
@@ -64,48 +29,13 @@ const MobileNavigationItem = ({
6429 activeItemId,
6530 onActiveItemChange,
6631 column,
67- onClose,
6832 hidePopup,
6933} : MobileNavigationItemProps ) => {
70- // const id = `${column}-${index}`;
71- // const isActive = id === activeItemId && isOpened;
72- // const toggleActive: MouseEventHandler = useCallback(
73- // (e) => {
74- // e.stopPropagation();
75-
76- // if (onActiveItemChange) {
77- // onActiveItemChange(isActive ? undefined : `${column}-${index}`);
78- // }
79- // },
80- // [onActiveItemChange, isActive, column, index],
81- // );
82-
83- // const onItemClick: MouseEventHandler = useCallback(
84- // (e) => {
85- // toggleActive(e);
86- // onClose();
87- // },
88- // [toggleActive, onClose],
89- // );
90-
91- // return (
92- // <li key={index} className={b('rows-item')}>
93- // {item.type === NavigationItemType.Dropdown ? (
94- // <MobileNavigationDropdown
95- // data={item}
96- // onToggle={toggleActive}
97- // isOpened={isActive}
98- // onItemClick={onItemClick}
99- // />
100- // ) : (
101- // <NavigationItem data={item} onClick={onItemClick} />
102- // )}
103- // </li>
104- // );
105- const id = `${ ItemColumnName . Left } -${ index } ` ;
34+ const id = `${ column } -${ index } ` ;
10635 const isActive = id === activeItemId ;
36+
10737 const onClick = getItemClickHandler ( {
108- column : ItemColumnName . Left ,
38+ column,
10939 index,
11040 activeItemId,
11141 onActiveItemChange,
@@ -118,8 +48,10 @@ const MobileNavigationItem = ({
11848 data = { item }
11949 onClick = { onClick }
12050 isActive = { isActive }
51+ isOpened = { isOpened }
12152 hidePopup = { hidePopup }
12253 isTopLevel = { true }
54+ isMobile = { true }
12355 />
12456 ) ;
12557} ;
@@ -130,7 +62,6 @@ export interface MobileNavigationProps {
13062 topItems ?: NavigationItemModel [ ] ;
13163 bottomItems ?: NavigationItemModel [ ] ;
13264 activeItemId ?: string ;
133- onClose : ( ) => void ;
13465 onActiveItemChange : ( id ?: string ) => void ;
13566 hidePopup : ( ) => void ;
13667}
@@ -140,7 +71,7 @@ const MobileNavigation: React.FC<MobileNavigationProps> = (props) => {
14071 return null ;
14172 }
14273
143- const { isOpened, topItems, bottomItems, activeItemId, onActiveItemChange, onClose , hidePopup} = props ;
74+ const { isOpened, topItems, bottomItems, activeItemId, onActiveItemChange, hidePopup} = props ;
14475
14576 return (
14677 < Portal >
@@ -155,7 +86,6 @@ const MobileNavigation: React.FC<MobileNavigationProps> = (props) => {
15586 index = { index }
15687 isOpened = { isOpened }
15788 activeItemId = { activeItemId }
158- onClose = { onClose }
15989 onActiveItemChange = { onActiveItemChange }
16090 hidePopup = { hidePopup }
16191 />
@@ -170,7 +100,6 @@ const MobileNavigation: React.FC<MobileNavigationProps> = (props) => {
170100 index = { index }
171101 isOpened = { isOpened }
172102 activeItemId = { activeItemId }
173- onClose = { onClose }
174103 onActiveItemChange = { onActiveItemChange }
175104 hidePopup = { hidePopup }
176105 />
0 commit comments