import { useState, VFC } from 'react'; import useMediaQuery from '@mui/material/useMediaQuery'; import { useTheme } from '@mui/material/styles'; import { Link } from 'react-router-dom'; import { AppBar, Container, IconButton, Tooltip, styled, Theme, } from '@mui/material'; import MenuIcon from '@mui/icons-material/Menu'; import SettingsIcon from '@mui/icons-material/Settings'; import UserProfile from 'component/user/UserProfile'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import MenuBookIcon from '@mui/icons-material/MenuBook'; import { ReactComponent as UnleashLogo } from 'assets/img/logoDarkWithText.svg'; import { ReactComponent as UnleashLogoWhite } from 'assets/img/logoWithWhiteText.svg'; import { DrawerMenu } from './DrawerMenu/DrawerMenu'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import { flexRow, focusable } from 'themes/themeStyles'; import { NavigationMenu } from './NavigationMenu/NavigationMenu'; import { getRoutes, getCondensedRoutes } from 'component/menu/routes'; import { DarkModeOutlined, KeyboardArrowDown, LightModeOutlined, } from '@mui/icons-material'; import { filterByConfig, mapRouteLink } from 'component/common/util'; import { useId } from 'hooks/useId'; import { ThemeMode } from 'component/common/ThemeMode/ThemeMode'; import { useThemeMode } from 'hooks/useThemeMode'; import { Notifications } from 'component/common/Notifications/Notifications'; import { useAdminRoutes } from 'component/admin/useAdminRoutes'; import InviteLinkButton from './InviteLink/InviteLinkButton/InviteLinkButton'; import { useUiFlag } from 'hooks/useUiFlag'; const StyledHeader = styled(AppBar)(({ theme }) => ({ backgroundColor: theme.palette.background.paper, padding: theme.spacing(1), boxShadow: 'none', position: 'relative', zIndex: 300, })); const StyledContainer = styled(Container)(() => ({ display: 'flex', alignItems: 'center', maxWidth: 1280, '&&&': { padding: 0 }, })); const StyledUserContainer = styled('div')({ marginLeft: 'auto', display: 'flex', alignItems: 'center', }); const StyledNav = styled('nav')({ display: 'flex', alignItems: 'center', flexGrow: 1, }); const StyledUnleashLogoWhite = styled(UnleashLogoWhite)({ width: '150px' }); const StyledUnleashLogo = styled(UnleashLogo)({ width: '150px' }); const StyledLinks = styled('div')(({ theme }) => ({ display: 'flex', justifyContent: 'center', marginLeft: theme.spacing(3), '& a': { textDecoration: 'none', color: 'inherit', marginRight: theme.spacing(3), display: 'flex', alignItems: 'center', }, })); const StyledAdvancedNavButton = styled('button')(({ theme }) => ({ ...focusable(theme), border: 'none', background: 'transparent', height: '100%', display: 'flex', fontSize: theme.fontSizes.bodySize, fontFamily: theme.typography.fontFamily, alignItems: 'center', color: 'inherit', cursor: 'pointer', })); const styledIconProps = (theme: Theme) => ({ color: theme.palette.neutral.main, }); const StyledLink = styled(Link)(({ theme }) => focusable(theme)); const StyledIconButton = styled(IconButton)<{ component?: 'a' | 'button'; href?: string; target?: string; }>(({ theme }) => ({ borderRadius: 100, '&:focus-visible': { outlineStyle: 'solid', outlineWidth: 2, outlineColor: theme.palette.primary.main, borderRadius: '100%', }, })); const Header: VFC = () => { const { onSetThemeMode, themeMode } = useThemeMode(); const theme = useTheme(); const adminId = useId(); const configId = useId(); const [adminRef, setAdminRef] = useState(null); const [configRef, setConfigRef] = useState(null); const disableNotifications = useUiFlag('disableNotifications'); const hasSearch = useUiFlag('featureSearchFrontend'); const { uiConfig, isOss } = useUiConfig(); const smallScreen = useMediaQuery(theme.breakpoints.down('md')); const [openDrawer, setOpenDrawer] = useState(false); const toggleDrawer = () => setOpenDrawer((prev) => !prev); const onAdminClose = () => setAdminRef(null); const onConfigureClose = () => setConfigRef(null); const routes = getRoutes(); const adminRoutes = useAdminRoutes(); const filteredMainRoutes = { mainNavRoutes: getCondensedRoutes(routes.mainNavRoutes) .filter(filterByConfig(uiConfig)) .map(mapRouteLink), mobileRoutes: getCondensedRoutes(routes.mobileRoutes) .filter(filterByConfig(uiConfig)) .map(mapRouteLink), adminRoutes, }; if (smallScreen) { return ( theme.palette.text.primary, }} onClick={toggleDrawer} aria-controls='header-drawer' aria-expanded={openDrawer} size='large' > ); } return ( } lightmode={ } /> Projects Search } elseShow={ Feature toggles } /> Playground setConfigRef(e.currentTarget)} aria-controls={configRef ? configId : undefined} aria-expanded={Boolean(configRef)} > Configure } elseShow={} /> } /> setAdminRef(e.currentTarget)} aria-controls={adminRef ? adminId : undefined} aria-expanded={Boolean(adminRef)} size='large' > {' '} ); }; export default Header;