PrerequisiteChain
Ce contenu n’est pas encore disponible dans votre langue.
The PrerequisiteChain component displays a visual chain of prerequisite topics, useful for showing API migration paths, dependency relationships, or knowledge prerequisites.
Import
Section titled “Import”import { PrerequisiteChain } from 'starlight-tags/components';| Prop | Type | Default | Description |
|---|---|---|---|
tagId | string | - | Tag ID to show prerequisites for |
tag | ProcessedTag | - | Pre-fetched tag object (for advanced use) |
tagsMap | Map<string, ProcessedTag> | - | Pre-fetched tags map (for advanced use) |
showDescription | boolean | true | Show helper text |
maxChainLength | number | 5 | Max prerequisites to show |
Basic Usage
Section titled “Basic Usage”import { PrerequisiteChain } from 'starlight-tags/components';
<PrerequisiteChain tagId="oauth2" />That’s it! The component fetches tag data and builds the chain automatically.
Prerequisites Setup
Section titled “Prerequisites Setup”For this component to display data, your tags need prerequisites defined in tags.yml:
tags: api-basics: label: "API Basics" description: "Introduction to the API"
authentication: label: "Authentication" prerequisites: - api-basics
oauth2: label: "OAuth 2.0" prerequisites: - api-basics - authenticationDisplay
Section titled “Display”The component renders as:
PrerequisitesComplete these topics before starting this content
[API Basics] → [Authentication] → [OAuth 2.0] You are hereUse Cases
Section titled “Use Cases”API Migration Paths
Section titled “API Migration Paths”Show users how to migrate between API versions:
<PrerequisiteChain tagId="api-v2" />tags: api-v1: label: "API v1" description: "Legacy API version"
api-v2: label: "API v2" prerequisites: - api-v1Learning Paths
Section titled “Learning Paths”Guide users through a sequence of topics:
<PrerequisiteChain tagId="webhooks" />Without Description
Section titled “Without Description”Hide the helper text for a more compact display:
<PrerequisiteChain tagId="webhooks" showDescription={false} />Limiting Chain Length
Section titled “Limiting Chain Length”For tags with many prerequisites, limit the display:
<PrerequisiteChain tagId="advanced-topic" maxChainLength={3} />If more prerequisites exist, it shows ”… and X more prerequisites”.
How It Works
Section titled “How It Works”- The component reads the
prerequisiteChaincomputed property from the tag - This property is automatically calculated based on the
prerequisitesfield in your tags configuration - It resolves the full chain recursively (prerequisites of prerequisites)
- Tags are displayed in order with arrows between them
- The current tag is highlighted with “You are here”
Responsive Design
Section titled “Responsive Design”On mobile devices (< 768px):
- The chain displays vertically instead of horizontally
- Arrows rotate 90 degrees to point downward
- “You are here” label adjusts position
Advanced: Pre-fetched Data
Section titled “Advanced: Pre-fetched Data”For advanced use cases where you already have tag data:
---import { PrerequisiteChain } from 'starlight-tags/components';
const { tags } = Astro.locals.starlightTags;const currentTag = tags.get('oauth2');---
{currentTag?.prerequisiteChain?.length > 0 && ( <PrerequisiteChain tag={currentTag} tagsMap={tags} />)}Styling
Section titled “Styling”The component uses Starlight’s CSS variables:
.prerequisite-chain { background: var(--sl-color-bg-sidebar); border: 1px solid var(--sl-color-hairline-shade); border-radius: var(--sl-border-radius);}Custom Styling
Section titled “Custom Styling”Override the default styles:
.prerequisite-chain { background: var(--sl-color-bg-nav); padding: 1.5rem;}
.prerequisite-chain__arrow { color: var(--sl-color-accent); font-size: 1.5em;}
.prerequisite-chain__current::before { content: "Current topic"; color: var(--sl-color-accent);}When to Use
Section titled “When to Use”This component is ideal for:
- API version migration guides
- SDK setup sequences
- Feature dependency documentation
- Complex workflows with ordered steps
- Any documentation with prerequisite knowledge
It works best when tags have clear prerequisite relationships defined in your tags.yml configuration.