Walkthrough
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.
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:
Each step names the file it targets and the lines to show:
focusdims every other line, so the reader's eye goes to the lines it names.highlightkeeps all lines at full strength and adds an accent background to the lines it names.fileis a file title, or its zero-based index. When a step leaves it out, it keeps the previous step's file.start-lineis 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
wide gives the code panel more room.false to keep them fully visible.1-5,8.3,5-6.1-5,8.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.
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
- Show full files with code blocks and code import
- Explain a procedure with steps