Skip to content

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

Description

@anshul23102

Summary

Code examples in the GlassyUI documentation site have no copy button. Users must manually select and copy code, which is friction-heavy especially for long snippets.

Proposed Solution

Add a floating copy button to every <pre> / code block on the docs site:

document.querySelectorAll('pre code').forEach(block => {
  const btn = document.createElement('button');
  btn.textContent = 'Copy';
  btn.className = 'copy-btn';
  btn.addEventListener('click', () => {
    navigator.clipboard.writeText(block.innerText).then(() => {
      btn.textContent = 'Copied!';
      setTimeout(() => (btn.textContent = 'Copy'), 2000);
    });
  });
  block.parentElement.style.position = 'relative';
  block.parentElement.appendChild(btn);
});

Style the button with the Glassy aesthetic and position it at top: 8px; right: 8px inside the code block container.

Checklist

  • I have searched for existing issues and this is not a duplicate
  • I am a GSSoC 2026 contributor

Additional Context

Level 2 feature. Include a fallback for document.execCommand('copy') for older browsers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions