Managing Interactive Examples (<Go>)
Interactive examples allow users to preview and edit code directly in the documentation. This guide explains how to manage these examples using the dedicated workspace and the <Go> component.
Overview
The interactive example system allows you to embed live, runnable Lynx code in your documentation. It consists of:
- Source Packages: Examples are real npm packages managed in
packages/lynx-example-packages/. - Build Process: A script bundles these packages into static assets for the website.
<Go>Component: A React component that renders the interactive editor and preview in your MDX files.
1. Using the <Go> Component
To embed an interactive example in your documentation, use the <Go> component.
Basic Usage
Import Go from @lynx and provide the example ID (which corresponds to the package directory name).
Component Props
Advanced Example
2. Managing Example Packages
All interactive examples are managed as dependencies in the packages/lynx-example-packages/ workspace.
Directory Structure
Adding a New Example
To make a new example available to the <Go> component:
- Publish the Package: Your example must be a valid npm package (e.g.,
@lynx-example/my-feature). - Add Dependency: Add the package to
packages/lynx-example-packages/package.json. - Install: Run
pnpm installin the workspace root to download the new example. - Rebuild Assets: The website build process will automatically detect and bundle the new example.
3. Build Architecture
For those interested in how it works under the hood:
- Script:
scripts/lynx-example.jsruns during the build. - Process:
- Scans
node_modules/@lynx-example/for packages. - Identifies bundle files (
.lynx.bundle,.web.bundle) and source code. - Generates an
example-metadata.jsonfor each example. - Copies assets to
docs/public/lynx-examples/.
- Scans
- Runtime: The
<Go>component fetches this metadata at runtime to hydrate the editor and preview.