Skip to content

[docs] Add GitHub demo source link to Demo component#4076

Open
CiscoFran10 wants to merge 5 commits intomui:masterfrom
CiscoFran10:docs/demo-github-demo-url
Open

[docs] Add GitHub demo source link to Demo component#4076
CiscoFran10 wants to merge 5 commits intomui:masterfrom
CiscoFran10:docs/demo-github-demo-url

Conversation

@CiscoFran10
Copy link
Contributor

@CiscoFran10 CiscoFran10 commented Feb 13, 2026

Summary

Adds a way to open and copy the GitHub source link for each demo from the docs. Demos get a “More actions” (⋮) menu with “View source on GitHub”, “Copy link to source”, and “Report an issue”.

image

Changes

  • getGitHubDemoUrl – New utility that turns a file:// URL (from import.meta.url) into the corresponding GitHub tree URL for the demo directory. Supports the selected variant (e.g. Default, CssModules, Tailwind) so the link points at the right folder.
  • getGitHubDemoUrl.test.ts – Tests for Unix/Windows paths, variants, Default, invalid/missing input, and encoded paths.
  • MoreVertIcon – New icon used as the trigger for the demo actions menu.
  • Demo component – Integrates a Menu triggered by the More icon when a GitHub URL is available:
    • View source on GitHub – Opens the demo source on GitHub in a new tab with GA event github.
    • Copy link to source – Copies the GitHub URL and shows “Link copied!” with GA event copy_source_link.
    • Report an issue – Opens the GitHub “new issue” page with pre-filled title.
  • Demo.css – Styles for the new menu (positioner, popup, items, separator).

Notes

  • The menu is only rendered when getGitHubDemoUrl returns a URL (i.e. when the demo’s url resolves to a path under docs/).
  • “View source on GitHub” is tracked with the existing github GA event. ?? Let me know if this is truly needed, but I thought it would be good to add.

Context

  1. There are no links to the source. It feels impactful to help the community contribute fixes. Shouldn't there be one (under a triple dot menu)?

See for context: #2766

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 13, 2026

commit: f536344

@mui-bot
Copy link

mui-bot commented Feb 13, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link

netlify bot commented Feb 13, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f536344
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/699004f583b5320008509c72
😎 Deploy Preview https://deploy-preview-4076--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

Adds a "More actions" menu to demo components with links to view source on GitHub, copy the source link, and report issues. The implementation follows repository guidelines with proper use of useTimeout and useStableCallback hooks, comprehensive test coverage, and accessible menu patterns with ARIA labels and live regions for status announcements.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation follows all repository coding guidelines (useTimeout, useStableCallback), includes comprehensive test coverage, uses proper accessibility patterns, and the changes are well-scoped to documentation features
  • No files require special attention

Important Files Changed

Filename Overview
docs/src/utils/getGitHubDemoUrl.ts New utility function that converts file:// URLs to GitHub source URLs with proper variant handling
docs/src/utils/getGitHubDemoUrl.test.ts Comprehensive test coverage for the getGitHubDemoUrl utility, covering Unix/Windows paths, variants, and edge cases
docs/src/components/Demo/Demo.tsx Added Menu component with GitHub source link, copy link, and report issue actions. Refactored timeout handling to use useTimeout hook

Last reviewed commit: 6e1af5d

Copy link

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 “More actions” menu to each docs demo to expose quick actions like viewing the demo’s source on GitHub, copying a source link, and reporting an issue.

Changes:

  • Added getGitHubDemoUrl utility (+ unit tests) to convert import.meta.url file:// locations into a GitHub directory URL, including variant subfolders.
  • Added MoreVertIcon and integrated a Menu into Demo to provide “View source”, “Copy link”, and “Report an issue” actions.
  • Added Demo.css styles for the new menu popup and items.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/src/utils/getGitHubDemoUrl.ts New utility to derive GitHub source URL for a demo directory (with variant support).
docs/src/utils/getGitHubDemoUrl.test.ts Unit tests covering Unix/Windows paths, variants, and encoded components.
docs/src/icons/MoreVertIcon.tsx New icon used for the demo actions menu trigger.
docs/src/components/Demo/Demo.tsx Adds “More actions” menu to demos and copy-feedback behavior for source links.
docs/src/components/Demo/Demo.css Adds styling for the new actions menu.

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

Copy link
Member

@aarongarciah aarongarciah left a comment

Choose a reason for hiding this comment

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

Did a initial pass and left some inline comments.

</span>
</GhostButton>
{githubUrl && (
<Menu.Root>
Copy link
Member

Choose a reason for hiding this comment

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

A flickering happens when opening the menu. See attached video:

Kapture.2026-02-13.at.08.00.35.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn’t reproduce the flickering on my side (tested on Windows). Could you confirm if it’s still happening? If so, could you share your device, OS, and browser?

Comment on lines -60 to -76
const onCopied = React.useCallback(() => {
const onCodeCopied = useStableCallback(() => {
ga?.trackEvent({
category: 'demo',
action: 'copy',
label: demoId,
params: { copy: demoId, slug: demoSlug || '' },
});

/* eslint-disable no-restricted-syntax */
const newTimeout = window.setTimeout(() => {
window.clearTimeout(newTimeout);
setCopyTimeout(0);
}, 2000);
window.clearTimeout(copyTimeout);
setCopyTimeout(newTimeout);
/* eslint-enable no-restricted-syntax */
}, [copyTimeout, ga, demoId, demoSlug]);
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid "unrelated" code, or at least try to explain the why behind those changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The project guidelines advise using useStableCallback and useTimeout over React.useCallback and window.setTimeout, so I tried to follow the boy scout rule here. Since I was adding similar copy behavior for the source link, it felt weird to implement it the "right way" while leaving the existing one with the old approach right next to it.

Same thing for the accessibility improvement (aria-hidden, aria-live), while working on the accessibility of the new menu, I couldn't help but update the existing copy button as well to keep them consistent.

That said, let me know if you'd prefer I revert these and create a separate PR for them.

Comment on lines +215 to +222
{codeCopied ? (
<CheckIcon aria-hidden="true" />
) : (
<CopyIcon aria-hidden="true" />
)}
<span className="sr-only" aria-live="polite">
{codeCopied && 'Code copied!'}
</span>
Copy link
Member

Choose a reason for hiding this comment

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

If there are other unrelated improvements, let's create a separate PRs for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explained above, lmk how to proceed

@zannager zannager added the docs Improvements or additions to the documentation. label Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to the documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants