Simple header
A top bar with a logo and a row of links that turns into a menu button on phones.
A top bar with a logo and a row of links that turns into a menu button on phones.
npm install @mantine/core @mantine/hooks
First time with Mantine UI? Set it up once.
/**
* Component from Mantine UI, https://ui.mantine.dev
* MIT License, Copyright (c) 2022 Vitaly Rtischev. Full text: https://github.com/mantinedev/ui.mantine.dev/blob/master/LICENCE
* Changed for Tastebud: the Mantine logo is a plain block and the word Studio.
*/
import { useState } from 'react';
import { Box, Burger, Container, Divider, Drawer, Group, ScrollArea, Text } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import classes from './HeaderSimple.module.css';
const links = [
{ link: '/about', label: 'Features' },
{ link: '/pricing', label: 'Pricing' },
{ link: '/learn', label: 'Learn' },
{ link: '/community', label: 'Community' },
];
export function HeaderSimple() {
const [opened, { toggle, close }] = useDisclosure(false);
const [active, setActive] = useState(links[0].link);
const items = links.map((link) => (
<a
key={link.label}
href={link.link}
className={classes.link}
data-active={active === link.link || undefined}
onClick={(event) => {
event.preventDefault();
setActive(link.link);
}}
>
{link.label}
</a>
));
return (
<header className={classes.header}>
<Container size="md" className={classes.inner}>
<Group gap={8} wrap="nowrap">
<Box w={28} h={28} bg="blue.6" style={{ borderRadius: 8 }} aria-hidden />
<Text fw={700} size="lg">
Studio
</Text>
</Group>
<Group gap={5} visibleFrom="xs">
{items}
</Group>
<Burger
opened={opened}
onClick={toggle}
hiddenFrom="xs"
size="sm"
aria-label="Toggle navigation"
/>
</Container>
<Drawer
opened={opened}
onClose={close}
size="100%"
padding="md"
title="Navigation"
hiddenFrom="xs"
zIndex={1000000}
>
<ScrollArea h="calc(100vh - 80px" mx="-md">
<Divider my="sm" />
{items}
</ScrollArea>
</Drawer>
</header>
);
}
/**
* Component from Mantine UI, https://ui.mantine.dev
* MIT License, Copyright (c) 2022 Vitaly Rtischev. Full text: https://github.com/mantinedev/ui.mantine.dev/blob/master/LICENCE
* Changed for Tastebud: Mantine's PostCSS shorthands (@mixin, $mantine-breakpoint-*) are written out as
* plain CSS, so it runs without postcss-preset-mantine.
*/
.header {
height: 56px;
margin-bottom: 120px;
background-color: var(--mantine-color-body);
border-bottom: 1px solid light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4));
}
.inner {
height: 56px;
display: flex;
justify-content: space-between;
align-items: center;
}
.link {
display: block;
line-height: 1;
padding: 8px 12px;
border-radius: var(--mantine-radius-sm);
text-decoration: none;
color: light-dark(var(--mantine-color-gray-7), var(--mantine-color-dark-0));
font-size: var(--mantine-font-size-sm);
font-weight: 500;
@media (max-width: 36em) {
border-radius: 0;
padding: var(--mantine-spacing-md);
}
&:hover {
background-color: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-6));
}
[data-mantine-color-scheme] &[data-active] {
background-color: var(--mantine-color-blue-filled);
color: var(--mantine-color-white);
}
}
Changed for this site: The Mantine logo is a plain block and the word Studio. Mantine's PostCSS shorthands (@mixin, $mantine-breakpoint-*) are written out as plain CSS, so it runs without postcss-preset-mantine.