|
1 | 1 | import React, {MouseEvent, useCallback, useMemo, useState} from 'react'; |
2 | 2 |
|
3 | | -import _ from 'lodash'; |
4 | | - |
5 | 3 | import Control from '../../../components/Control/Control'; |
6 | 4 | import OutsideClick from '../../../components/OutsideClick/OutsideClick'; |
7 | 5 | import {Col, Grid, Row} from '../../../grid'; |
8 | 6 | import {NavigationClose, NavigationOpen} from '../../../icons'; |
9 | 7 | import { |
10 | 8 | HeaderData, |
| 9 | + NavigationButtonItem, |
| 10 | + NavigationDropdownItem, |
11 | 11 | NavigationItemBase, |
12 | 12 | NavigationItemModel, |
| 13 | + NavigationItemType, |
| 14 | + NavigationLinkItem, |
13 | 15 | ThemedNavigationLogoData, |
14 | 16 | } from '../../../models'; |
15 | 17 | import {block} from '../../../utils'; |
@@ -59,17 +61,30 @@ const MobileMenuButton: React.FC<MobileMenuButtonProps> = ({ |
59 | 61 |
|
60 | 62 | const iconSizeKey: keyof NavigationItemBase = 'iconSize'; |
61 | 63 |
|
| 64 | +const isButtonItem = (item: NavigationItemModel): item is NavigationButtonItem => |
| 65 | + item.type === NavigationItemType.Button; |
| 66 | + |
| 67 | +const isDropdownItem = (item: NavigationItemModel): item is NavigationDropdownItem => |
| 68 | + item.type === NavigationItemType.Dropdown; |
| 69 | + |
62 | 70 | export const Header: React.FC<HeaderProps> = ({data, logo}) => { |
63 | 71 | const {leftItems, rightItems, iconSize = 20} = data; |
64 | 72 | const [isSidebarOpened, setIsSidebarOpened] = useState(false); |
65 | 73 | const [activeItemId, setactiveItemId] = useState<string | undefined>(undefined); |
66 | 74 |
|
67 | 75 | const getNavigationItemWithIconSize = useCallback( |
68 | 76 | (item: NavigationItemModel) => { |
69 | | - if (!(iconSizeKey in item)) { |
70 | | - return {...item, iconSize}; |
| 77 | + const newItem = {...item}; |
| 78 | + if ('items' in newItem && isDropdownItem(newItem)) { |
| 79 | + newItem.items = newItem.items.map( |
| 80 | + getNavigationItemWithIconSize, |
| 81 | + ) as NavigationLinkItem[]; |
| 82 | + } |
| 83 | + |
| 84 | + if (!(iconSizeKey in newItem) && !isButtonItem(newItem)) { |
| 85 | + newItem.iconSize = iconSize; |
71 | 86 | } |
72 | | - return item; |
| 87 | + return newItem; |
73 | 88 | }, |
74 | 89 | [iconSize], |
75 | 90 | ); |
|
0 commit comments