Etch component
TOC 1
Notion-style floating outline built from page headings.
Documentation
A floating table of contents built from the page's headings, in Notion's style: on desktop a slim rail at the side that opens into a panel, and on mobile a pill button that opens the same panel.
How to use it
- Place it on a page or in a template, such as the one for blog posts. It lists the headings found in Content Selector (
mainby default) at the Heading Levels (h2, h3). - Exclude Selector leaves out headings inside matching elements, such as a sidebar. Minimum Headings (2) hides it on pages with fewer headings.
- Mode: responsive (the rail above the Breakpoint, 768px, and the pill below it), rail or pill.
- Title sets the panel's title ("On This Page").
- Scroll Offset leaves room above a heading it jumps to, for a sticky header. Update URL Hash writes the section's id in the address bar.
- Numbered entries, a rail without its sliding marker and a wider panel are CSS recipes, below. Try them in the preview's Styles tab, then paste the ones you pick in the site's
mainstylesheet.
Good to know
- Headings without an id get one from their text, so links to sections work.
- The configurator sets what it lists, its mode and how it scrolls. The CSS variables set its colors, sizes and timing, and the recipes below set them for the whole site.
- On the rail, a line slides to the current section, and on the phone's button a ring fills as the page scrolls.
CSS recipes
--mac-toc-1-panel-width (16rem, 256px), --mac-toc-1-panel-radius (--radius-s) and --mac-toc-1-line-width (16px) set the width and corners of the panel the rail opens and the length of the rail's lines. A recipe changes every TOC 1 on the site. Paste it in the site's main stylesheet, which Etch prints after the components' styles.
Numbered
For a long page whose sections readers cite by number, the entries numbered 1, 1.1, 1.2 and 2.
/* TOC 1's entries numbered 1, 1.1, 1.2, 2 */
.mac-toc-1__list,
.mac-toc-1__sublist {
counter-reset: mac-toc-1;
}
.mac-toc-1__item {
counter-increment: mac-toc-1;
}
.mac-toc-1__link::before {
content: counters(mac-toc-1, '.');
flex-shrink: 0;
font-variant-numeric: tabular-nums;
}
Without the sliding marker
For a quieter rail, without the line that slides to the current section, and the phone's button without its ring.
/* TOC 1 without the sliding marker and the progress ring */
.mac-toc-1__marker,
.mac-toc-1__ring {
display: none;
}
A wider panel
For long headings, the panel the rail opens 320px wide instead of 256px.
/* TOC 1's panel 320px wide */
.mac-toc-1 {
--mac-toc-1-panel-width: 20rem;
}
Reference
Read from the component's JSON, so it's always current.
Loading the reference