[Feature] Add one-click copy button to all code snippets in docs - #772
Open
sonusharma6-dsa wants to merge 1 commit into
Open
[Feature] Add one-click copy button to all code snippets in docs#772sonusharma6-dsa wants to merge 1 commit into
sonusharma6-dsa wants to merge 1 commit into
Conversation
|
@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. |
There was a problem hiding this comment.
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
useEffectinPageShellthat scans.ps-content preblocks 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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.