Skip to content

[Feature] Add one-click copy button to all code snippets in docs - #772

Open
sonusharma6-dsa wants to merge 1 commit into
Jaishree2310:mainfrom
sonusharma6-dsa:feat/copy-code-snippets
Open

[Feature] Add one-click copy button to all code snippets in docs#772
sonusharma6-dsa wants to merge 1 commit into
Jaishree2310:mainfrom
sonusharma6-dsa:feat/copy-code-snippets

Conversation

@sonusharma6-dsa

Copy link
Copy Markdown

Closes #769. Adds a global glassy copy button to all pre/code blocks in the components details pages dynamically using a React useEffect hook inside PageShell, with fallback support for older browsers.

Copilot AI review requested due to automatic review settings July 2, 2026 15:52
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

@sonusharma6-dsa is attempting to deploy a commit to the jaishree2310's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

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 “copy to clipboard” affordance to documentation/code examples by injecting a glassy-styled copy button into <pre> blocks rendered inside PageShell, aiming to reduce friction when copying snippets across component detail pages.

Changes:

  • Adds a useEffect in PageShell that scans .ps-content pre blocks and appends a copy button.
  • Implements Clipboard API copy behavior with a legacy document.execCommand('copy') fallback and success icon feedback.

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

Comment on lines +15 to +20
if (
pre.querySelector('.global-copy-btn') ||
pre.parentElement?.querySelector('button')
)
return;

const btn = document.createElement('button');
btn.className =
'global-copy-btn absolute top-2 right-2 backdrop-filter backdrop-blur-xl bg-white/10 border border-white/20 p-2 hover:bg-white/30 rounded-md transition-all duration-300 z-10 text-white flex items-center justify-center';
btn.title = 'Copy to clipboard';
Comment on lines +36 to +39
// Exclude the button text itself if it was copied
const textToCopy = (preEl.innerText || '')
.replace(/Copy|Copied!/g, '')
.trim();
Comment on lines +50 to +52
.catch(err => {
console.error('Failed to copy: ', err);
});

preEl.appendChild(btn);
});
}, [children]);
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.

[Feature] Add one-click copy button to all code snippets in docs

2 participants