Skip to content

Restore code-block copy button #569

@drmowinckels

Description

@drmowinckels

Context

A copy-to-clipboard button for code blocks (assets/js/copy-code.js + matching CSS in assets/css/components/syntax.css + bundling in layouts/partials/footer/scripts.html) was prototyped during the rebrand but reverted before launch because the toast confirmation wasn't behaving correctly.

What we want

Code blocks (.highlight) should have a copy-to-clipboard button in the top-right corner with:

  • Visible-on-hover affordance
  • Click → write code.innerText to clipboard via navigator.clipboard.writeText
  • Visual feedback on success (icon swap to check, brief toast "Copied!")
  • Failure path (toast "Copy failed")
  • Dark-mode parity using CSS variables (no hardcoded greens — the previous attempt hardcoded #0a5030 / #86efac for the success state)

Suggested approach

  • Reuse the previous JS scaffold from git history (revert commit on `rebrand` branch removed it; check earlier WIP).
  • Investigate why the toast didn't render — likely a positioning/stacking-context issue with `.highlight.has-copy-btn { position: relative }` and the toast appended to `block.parentNode`.
  • Use a CSS variable (e.g. `--color-success` or similar) for the success state instead of hardcoded hex.
  • Consider Alpine for the show/hide of the toast rather than imperative `setTimeout` chains.

Out of scope

  • Keyboard-only invocation (separate accessibility ticket if needed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions