Skip to content
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

feat: add copy button to viewer #70

Merged
merged 6 commits into from
Oct 22, 2022

Conversation

hay-kot
Copy link
Contributor

@hay-kot hay-kot commented Oct 1, 2022

Closes #53

CleanShot 2022-09-30 at 21 37 42@2x

@hay-kot hay-kot changed the title add copy button to viewer feat: add copy button to viewer Oct 1, 2022
Copy link
Owner

@szabodanika szabodanika left a comment

Choose a reason for hiding this comment

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

Thank you for this PR, very very useful feature and simple implementation. Just to make the UI blend in with the rest of the application a bit better, I would make a few small changes, please see suggestions. With these changes I am happy to merge it right away

Comment on lines 20 to 24
<button id="copy-button" class="copy-button">
<svg id="copy-icon" style="width:24px;height:24px" viewBox="0 0 24 24">
<path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
</svg>
</button>
Copy link
Owner

Choose a reason for hiding this comment

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

Let's keep this text based for now I think. It will also allow us to change the text

 <a id="copy-button" class="copy-button">
   Copy
 </a>

const content = `{{ pasta.content_escaped() }}`

btn.addEventListener("click", () => {
navigator.clipboard.writeText(content)
Copy link
Owner

Choose a reason for hiding this comment

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

Let's change the button text to Copied here:

btn.innerText = "Copied"

Comment on lines 82 to 83
padding: 8px;
margin: 5px;
Copy link
Owner

Choose a reason for hiding this comment

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

Adjusted placing for the new shape, plus change cursor type to show it's interactive:

padding: 3px;
margin: 3px;
cursor: pointer;

@hay-kot
Copy link
Contributor Author

hay-kot commented Oct 22, 2022

Should be good. I didn't add cursor: pointer; because that should already be applied since it's a button element.

CleanShot 2022-10-22 at 10 11 02

@@ -80,6 +80,10 @@
pub fn content_not_highlighted(&self) -> String {
html_highlight(&self.content, "txt")
}

pub fn content_escaped(&self) -> String {
self.content.replace("`", "\\`").replace("$", "\\$")

Check warning

Code scanning / clippy

single-character string constant used as pattern

single-character string constant used as pattern
@@ -80,6 +80,10 @@
pub fn content_not_highlighted(&self) -> String {
html_highlight(&self.content, "txt")
}

pub fn content_escaped(&self) -> String {
self.content.replace("`", "\\`").replace("$", "\\$")

Check warning

Code scanning / clippy

single-character string constant used as pattern

single-character string constant used as pattern
@szabodanika
Copy link
Owner

Should be good. I didn't add cursor: pointer; because that should already be applied since it's a button element.

This suggestion would change it from a button to a link (to make it look the same as all the other actions): #70 (comment)

kép

@szabodanika
Copy link
Owner

Looks and works great, thank you so much!

@szabodanika szabodanika merged commit 3e58ba3 into szabodanika:master Oct 22, 2022
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.

copy button in pasta field
2 participants