Added copy code button functionality in code blocks#7701
Added copy code button functionality in code blocks#7701shibadityadeb wants to merge 4 commits intowebpack:mainfrom
Conversation
|
@shibadityadeb is attempting to deploy a commit to the OpenJS Foundation Team on Vercel. A member of the Team first needs to authorize it. |
| "markdownlint-cli/markdownlint": "^0.37.4" | ||
| } | ||
| }, | ||
| "packageManager": "yarn@4.11.0+sha512.4e54aeace9141df2f0177c266b05ec50dc044638157dae128c471ba65994ac802122d7ab35bcd9e81641228b7dcf24867d28e750e0bcae8a05277d600008ad54" |
There was a problem hiding this comment.
Please remove all changes related to yarn from this PR, only code related to the problem
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
I've authorized a deploy to visually check the changes first. After that, this is how our review will go:
In the code check we will need to check both for a11y and also different browser sizes. |
|
Something is wrong with building, so you will need to fix the build command :) |
|
@evenstensberg will look into the issue |
|
Hi and thank you for working on this. We've recieved a PR that superseeded this. Again, thank you for your contribution! Keep your eyes on issues in the issues list and be active on discord, thanks! 💙 |
|
Thank you for the update! No worries at all , glad to contribute in any way I can. :) |
Summary
This PR adds a "Copy to Clipboard" button feature to all code blocks (
<pre>tags) throughout the/conceptssection and all its child routes on the webpack.js.org documentation site. The implementation enhances user experience by allowing visitors to quickly copy code examples to their clipboard with a single click.Motivation:
Related Issues:
What kind of change does this PR introduce?
This PR introduces a feature enhancement that adds interactive UI elements to documentation pages without modifying any content files or breaking changes.
Changes Include:
CopyCodeButtonReact component with clipboard functionalityPagecomponent for automatic code block enhancementReactDOM.render)Did you add tests for your changes?
Yes, comprehensive tests have been added:
Test Results:
Does this PR introduce a breaking change?
No, this PR introduces zero breaking changes:
If relevant, what needs to be documented once your changes are merged or what have you already documented?
No additional documentation needed:
/concepts/*pagesImplementation Details
Files Added:
src/components/CopyCodeButton/CopyCodeButton.jsx(33 lines)src/components/CopyCodeButton/CopyCodeButton.scss(45 lines)Files Modified:
src/components/Page/Page.jsximport CopyCodeButton from '../CopyCodeButton/CopyCodeButton'import ReactDOM from 'react-dom'useEffecthook to enhance code blocks when content loads/conceptsroutesHow It Works:
/concepts/*loads, thePagecomponent detects content has loaded<pre>elements in the pageCopyCodeButtoncomponent into the wrappertop: 8px, right: 8pxwithz-index: 10dataset.copyButtonAddedflag to avoid duplicatesBrowser Compatibility:
navigator.clipboard.writeText)Performance:
/conceptsroutesquerySelectorAllcall)Visual Representation
Light Mode:
Dark Mode:
After Click:
Testing Evidence
Code Quality:
/conceptspagesManual Testing:
/concepts/*routesDeployment Notes
No special deployment steps required:
PR Checklist
--
Test Cases Passing
--
Copy Button (Before Click)
--
Copy Button (After Click – "Copied!" State)