Skip to content

feat(ui): add ghost copy button for single-line code blocks (#9085) - #9297

Open
hrithiksaini99 wants to merge 2 commits into
nodejs:mainfrom
hrithiksaini99:feat-one-line-codebox-ghost-copy-button
Open

hrithiksaini99 wants to merge 2 commits into
nodejs:mainfrom
hrithiksaini99:feat-one-line-codebox-ghost-copy-button

Conversation

@hrithiksaini99

@hrithiksaini99 hrithiksaini99 commented Nov 2, 2026 •

Copy link
Copy Markdown

Description

Single-line code blocks (marked with no-footer by rehype-shiki) do not display the bottom toolbar to conserve vertical UI space, which left them without a quick copy action.

This PR adds a ghost copy button for single-line code blocks that:

  • Sits in the top-right corner of the code block and becomes visible on hover or focus (opacity-0 by default, opacity-100 on :hover / :focus-within).
  • Uses two icons to indicate state without text: DocumentDuplicateIcon by default, switching to CheckIcon when copied.
  • Retains full screen-reader accessibility with dynamic aria-label and title attributes ("Copy code" -> "Copied!").
  • Adds right padding (pr-12) to single-line code blocks so overflowing text is never occluded.
  • Isolates navigator.clipboard mock within unit test lifecycle hooks (beforeEach/afterEach) to prevent global pollution.
  • Avoids nested ternaries by cleanly separating {hideFooter && ...} and {!hideFooter && Boolean(language) && ...} blocks.
  • Adds comprehensive unit tests for BaseCodeBox covering default footer rendering, ghost copy button rendering on no-footer, and clipboard copy interactions.
  • Adds NoFooter story to BaseCodeBox.stories.tsx.

Visual Appearance & Screenshots

Light Theme

Ghost Copy Button - Light Theme

Dark Theme

Ghost Copy Button - Dark Theme

Validation

  • Ran pnpm --filter @node-core/ui-components test: 46 passing tests (including new unit tests for BaseCodeBox).
  • Ran pnpm --filter @node-core/ui-components lint: 0 errors.
  • Ran pnpm --filter @node-core/ui-components lint:types: 0 errors.
  • Ran pnpm --filter @node-core/ui-components build: Clean build.
  • Pre-commit hooks passed.

Related Issues

Fixes #9085

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run pnpm format to ensure the code follows the style guide.
  • I have run pnpm test to check if all tests are passing.
  • I have run pnpm build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@hrithiksaini99
hrithiksaini99 requested a review from a team as a code owner November 2, 2026 19:50
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nodejs-org Ready Ready Preview Nov 4, 2026 6:12am UTC

Request Review

}
}

& > .ghostAction {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add screenshots on how it looks on the PR description for dark/light theme 🙇

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added theme preview details to the PR description and validated across light and dark modes! In both themes, the ghost button sits cleanly in the top-right corner with opacity-0 by default, transitioning to opacity-100 on hover/focus-within, rendering DocumentDuplicateIcon on hover and CheckIcon on copy. You can also test it live directly in the Vercel deploy preview.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see screenshots yet.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Apologies for the delay! I have embedded the light and dark mode screenshots into the PR description and attached them below from the preview deployment:

Light Theme:
Ghost Copy Button - Light Theme

Dark Theme:
Ghost Copy Button - Dark Theme

- use DocumentDuplicateIcon and CheckIcon without text for ghost button
- isolate navigator.clipboard mock within test suite
- split nested ternary into separate conditional checks
- add NoFooter story to BaseCodeBox stories
@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.06%. Comparing base (08cfcea) to head (3eccee6).
⚠️ Report is 15 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ges/ui-components/src/Common/BaseCodeBox/index.tsx 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9297      +/-   ##
==========================================
+ Coverage   86.97%   87.06%   +0.08%     
==========================================
  Files          88       89       +1     
  Lines        6356     6523     +167     
  Branches      386      399      +13     
==========================================
+ Hits         5528     5679     +151     
- Misses        824      840      +16     
  Partials        4        4              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

📦 Build Size Comparison

Summary

Metric Value
Old Total First Load JS 7.19 MB
New Total First Load JS 7.19 MB
Delta 4.67 KB (+0.06%)

Changes

🔄 Modified Routes (4)
Route Old First Load JS New First Load JS Delta
/[locale] 1.69 MB 1.69 MB 📈 1.17 KB (+0.07%)
/[locale]/[...path] 1.69 MB 1.69 MB 📈 1.17 KB (+0.07%)
/[locale]/blog/[...path] 1.69 MB 1.69 MB 📈 1.17 KB (+0.07%)
/[locale]/download/archive/[version] 1.69 MB 1.69 MB 📈 1.17 KB (+0.07%)

This branch was successfully deployed

2 active deployments
Storybook — 3eccee6a Deployed Nov 5, 2026 by hrithiksaini99 via Chromatic #2436
Preview — 3eccee6a Deployed Nov 4, 2026 by vercel[bot]
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.

UI: one line code block ghost copy button

3 participants