Skip to content

feat(storybook): add global GitHub source link to every story#239

Merged
horner merged 2 commits into
mainfrom
horner/storybook-github-source-link
May 20, 2026
Merged

feat(storybook): add global GitHub source link to every story#239
horner merged 2 commits into
mainfrom
horner/storybook-github-source-link

Conversation

@horner
Copy link
Copy Markdown
Member

@horner horner commented May 20, 2026

Every story page in Storybook is a potential entry point for a developer who wants to dig into the source. Today there is no fast path from a Storybook page to the actual component file on GitHub -- you have to know the repo layout and navigate there yourself.

This adds a withGitHubSource global decorator in .storybook/preview.tsx that automatically appends a small, low-opacity "View source on GitHub ↗" link below every story. The link is derived at runtime from context.parameters.fileName (the absolute on-disk path Storybook already provides), so no per-story configuration is needed:

  • Strips the machine-local prefix up to /src/ to get the repo-relative path.
  • Replaces .stories.tsx with .tsx so the link points to the component source file, not the stories file.
  • Renders outside the brand-styled wrapper (outermost decorator position) so it is unaffected by theme/brand switching.

Works on every canvas tab and within each story preview in the docs tab, with zero changes to individual story files.

Adds a withGitHubSource decorator in preview.tsx that appends a small
'View source on GitHub' link below every story. The link is derived
automatically from context.parameters.fileName (the absolute path to
the stories file), strips everything before /src/, and replaces
.stories.tsx with .tsx so it points to the component source file
rather than the stories file itself.

No per-story configuration needed -- works on every canvas and docs page.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 20, 2026 20:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a global Storybook decorator that renders a “View source on GitHub” link beneath each story, aiming to provide a quick path from Storybook to the relevant source file in this repo.

Changes:

  • Introduces a new withGitHubSource global decorator that derives a GitHub URL from context.parameters.fileName.
  • Registers the decorator globally and orders it to render outside the existing brand wrapper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .storybook/preview.tsx Outdated
Comment thread .storybook/preview.tsx Outdated
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 20, 2026

Deploying ui with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3c782d5
Status: ✅  Deploy successful!
Preview URL: https://3b612f74.ui-6d0.pages.dev
Branch Preview URL: https://horner-storybook-github-sour.ui-6d0.pages.dev

View logs

@horner
Copy link
Copy Markdown
Member Author

horner commented May 20, 2026

Thanks for the deploy confirmation -- the preview looks good!

- Normalize Windows backslashes to forward slashes before any path
  operations so the link renders correctly on Windows dev machines.
- Only strip '.stories' from the basename when it strictly matches
  'Name.stories.(ts|tsx|js|jsx)' (no extra dot-segments). Non-standard
  names like AGGrid.enhanced.stories.tsx now safely link to the stories
  file itself rather than a non-existent component file.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@horner horner merged commit 23de526 into main May 20, 2026
10 checks passed
@horner horner deleted the horner/storybook-github-source-link branch May 20, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants