Table of Contents
PreviewA table of contents that highlights the headings you are reading.
Delivery
Orders placed before 2 pm on a working day ship the same day. You get a tracking link by email once the parcel leaves the warehouse, and you can follow it until the courier hands it over at your door.
Returns
You can return unworn items within 30 days. Print the return label from your order confirmation and drop the parcel at any post office. Keep the receipt of the post office until your refund has arrived.
Payment
We accept credit card, PayPal and invoice. Your card is charged when the order ships, not when you place it, so an item that is out of stock never costs you anything.
Contact
Write to support@example.com or call us on weekdays between 9 am and 5 pm. We answer emails within one working day, and a call is quicker for questions about a parcel on its way.
Features
Permalink to heading "Features"- Highlights the links of the headings that are visible, tracked with an
IntersectionObserver - Highlights several links at once when several headings are visible
- Scrolls its own list so the first active link stays in view
- Follows the headings of a scroll container as well as of the page
- Sets
aria-current="location"on the active links - Exposes the position of the active links for an animated indicator
<primitives:toc.root>
<primitives:toc.title />
<primitives:toc.list>
<primitives:toc.indicator />
<primitives:toc.item>
<primitives:toc.link />
</primitives:toc.item>
</primitives:toc.list>
</primitives:toc.root>
Installation
Permalink to heading "Installation"typo3 ui:add toc
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Build the items from your content
Permalink to heading "Build the items from your content"items takes TocItem objects or arrays with a value (the id of the heading element) and a depth. A TocItem also carries the label for your template and for client scripts.
use Jramke\FluidPrimitives\Domain\Dto\TocItem;
$items = array_map(
static fn(array $header) => new TocItem(value: 'c' . $header['uid'], depth: 2, label: $header['header']),
$contentElements,
);
<ui:toc.root items="{items}">
<ui:toc.list>
<f:for each="{items}" as="item">
<ui:toc.item value="{item.value}"><ui:toc.link>{item.label}</ui:toc.link></ui:toc.item>
</f:for>
</ui:toc.list>
</ui:toc.root>
Indent nested headings
Permalink to heading "Indent nested headings"List the depth of each heading in items: 2 for an h2, 3 for an h3. An item exposes it as the --depth CSS variable, which the ui:toc.item of the registry turns into an indent.
Delivery
Orders placed before 2 pm on a working day ship the same day. You get a tracking link by email once the parcel leaves the warehouse, and you can follow it until the courier hands it over at your door.
Delivery times
Parcels reach most addresses in Germany within two working days, the rest of Europe takes up to five. Islands and remote regions can take a day or two longer, which the tracking link shows.
Shipping costs
Shipping is free from 50 EUR. Below that it costs 4.90 EUR within Germany and 9.90 EUR for the rest of Europe. The costs show in your basket before you pay.
Returns
You can return unworn items within 30 days. Print the return label from your order confirmation and drop the parcel at any post office. Keep the receipt of the post office until your refund has arrived.
Refunds
We refund the price of the items to the payment method you used. The shipping costs come back too if you return the whole order, otherwise they stay with the items you keep.
Refund times
A refund arrives within five working days after we receive the parcel. You get an email as soon as we have booked it, and your bank may need a few more days to show it.
Contact
Write to support@example.com or call us on weekdays between 9 am and 5 pm. We answer emails within one working day, and a call is quicker for questions about a parcel on its way.
Follow the active link with an indicator
Permalink to heading "Follow the active link with an indicator"Place a ui:toc.indicator in the list. It follows the active links through the --top, --height, --left and --width CSS variables of the root, and the list is its positioning context.
Delivery
Orders placed before 2 pm on a working day ship the same day. You get a tracking link by email once the parcel leaves the warehouse, and you can follow it until the courier hands it over at your door.
Returns
You can return unworn items within 30 days. Print the return label from your order confirmation and drop the parcel at any post office. Keep the receipt of the post office until your refund has arrived.
Refunds
We refund the price of the items to the payment method you used. The shipping costs come back too if you return the whole order, otherwise they stay with the items you keep.
Payment
We accept credit card, PayPal and invoice. Your card is charged when the order ships, not when you place it, so an item that is out of stock never costs you anything.
Contact
Write to support@example.com or call us on weekdays between 9 am and 5 pm. We answer emails within one working day, and a call is quicker for questions about a parcel on its way.
Draw a rail
Permalink to heading "Draw a rail"Each link draws a segment of the rail beside it, and the segment of an active link turns dark. A heading one level deeper steps the rail in, with a curve where the level changes.
Delivery
Orders placed before 2 pm on a working day ship the same day. Later orders leave the warehouse the next morning, and we do not ship on Sundays or public holidays.
Returns
You can return unworn items within 30 days. They need their tags and the original packaging, and we check them when the parcel arrives at our warehouse.
Return label
Print the label from your order confirmation and stick it on the parcel. If you have no printer, show the QR code in the email at any post office and they print it for you.
Return window
The 30 days start on the day the parcel arrives, not on the day you ordered. Send the items back within that time, and we still accept them if the parcel is on its way.
Payment
We accept credit card, PayPal and invoice. You pick one at the end of the checkout, and you can change it as long as the order has not shipped.
Credit card
Your card is charged when the order ships, not when you place it. If the payment fails, we email you a link to try another card before we cancel anything.
Invoice
You get the invoice with the parcel and a second copy by email. Invoice payment is available from your second order, and only for orders up to 500 EUR.
Due date
Pay within 14 days of the invoice date. The bank details are on the invoice, so please add the invoice number as the reference, otherwise we cannot match your payment.
Contact
Write to support@example.com on weekdays and we answer within one working day. Please add your order number, so we can find your order without asking again.
Collapse the list into a summary
Permalink to heading "Collapse the list into a summary"Put the list into a ui:collapsible. The trigger shows the active heading and how far you are, so the list can stay closed. The script mounts the Toc itself and updates the summary from onActiveChange: the --progress of the ring, the number and the label of the active heading.
Ingredients
Mix 500 g flour, 10 g salt, 7 g dry yeast and 350 ml lukewarm water. The dough is sticky, so keep a bowl of water nearby to wet your hands. Use bread flour if you can, it holds the shape better.
Kneading
Knead for ten minutes until the dough stops sticking to your hands, then let it rest for an hour. It should double in size, and small bubbles show on the surface when it is ready.
Shaping
Fold the dough into a tight ball, place it seam side up in a floured basket and cover it. Let it rise for another hour, until a finger pressed into it leaves a dent that fills back slowly.
Baking
Bake at 240 C for 20 minutes with a pan of water on the rack below, then 20 minutes at 200 C. The crust should be deep brown, and the loaf sounds hollow when you tap its bottom.
Storing
Let the loaf cool for an hour before cutting. It stays fresh for three days in a linen bag, and you can slice and freeze what you do not eat to toast it later.
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.
toc.root
Permalink to heading "toc.root"Wraps the table of contents, provides its state and takes the items. Renders a <nav> element.
| Name | Description | Required | Default |
|---|---|---|---|
items | array|Domain\Dto\TocItem[]The headings of the page, a list of `TocItem` objects or of arrays with a `value` (the id of the heading) and a `depth` (its level, e.g. `2` for an `h2`). Every `ui:toc.item` takes its depth from here. | Yes | - |
defaultActiveIds | string[]The ids of the headings that are active when rendered, until the first observation replaces them. Use when you don't need to control the active headings. | No | - |
rootMargin | stringThe root margin of the IntersectionObserver. It sets the area of the viewport in which a heading counts as visible. | No | '-20px 0% -40% 0%' |
threshold | float|float[]The threshold of the IntersectionObserver. `0` makes a heading active as soon as a single pixel of it is inside the root margin. | No | 0 |
scrollEl | stringA CSS selector of the scroll container the headings sit in. Defaults to the viewport of the document. | No | - |
autoScroll | booleanWhether the table of contents scrolls the first active item into view when the active headings change. It scrolls every scrollable ancestor of the item, the page included, so turn it off for a list that does not scroll itself. | No | true |
scrollBehavior | Enum\ScrollBehaviorThe scroll behavior of the auto-scroll of the list and of a click on a link. A link only scrolls by itself when `scrollEl` is set, otherwise the browser follows its hash. Smooth scrolling is skipped for a visitor who prefers reduced motion. | No | Smooth |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
class | stringThe CSS class(es) to be applied to the component. | No | - |
toc.title
Permalink to heading "toc.title"Labels the table of contents. Renders an <h2> element, set level for another heading level.
| Name | Description | Required | Default |
|---|---|---|---|
level | integerThe heading level to render for the title. | No | 2 |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
toc.list
Permalink to heading "toc.list"Wraps the items and is the positioning context of the indicator. Renders a <ul> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
toc.item
Permalink to heading "toc.item"One heading of the page, identified by its value. Renders an <li> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | stringThe id of the heading the item points to. It has to be one of the `items` of the root, which also set the depth of the item. The depth is available as the `--depth` CSS variable to indent the item. | Yes | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-toc-item | <uid> |
data-value | The value of the item |
data-depth | The depth of the item |
data-active | Present when active or pressed |
data-first | |
data-last |
toc.link
Permalink to heading "toc.link"Links to the heading of its item. Renders an <a> element.
| Name | Description | Required | Default |
|---|---|---|---|
href | stringThe target of the link. Defaults to the hash of the item's heading, `#value`. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-toc-link | <uid> |
data-value | The value of the item |
data-active | Present when active or pressed |
toc.indicator
Permalink to heading "toc.indicator"Follows the active items. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
activeIds | string[] | All currently active (visible) heading ids |
activeItems | TocItem[] | The active (visible) TOC items |
items | TocItem[] | The resolved items list |
setActiveIds | (value: string[]) => void | Manually set the active heading ids |
scrollTo | (value: string, details?: ScrollToDetails | undefined) => void | Scrolls to the heading with the given id. |
getItemState | (props: ItemProps) => ItemState | Returns the state of a TOC item |
getIndicatorState | () => IndicatorState | Returns the state of the indicator |