Walkthrough

Components•5 min read|
|

A walkthrough pairs a column of explanation with a sticky code panel. As the reader scrolls through the steps, the panel switches to the file each step is about and focuses the lines it describes. It is the best way to explain a real program without breaking it into disconnected snippets.

Import the SDK and construct a client with your API key. The rest of the file is dimmed while you read this step.

Call the API and wait for the result. These lines are highlighted instead of dimming the others.

A substep takes over the panel for a finer point, here the two lines that use the response.

Steps can point at other files. The panel switches to config.json.

import { Client } from "orbit-sdk";const client = new Client({ key: process.env.ORBIT_KEY });const events = await client.events.list({ limit: 10 });for (const event of events.data) { console.log(event.title);}
{ "region": "eu-west-1", "retries": 3, "timeout": 30}

How to write one

Put wc-walkthrough-step elements first, one per idea, and then one fenced code block for each file. Give every fence a title, which is the name the steps refer to:

<wc-walkthrough> <wc-walkthrough-step title="Create the client" file="client.js" focus="1-3"> Import the SDK and construct a client. </wc-walkthrough-step> <wc-walkthrough-step title="Send a request" file="client.js" highlight="5-8"> Call the API and wait for the result. </wc-walkthrough-step> ```js title="client.js" import { Client } from "orbit-sdk"; // ... ``` </wc-walkthrough>

Each step names the file it targets and the lines to show:

  • focus dims every other line, so the reader's eye goes to the lines it names.
  • highlight keeps all lines at full strength and adds an accent background to the lines it names.
  • file is a file title, or its zero-based index. When a step leaves it out, it keeps the previous step's file.
  • start-line is the line the panel scrolls to. By default that is the first focused or highlighted line.

Line lists use the same syntax as code blocks: a comma-separated mix of numbers and ranges, such as 1-5,8.

A substep is a finer target inside a step. While it is in view it takes over the panel, with its own file, focus, highlight and start-line, and it inherits the step's file when it omits file.

Layout and behavior

The column split. wide gives the code panel more room. The height of the code panel, as any CSS length. Fade the steps that are not in view. Set false to keep them fully visible. The step heading. Inline Markdown works. A short summary under the title. The target file: a file title or its zero-based index. Lines to focus, dimming the rest, such as 1-5,8. Lines to highlight with an accent background, such as 3,5-6. The line the panel scrolls to. A short heading above the substep text. The target file. Defaults to the parent step's file. Lines to focus, such as 1-5,8. Lines to highlight. The line the panel scrolls to.

On narrow screens there is no room for two columns, so each step shows its own code inline beneath the text. The panel respects reduced motion, and the prose reads fine without JavaScript, because the steps are ordinary page content.

Aim for three to seven steps over one or two short files. If a step needs more than a few lines of explanation, split it into a substep or its own page.

From Fern

Fern's ScrollWalkthrough converts to this component. The importer maps its steps and substeps, and drops two options that have no equivalent, stickyHeaders and substepStyle. See the component mapping.

Next steps