import { css, cx } from '@emotion/css'; import classNames from 'classnames'; import React, { PropsWithChildren } from 'react'; import { GrafanaTheme2, PageLayoutType } from '@grafana/data'; import { useStyles2, LinkButton, useTheme2 } from '@grafana/ui'; import config from 'app/core/config'; import { useGrafana } from 'app/core/context/GrafanaContext'; import { CommandPalette } from 'app/features/commandPalette/CommandPalette'; import { KioskMode } from 'app/types'; import { AppChromeMenu } from './AppChromeMenu'; import { MegaMenu as DockedMegaMenu } from './DockedMegaMenu/MegaMenu'; import { MegaMenu } from './MegaMenu/MegaMenu'; import { NavToolbar } from './NavToolbar/NavToolbar'; import { SectionNav } from './SectionNav/SectionNav'; import { TopSearchBar } from './TopBar/TopSearchBar'; import { TOP_BAR_LEVEL_HEIGHT } from './types'; export interface Props extends PropsWithChildren<{}> {} export function AppChrome({ children }: Props) { const { chrome } = useGrafana(); const state = chrome.useState(); const searchBarHidden = state.searchBarHidden || state.kioskMode === KioskMode.TV; const theme = useTheme2(); const styles = useStyles2(getStyles); const contentClass = cx({ [styles.content]: true, [styles.contentNoSearchBar]: searchBarHidden, [styles.contentChromeless]: state.chromeless, }); const handleMegaMenu = () => { switch (state.megaMenu) { case 'closed': chrome.setMegaMenu('open'); break; case 'open': chrome.setMegaMenu('closed'); break; case 'docked': // on large screens, clicking the button when the menu is docked should close the menu // on smaller screens, the docked menu is hidden, so clicking the button should open the menu const isLargeScreen = window.innerWidth >= theme.breakpoints.values.xl; isLargeScreen ? chrome.setMegaMenu('closed') : chrome.setMegaMenu('open'); break; } }; // Chromeless routes are without topNav, mega menu, search & command palette // We check chromeless twice here instead of having a separate path so {children} // doesn't get re-mounted when chromeless goes from true to false. return (