Skip to content

Added copy-to-clipboard button#74

Open
raushan-2006 wants to merge 2 commits into
pushkarscripts:mainfrom
raushan-2006:add-copy-button
Open

Added copy-to-clipboard button#74
raushan-2006 wants to merge 2 commits into
pushkarscripts:mainfrom
raushan-2006:add-copy-button

Conversation

@raushan-2006
Copy link
Copy Markdown

Related Issue

Fixes #9


Description

This PR implements a global, lightweight Copy-to-Clipboard feature for all code snippets and command blocks across the platform's academic modules.

Key changes include:

  • Interactive Copy Action: Integrated a dedicated copy button into the core <CodeBlock /> component template used universally across Semester 1, 2, and 4 course pages.
  • Visual Feedback State: Added dynamic state management (useState) to toggle between a default copy icon and a temporary "Copied!" indicator text/icon upon successful execution to improve user experience.
  • Native Clipboard API Integration: Handled text execution using browser-native navigator.clipboard.writeText to keep the codebase lightweight and eliminate unnecessary third-party package dependencies.
  • Responsive Layout Design: Styled the copy asset overlay to align cleanly with the dark-gold premium theme boundaries on both desktop grids and compact mobile viewports without covering important syntax text.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • UI/UX improvement
  • Refactor

Screenshots / Demo

Screenshot 2026-05-19 at 12 59 22 AM

How Has This Been Tested?

  • Verified the copying logic across various browsers (Chrome, Safari, Firefox) to confirm native Clipboard API compatibility.
  • Tested the component layout responsiveness using Chrome DevTools mobile emulation to verify touch targets and button placement.
  • Confirmed that formatting, indentation, and newlines are preserved correctly upon pasting the copied text into local text editors.

Checklist

  • My code follows the project structure and conventions
  • I have tested the changes locally
  • I have linked the related issue properly
  • I have added screenshots where applicable
  • No existing functionality was broken

AI Usage

  • I have not used AI tools for this contribution

  • I have used AI tools (ChatGPT, Copilot, Claude, etc.) and I have reviewed, verified, and understood all generated code/content before submitting this PR

If AI tools were used, briefly explain how:

Used to draft the reactive toggle delay logic for the visual "Copied!" feedback state.


Additional Notes

This directly fixes the accessibility bottleneck for mobile workspace readers who previously struggled with manual inline text selection.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 18, 2026

Someone is attempting to deploy a commit to the PushkarScripts Team on Vercel.

A member of the Team first needs to authorize it.

@pushkarscripts
Copy link
Copy Markdown
Owner

The copy button functionality works fine, but the current UI styling still feels visually inconsistent.

Right now there are multiple layered borders/containers around the code block which makes the alignment look a bit off. The copy button border styling also doesn’t fully match the surrounding container/theme yet.

Try simplifying the container structure a bit and make the button styling blend more naturally with the existing UI.

image

@raushan-2006
Copy link
Copy Markdown
Author

give a rough idea about copy button and container layout

@raushan-2006
Copy link
Copy Markdown
Author

Related Issue

Fixes #9


Description

This PR implements a global, lightweight Copy-to-Clipboard feature for all code snippets and command blocks across the platform's academic modules.

Key changes include:

  • Interactive Copy Action: Integrated a dedicated copy button into the core <CodeBlock /> component template used universally across Semester 1, 2, and 4 course pages.
  • Visual Feedback State: Added dynamic state management (useState) to toggle between a default copy icon and a temporary "Copied!" indicator text/icon upon successful execution to improve user experience.
  • Native Clipboard API Integration: Handled text execution using browser-native navigator.clipboard.writeText to keep the codebase lightweight and eliminate unnecessary third-party package dependencies.
  • Responsive Layout Design: Styled the copy asset overlay to align cleanly with the dark-gold premium theme boundaries on both desktop grids and compact mobile viewports without covering important syntax text.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • UI/UX improvement
  • Refactor

Screenshots / Demo

Screenshot 2026-05-20 at 9 31 26 AM

How Has This Been Tested?

  • Verified the copying logic across various browsers (Chrome, Safari, Firefox) to confirm native Clipboard API compatibility.
  • Tested the component layout responsiveness using Chrome DevTools mobile emulation to verify touch targets and button placement.
  • Confirmed that formatting, indentation, and newlines are preserved correctly upon pasting the copied text into local text editors.

Checklist

  • My code follows the project structure and conventions
  • I have tested the changes locally
  • I have linked the related issue properly
  • I have added screenshots where applicable
  • No existing functionality was broken

AI Usage

  • I have not used AI tools for this contribution

  • I have used AI tools (ChatGPT, Copilot, Claude, etc.) and I have reviewed, verified, and understood all generated code/content before submitting this PR

If AI tools were used, briefly explain how:

Used to draft the reactive toggle delay logic for the visual "Copied!" feedback state.


Additional Notes

This directly fixes the accessibility bottleneck for mobile workspace readers who previously struggled with manual inline text selection.

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 Copy Button for Code Blocks

2 participants