Table of contents
A list of page headings with the current one marked.
A list of page headings with the current one marked.
npm install @mantine/core @tabler/icons-react clsx
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
*/
import { IconListSearch } from '@tabler/icons-react';
import cx from 'clsx';
import { Box, Group, Text } from '@mantine/core';
import classes from './TableOfContents.module.css';
const links = [
{ label: 'Usage', link: '#usage', order: 1 },
{ label: 'Position and placement', link: '#position', order: 1 },
{ label: 'With other overlays', link: '#overlays', order: 1 },
{ label: 'Manage focus', link: '#focus', order: 1 },
{ label: 'Examples', link: '#1', order: 1 },
{ label: 'Show on focus', link: '#2', order: 2 },
{ label: 'Show on hover', link: '#3', order: 2 },
{ label: 'With form', link: '#4', order: 2 },
];
const active = '#overlays';
export function TableOfContents() {
const items = links.map((item) => (
<Box<'a'>
component="a"
href={item.link}
onClick={(event) => event.preventDefault()}
key={item.label}
className={cx(classes.link, { [classes.linkActive]: active === item.link })}
style={{ paddingLeft: `calc(${item.order} * var(--mantine-spacing-md))` }}
>
{item.label}
</Box>
));
return (
<div>
<Group mb="md">
<IconListSearch size={18} stroke={1.5} />
<Text>Table of contents</Text>
</Group>
{items}
</div>
);
}
/**
* 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.
*/
.link {
display: block;
text-decoration: none;
color: var(--mantine-color-text);
line-height: 1.2;
font-size: var(--mantine-font-size-sm);
padding: var(--mantine-spacing-xs);
border-top-right-radius: var(--mantine-radius-sm);
border-bottom-right-radius: var(--mantine-radius-sm);
border-left: 1px solid light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4));
&:hover {
background-color: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-6));
}
}
.linkActive {
font-weight: 500;
border-left-color: light-dark(var(--mantine-color-blue-6), var(--mantine-color-blue-4));
color: light-dark(var(--mantine-color-blue-6), var(--mantine-color-blue-4));
&,
&:hover {
background-color: var(--mantine-color-blue-light) !important;
}
}
Changed for this site: Mantine's PostCSS shorthands (@mixin, $mantine-breakpoint-*) are written out as plain CSS, so it runs without postcss-preset-mantine.