import * as React from 'react'; import { Group, MantineColor, Text, Title, useMantineTheme } from '@mantine/core'; import { useMediaQuery } from '@mantine/hooks'; import { useVisynAppContext } from '../VisynAppContext'; import { IAboutAppModalConfig } from './AboutAppModal'; import { BurgerMenu } from './BurgerMenu'; import { ConfigurationMenu } from './ConfigurationMenu'; import { DatavisynLogo } from './DatavisynLogo'; import { UserMenu } from './UserMenu'; export function VisynHeader({ color = 'white', backgroundColor, height = '100%', components, }: { /** * Optional color to be used for the background. If it is part of the mantine colors, it uses the primary shade, otherwise it is interpreted as CSS color. */ backgroundColor?: MantineColor; /** * Optional color to be used for the text. This must be in contrast with the given `backgroundColor`. */ color?: MantineColor; /** * Extension components to be rendered within the header. */ height?: React.CSSProperties['height']; components?: Partial<{ beforeLeft: JSX.Element; burgerMenu: JSX.Element; title: JSX.Element; afterLeft: JSX.Element; beforeCenter: JSX.Element; center: JSX.Element; afterCenter: JSX.Element; beforeRight: JSX.Element; logo: JSX.Element; userAvatar: JSX.Element; userMenu: JSX.Element; configurationMenu: JSX.Element; afterRight: JSX.Element; aboutAppModal: IAboutAppModalConfig; }>; }) { const { appName, user } = useVisynAppContext(); const largerThanSm = useMediaQuery('(min-width: 768px)'); const smallerThanMd = useMediaQuery('(max-width: 768px)'); const theme = useMantineTheme(); return ( {largerThanSm && components?.beforeLeft} {components?.burgerMenu ? : null} {components?.title === undefined ? ( <Text truncate c={color}> {appName} </Text> ) : ( components?.title )} {largerThanSm && components?.afterLeft} {largerThanSm && components?.beforeCenter} {largerThanSm && components?.center} {largerThanSm && components?.afterCenter} {largerThanSm && components?.beforeRight} {components?.logo === undefined ? : components?.logo} {components?.userAvatar === undefined ? ( user && user.name ? ( ) : null ) : ( components?.userAvatar )} : components?.logo} menu={components?.configurationMenu} aboutAppModal={components?.aboutAppModal} /> {largerThanSm && components?.afterRight} ); }