Skip to content

Conversation

@GaneshPatil7517
Copy link

Summary

This PR implements the "Copy Code" feature requested in issue #7698.
A Copy button is added to the top-right corner of each code block on the documentation site, allowing users to copy the entire code snippet with a single click.

Motivation

Currently, users must manually select and copy code from documentation pages.
This is time-consuming, error-prone, and difficult on mobile devices.

Adding a Copy button:

  • Improves developer experience
  • Makes code examples easier to use
  • Reduces friction while following documentation
  • Aligns Webpack docs with modern documentation standards (e.g., MDN, Next.js, TailwindCSS)

Implementation Details

  • Added new CodeBlock component with a built-in Copy button.
  • Integrated navigator.clipboard.writeText() to copy code.
  • Styled the button to match Webpack documentation UI.
  • Updated mdx-components.js to use the new CodeBlock wrapper.
  • Ensured accessibility (focus, hover states).

Screenshots / Demo

(If you want, add before/after screenshots here)

Linked Issue

Closes #7698

Checklist

  • Copy Code button added
  • Works on desktop & mobile
  • No breaking changes
  • Code formatted and linted

@vercel
Copy link

vercel bot commented Nov 23, 2025

@GaneshPatil7517 is attempting to deploy a commit to the OpenJS Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@linux-foundation-easycla
Copy link

CLA Not Signed

Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

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

could you fix CI issues? If you are stuck just ask chatgpt.

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.

Add "Copy Code" button to code examples on documentation site

2 participants