@ -23,8 +23,9 @@ const NavBarDropdown = ({
reverseDirection = false ,
subtitleText ,
} : Props ) = > {
const filteredItems = items . filter ( ( item ) = > ! item . hideFromMenu ) ;
const theme = useTheme2 ( ) ;
const styles = getStyles ( theme , reverseDirection ) ;
const styles = getStyles ( theme , reverseDirection , filteredItems ) ;
let header = (
< button onClick = { onHeaderClick } className = { styles . header } >
@ -47,19 +48,17 @@ const NavBarDropdown = ({
return (
< ul className = { ` ${ styles . menu } dropdown-menu dropdown-menu--sidemenu ` } role = "menu" >
< li > { header } < / li >
{ items
. filter ( ( item ) = > ! item . hideFromMenu )
. map ( ( child , index ) = > (
< DropdownChild
key = { ` ${ child . url } - ${ index } ` }
isDivider = { child . divider }
icon = { child . icon as IconName }
onClick = { child . onClick }
target = { child . target }
text = { child . text }
url = { child . url }
/ >
) ) }
{ filteredItems . map ( ( child , index ) = > (
< DropdownChild
key = { ` ${ child . url } - ${ index } ` }
isDivider = { child . divider }
icon = { child . icon as IconName }
onClick = { child . onClick }
target = { child . target }
text = { child . text }
url = { child . url }
/ >
) ) }
{ subtitleText && < li className = { styles . subtitle } > { subtitleText } < / li > }
< / ul >
) ;
@ -67,52 +66,62 @@ const NavBarDropdown = ({
export default NavBarDropdown ;
const getStyles = ( theme : GrafanaTheme2 , reverseDirection : Props [ 'reverseDirection' ] ) = > ( {
header : css `
background - color : $ { theme . colors . background . secondary } ;
border : none ;
color : $ { theme . colors . text . primary } ;
font - size : $ { theme . typography . h4 . fontSize } ;
font - weight : $ { theme . typography . h4 . fontWeight } ;
padding : $ { theme . spacing ( 1 ) } $ { theme . spacing ( 1 ) } $ { theme . spacing ( 1 ) } $ { theme . spacing ( 2 ) } ! important ;
white - space : nowrap ;
width : 100 % ;
const getStyles = (
theme : GrafanaTheme2 ,
reverseDirection : Props [ 'reverseDirection' ] ,
filteredItems : Props [ 'items' ]
) = > {
const adjustHeightForBorder = filteredItems ! . length === 0 ;
& : hover {
background - color : $ { theme . colors . action . hover } ;
}
return {
header : css `
background - color : $ { theme . colors . background . secondary } ;
border : none ;
color : $ { theme . colors . text . primary } ;
height : $ { theme . components . sidemenu . width - ( adjustHeightForBorder ? 2 : 1 ) } px ;
font - size : $ { theme . typography . h4 . fontSize } ;
font - weight : $ { theme . typography . h4 . fontWeight } ;
padding : $ { theme . spacing ( 1 ) } $ { theme . spacing ( 1 ) } $ { theme . spacing ( 1 ) } $ { theme . spacing ( 2 ) } ! important ;
white - space : nowrap ;
width : 100 % ;
& : hover {
background - color : $ { theme . colors . action . hover } ;
}
. sidemenu - open -- xs & {
display : flex ;
font - size : $ { theme . typography . body . fontSize } ;
font - weight : $ { theme . typography . body . fontWeight } ;
padding - left : $ { theme . spacing ( 1 ) } ! important ;
}
` ,
menu : css `
flex - direction : $ { reverseDirection ? 'column-reverse' : 'column' } ;
. sidemenu - open -- xs & {
display : flex ;
font - size : $ { theme . typography . body . fontSize } ;
font - weight : $ { theme . typography . body . fontWeight } ;
padding - left : $ { theme . spacing ( 1 ) } ! important ;
}
` ,
menu : css `
border : 1px solid $ { theme . components . panel . borderColor } ;
flex - direction : $ { reverseDirection ? 'column-reverse' : 'column' } ;
. sidemenu - open -- xs & {
display : flex ;
flex - direction : column ;
float : none ;
. sidemenu - open -- xs & {
display : flex ;
flex - direction : column ;
float : none ;
margin - bottom : $ { theme . spacing ( 1 ) } ;
position : unset ;
width : 100 % ;
}
` ,
subtitle : css `
border - bottom : 1px solid $ { theme . colors . border . weak } ;
color : $ { theme . colors . text . secondary } ;
font - size : $ { theme . typography . bodySmall . fontSize } ;
font - weight : $ { theme . typography . bodySmall . fontWeight } ;
margin - bottom : $ { theme . spacing ( 1 ) } ;
position : unset ;
width : 100 % ;
}
` ,
subtitle : css `
border - bottom : 1px solid $ { theme . colors . border . weak } ;
color : $ { theme . colors . text . secondary } ;
font - size : $ { theme . typography . bodySmall . fontSize } ;
font - weight : $ { theme . typography . bodySmall . fontWeight } ;
margin - bottom : $ { theme . spacing ( 1 ) } ;
padding : $ { theme . spacing ( 1 ) } $ { theme . spacing ( 2 ) } $ { theme . spacing ( 1 ) } ;
white - space : nowrap ;
padding : $ { theme . spacing ( 1 ) } $ { theme . spacing ( 2 ) } $ { theme . spacing ( 1 ) } ;
white - space : nowrap ;
. sidemenu - open -- xs & {
border - bottom : none ;
margin - bottom : 0 ;
}
` ,
} ) ;
. sidemenu - open -- xs & {
border - bottom : none ;
margin - bottom : 0 ;
}
` ,
} ;
} ;