Files
Homarr/src/components/layout/new-header/Header.tsx

90 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-07-31 23:27:11 +02:00
import {
Box,
Center,
Flex,
Group,
Header,
Text,
UnstyledButton,
useMantineTheme,
} from '@mantine/core';
2023-07-30 01:09:10 +02:00
import { useMediaQuery } from '@mantine/hooks';
import { IconAlertTriangle } from '@tabler/icons-react';
2023-07-29 20:56:08 +02:00
import Link from 'next/link';
2023-07-30 01:09:10 +02:00
import { useScreenLargerThan } from '~/hooks/useScreenLargerThan';
2023-07-29 20:56:08 +02:00
import { Logo } from '../Logo';
import { AvatarMenu } from './AvatarMenu';
2023-07-29 20:56:08 +02:00
import { Search } from './search';
type MainHeaderProps = {
logoHref?: string;
showExperimental?: boolean;
2023-07-30 01:09:10 +02:00
headerActions?: React.ReactNode;
2023-07-30 19:45:48 +02:00
leftIcon?: React.ReactNode;
2023-07-29 20:56:08 +02:00
};
2023-07-30 01:09:10 +02:00
export const MainHeader = ({
showExperimental = false,
logoHref = '/',
headerActions,
2023-07-30 20:17:35 +02:00
leftIcon,
2023-07-30 01:09:10 +02:00
}: MainHeaderProps) => {
const { breakpoints } = useMantineTheme();
const isSmallerThanMd = useMediaQuery(`(max-width: ${breakpoints.sm})`);
const experimentalHeaderNoteHeight = isSmallerThanMd ? 50 : 30;
2023-07-31 23:27:11 +02:00
const headerBaseHeight = isSmallerThanMd ? 60 + 46 : 60;
const headerHeight = showExperimental
? headerBaseHeight + experimentalHeaderNoteHeight
: headerBaseHeight;
2023-07-30 01:09:10 +02:00
2023-07-29 20:56:08 +02:00
return (
<Header height={headerHeight} pb="sm" pt={0}>
2023-07-30 01:09:10 +02:00
<ExperimentalHeaderNote visible={showExperimental} height={experimentalHeaderNoteHeight} />
2023-07-29 20:56:08 +02:00
<Group spacing="xl" mt="xs" px="md" position="apart" noWrap>
2023-07-30 20:17:35 +02:00
<Group noWrap style={{ flex: 1 }}>
2023-07-30 19:45:48 +02:00
{leftIcon}
2023-07-30 20:17:35 +02:00
<UnstyledButton component={Link} href={logoHref}>
2023-07-30 19:45:48 +02:00
<Logo />
</UnstyledButton>
</Group>
2023-07-29 20:56:08 +02:00
2023-07-31 23:27:11 +02:00
{!isSmallerThanMd && <Search />}
2023-07-29 20:56:08 +02:00
2023-07-30 01:09:10 +02:00
<Group noWrap style={{ flex: 1 }} position="right">
<Group noWrap spacing={8}>
{headerActions}
</Group>
<AvatarMenu />
2023-07-29 20:56:08 +02:00
</Group>
</Group>
2023-07-31 23:27:11 +02:00
{isSmallerThanMd && (
<Center mt="xs" px="md">
<Search isMobile />
</Center>
)}
2023-07-29 20:56:08 +02:00
</Header>
);
};
type ExperimentalHeaderNoteProps = {
2023-07-30 01:09:10 +02:00
height?: 30 | 50;
2023-07-29 20:56:08 +02:00
visible?: boolean;
};
2023-07-30 01:09:10 +02:00
const ExperimentalHeaderNote = ({ visible = false, height = 30 }: ExperimentalHeaderNoteProps) => {
2023-07-29 20:56:08 +02:00
if (!visible) return null;
return (
2023-07-30 01:09:10 +02:00
<Box bg="red" h={height} p={3} px={6}>
2023-07-29 20:56:08 +02:00
<Flex h="100%" align="center" columnGap={7}>
2023-07-30 01:09:10 +02:00
<IconAlertTriangle color="white" size="1rem" style={{ minWidth: '1rem' }} />
<Text color="white" lineClamp={height === 30 ? 1 : 2}>
2023-07-29 20:56:08 +02:00
This is an experimental feature of Homarr. Please report any issues to the official Homarr
team.
</Text>
</Flex>
</Box>
);
};