-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add copy button for code snippet #3281
Conversation
In our meeting today we discussed copying how GitHub does this, so that you only see the "copy" button when you mouse over the area, and it is removed when you leave that area. We should see what they do with touch events for mobile. Also, I wonder if we should steal their icon too vs. using the "copy" text? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of listening to the mouse move, you can use mouseenter/mouseleave
event handler. I suggest that you do the followings:
const snippets = post.querySelectorAll('pre code')
snippet.onmouseenter = () => { const button = createButton(); button.onclick = () => copySnippet(snippet.text); snippet.appendChild(button); }
snippet.onmouseleave = removeButton
@menghif, I was playing around with this PR, trying to make |
Hello! Please rebase, as the following commit 6046273 has reorganized our file structure! |
This now shows/hides the button as expected |
It's so cool to see you took some inspiration from me 😄 |
I put you as a co-author 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, but I don't think the code is ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got rid of my previous feedback - I'm also loving the instant feedback that the click has registered and has copied the code block! Nice work team!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks amazing! Thank you @DukeManh for making it great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I'd like to see an issue filed to deal with the difference between how the two copy buttons work. We should re-use the same component or at least have the styles be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #3356 follow-up.
Co-authored-by: @TueeNguyen
c692e46
to
3635277
Compare
Issue This PR Addresses
Fixes #2923
Type of Change
Description
Steps to test the PR
pnpm i
cp config/env.staging .env
pnpm dev
Checklist