1- import React , { MouseEvent , useCallback , useState } from 'react' ;
1+ import React , { MouseEvent , useCallback , useMemo , useState } from 'react' ;
22
33import _ from 'lodash' ;
44
55import Control from '../../../components/Control/Control' ;
66import OutsideClick from '../../../components/OutsideClick/OutsideClick' ;
77import { Col , Grid , Row } from '../../../grid' ;
88import { NavigationClose , NavigationOpen } from '../../../icons' ;
9- import { HeaderData , ThemedNavigationLogoData } from '../../../models' ;
9+ import {
10+ HeaderData ,
11+ NavigationItemBase ,
12+ NavigationItemModel ,
13+ ThemedNavigationLogoData ,
14+ } from '../../../models' ;
1015import { block } from '../../../utils' ;
1116import { ItemColumnName } from '../../constants' ;
1217import Logo from '../Logo/Logo' ;
@@ -52,11 +57,32 @@ const MobileMenuButton: React.FC<MobileMenuButtonProps> = ({
5257 ) ;
5358} ;
5459
60+ const iconSizeKey : keyof NavigationItemBase = 'iconSize' ;
61+
5562export const Header : React . FC < HeaderProps > = ( { data, logo} ) => {
56- const { leftItems, rightItems} = data ;
63+ const { leftItems, rightItems, iconSize = 20 } = data ;
5764 const [ isSidebarOpened , setIsSidebarOpened ] = useState ( false ) ;
5865 const [ activeItemId , setactiveItemId ] = useState < string | undefined > ( undefined ) ;
5966
67+ const getNavigationItemWithIconSize = useCallback (
68+ ( item : NavigationItemModel ) => {
69+ if ( ! ( iconSizeKey in item ) ) {
70+ return { ...item , iconSize} ;
71+ }
72+ return item ;
73+ } ,
74+ [ iconSize ] ,
75+ ) ;
76+
77+ const leftItemsWithIconSize = useMemo (
78+ ( ) => leftItems . map ( getNavigationItemWithIconSize ) ,
79+ [ getNavigationItemWithIconSize , leftItems ] ,
80+ ) ;
81+ const rightItemsWithIconSize = useMemo (
82+ ( ) => rightItems ?. map ( getNavigationItemWithIconSize ) ,
83+ [ getNavigationItemWithIconSize , rightItems ] ,
84+ ) ;
85+
6086 const onActiveItemChange = useCallback ( ( id ?: string ) => {
6187 setactiveItemId ( id ) ;
6288 } , [ ] ) ;
@@ -86,7 +112,7 @@ export const Header: React.FC<HeaderProps> = ({data, logo}) => {
86112 < div className = { b ( 'navigation-container' ) } >
87113 < Navigation
88114 className = { b ( 'navigation' ) }
89- links = { leftItems }
115+ links = { leftItemsWithIconSize }
90116 activeItemId = { activeItemId }
91117 onActiveItemChange = { onActiveItemChange }
92118 />
@@ -96,9 +122,9 @@ export const Header: React.FC<HeaderProps> = ({data, logo}) => {
96122 isSidebarOpened = { isSidebarOpened }
97123 onSidebarOpenedChange = { onSidebarOpenedChange }
98124 />
99- { rightItems && (
125+ { rightItemsWithIconSize && (
100126 < ul className = { b ( 'buttons' ) } >
101- { rightItems . map ( ( button , index ) => (
127+ { rightItemsWithIconSize . map ( ( button , index ) => (
102128 < NavigationListItem
103129 key = { index }
104130 className = { b ( 'buttons-item' ) }
0 commit comments