Skip to content

Conversation

@IshikaBanga26
Copy link

This pull request adds a “Copy” button to the code snippet section in the Tip Calculator example, allowing users to easily copy example code with one click.
Additionally, minor UI improvements have been made to enhance readability and visual separation.

Changes Made:

Added a Copy button with clipboard functionality.

Styled

 blocks with a light background and border for better contrast.

Added margin above the code section for clear spacing.

Enhanced button hover feedback and alignment.

Impact:

Improves user experience and accessibility.

Makes example sections more interactive and visually clear.

@vercel
Copy link

vercel bot commented Oct 29, 2025

@IshikaBanga26 is attempting to deploy a commit to the Suman Kunwar's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Oct 29, 2025

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

Project Deployment Preview Comments Updated (UTC)
learn-javascript Error Error Oct 29, 2025 10:45pm

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds a copy-to-clipboard button feature for code snippets in the Tip Calculator example, along with styled code blocks for better visual presentation. However, the PR also includes several package.json dependency version changes that appear unrelated to the copy button feature and require careful review.

Key Changes

  • Implements a JavaScript-based copy button with clipboard API integration for code snippets
  • Adds CSS styling for code blocks with background, borders, and button hover effects
  • Updates multiple npm package versions in package.json (both upgrades and downgrades)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
package.json Updates dependency versions for cz-conventional-changelog (downgrade), gitbook-plugin-exercises (major downgrade), and honkit (major upgrade)
examples/Tip_Calculator/style.css Adds CSS styles for code blocks and copy button, including duplicate .code-block rule definitions
examples/Tip_Calculator/script.js Implements copy button functionality with DOM manipulation and clipboard API, but lacks error handling
examples/Tip_Calculator/index.html Adds a code block example demonstrating a tip calculation function with formatting issues

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"gitbook-plugin-chapter-fold": "^0.0.4",
"gitbook-plugin-edit-link": "^2.0.2",
"gitbook-plugin-exercises": "^3.0.0",
"gitbook-plugin-exercises": "^1.0.0",
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

This change downgrades gitbook-plugin-exercises from ^3.0.0 to ^1.0.0. This is a major version downgrade that could remove important features or break existing functionality. Please verify if this downgrade is intentional and ensure all dependent code remains compatible with version 1.0.0.

Suggested change
"gitbook-plugin-exercises": "^1.0.0",
"gitbook-plugin-exercises": "^3.0.0",

Copilot uses AI. Check for mistakes.
"gitbook-plugin-sitemap": "^1.2.0",
"gitbook-plugin-theme-creative": "github:sumn2u/gitbook-plugin-theme-creative",
"honkit": "^4.0.4",
"honkit": "^6.1.4",
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

This change upgrades honkit from ^4.0.4 to ^6.1.4, skipping version 5 entirely. This is a major version upgrade that may include breaking changes. Please ensure all honkit plugins and configurations are compatible with version 6.1.4, and test the build thoroughly.

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +38
.code-block {
margin-top: 20px;
}
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

The .code-block class is defined twice in this file (lines 36-38 and lines 68-70). The first definition sets margin-top: 20px and the second sets position: relative. These should be combined into a single rule block to avoid confusion and improve maintainability.

Copilot uses AI. Check for mistakes.
const text = codeBlock.textContent;
navigator.clipboard.writeText(text).then(() => {
button.textContent = 'Copied!';
setTimeout(() => (button.textContent = 'Copy'), 2000);
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

The clipboard API usage lacks error handling. If the clipboard write fails (e.g., due to browser permissions or HTTPS requirement), the promise rejection is not caught, which could lead to unhandled promise rejections. Consider adding a .catch() handler to provide user feedback when copying fails.

Suggested change
setTimeout(() => (button.textContent = 'Copy'), 2000);
setTimeout(() => (button.textContent = 'Copy'), 2000);
}).catch(() => {
button.textContent = 'Failed!';
setTimeout(() => (button.textContent = 'Copy'), 2000);

Copilot uses AI. Check for mistakes.
Comment on lines +35 to +39
<pre><code>
function calculateTip(bill, percentage) {
return (bill * percentage) / 100;
}
</code></pre>
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

The code inside the <code> tag has inconsistent indentation. The opening line starts on line 35, but the function code on lines 36-38 has extra leading whitespace that will be copied when users click the copy button. Consider removing the extra indentation to provide cleaner copied code, or adjust the indentation to be consistent with typical JavaScript formatting.

Copilot uses AI. Check for mistakes.
"devDependencies": {
"@honkit/honkit-plugin-ga": "^1.0.1",
"cz-conventional-changelog": "^3.3.0",
"cz-conventional-changelog": "^3.0.1",
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

This change downgrades cz-conventional-changelog from ^3.3.0 to ^3.0.1. Unless there's a specific reason for this downgrade (such as compatibility issues), it's generally better to keep dependencies at their latest compatible versions to benefit from bug fixes and improvements. Please verify if this downgrade is intentional.

Suggested change
"cz-conventional-changelog": "^3.0.1",
"cz-conventional-changelog": "^3.3.0",

Copilot uses AI. Check for mistakes.
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.

1 participant