import React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Icon, IconName, Link, useTheme2 } from '@grafana/ui'; import { css } from '@emotion/css'; export interface Props { icon?: IconName; isActive?: boolean; isDivider?: boolean; onClick?: () => void; styleOverrides?: string; target?: HTMLAnchorElement['target']; text: string; url?: string; adjustHeightForBorder?: boolean; isMobile?: boolean; } export function NavBarMenuItem({ icon, isActive, isDivider, onClick, styleOverrides, target, text, url, isMobile = false, }: Props) { const theme = useTheme2(); const styles = getStyles(theme, isActive, styleOverrides); const linkContent = (
{icon && } {text}
{target === '_blank' && ( )}
); let element = ( ); if (url) { element = !target && url.startsWith('/') ? ( {linkContent} ) : ( {linkContent} ); } if (isMobile) { return isDivider ? (
  • ) : (
  • {element}
  • ); } return isDivider ? (
    ) : ( <>{element} ); } NavBarMenuItem.displayName = 'NavBarMenuItem'; const getStyles = (theme: GrafanaTheme2, isActive: Props['isActive'], styleOverrides: Props['styleOverrides']) => ({ divider: css` border-bottom: 1px solid ${theme.colors.border.weak}; height: 1px; margin: ${theme.spacing(1)} 0; overflow: hidden; `, element: css` align-items: center; background: none; border: none; color: ${isActive ? theme.colors.text.primary : theme.colors.text.secondary}; display: flex; font-size: inherit; height: 100%; padding: 5px 12px 5px 10px; position: relative; text-align: left; white-space: nowrap; width: 100%; &:hover, &:focus-visible { background-color: ${theme.colors.action.hover}; color: ${theme.colors.text.primary}; } &:focus-visible { box-shadow: none; outline: 2px solid ${theme.colors.primary.main}; outline-offset: -2px; transition: none; } &::before { display: ${isActive ? 'block' : 'none'}; content: ' '; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; border-radius: 2px; background-image: ${theme.colors.gradients.brandVertical}; } ${styleOverrides}; `, externalLinkIcon: css` color: ${theme.colors.text.secondary}; margin-left: ${theme.spacing(1)}; `, icon: css` margin-right: ${theme.spacing(1)}; `, linkContent: css` display: flex; flex: 1; flex-direction: row; justify-content: space-between; `, });