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

Add code copy buttons to docs #883

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from
Draft

Add code copy buttons to docs #883

wants to merge 20 commits into from

Conversation

dancormier
Copy link
Contributor

Addresses #829

For now, I've only applied it to product/components/cards to keep myself from having to change it in 1000 places. It's out of draft to solicit some 👍/👎 on the approach, but consider this in "do-not-merge" territory.

TODO

  • Add copy button to all code snippets

Preview

2022-03-22 18 10 48

@dancormier dancormier added do-not-merge Pull requests that are in progress and should not be merged yet work-in-progress A work in progress, not meant to merge documentation labels Mar 22, 2022
@dancormier dancormier changed the title Add code copy buttons to Card page Add code copy buttons to docs Mar 22, 2022
@dancormier dancormier linked an issue Mar 22, 2022 that may be closed by this pull request
@netlify
Copy link

netlify bot commented Mar 22, 2022

Deploy Preview for stacks ready!

Name Link
🔨 Latest commit 3ea29dd
🔍 Latest deploy log https://app.netlify.com/sites/stacks/deploys/62c6fc2c693acf0009d0a4f3
😎 Deploy Preview https://deploy-preview-883--stacks.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Collaborator

@b-kelly b-kelly left a comment

Choose a reason for hiding this comment

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

I like this approach! I'd recommend implementing this on the checkbox page as well to see how the button looks in a codeblock that has horizontal scrolling (partially obscuring the code).

docs/assets/js/controllers/clipboard.ts Outdated Show resolved Hide resolved
@@ -9,13 +9,18 @@
<p class="stacks-copy">The base card styling applies a border and padding to the card.</p>
<p class="stacks-copy">Cards can be any size and it’s ok to increase the body text size for larger cards.</p>
<div class="stacks-preview">
<div class="stacks-clipboard-content ps-relative" data-controller="clipboard">
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could/should probably extend/replace the highlight shortcode to include the copy/paste button as well. That way we'd get it "for free" and wouldn't have to add boilerplate all over the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to add the copy button to the highlight shortcode, but also have it available standalone. This will allow us to add a copy button to any element, like so:

image

It's a contrived example, but I think it illustrates the point.

docs/assets/js/controllers/clipboard.ts Outdated Show resolved Hide resolved
docs/.eleventy.js Outdated Show resolved Hide resolved
docs/.eleventy.js Outdated Show resolved Hide resolved
b-kelly pushed a commit that referenced this pull request May 23, 2022
@b-kelly b-kelly force-pushed the code-copy-btn branch 2 times, most recently from c501836 to aa84fc3 Compare May 23, 2022 18:28
@dancormier dancormier marked this pull request as draft July 6, 2022 21:47
@MaxHorstmann
Copy link

Love this! Any chance we'll see it on SO one day? :)

@dancormier
Copy link
Contributor Author

Hey @MaxHorstmann! Nice to hear from you!

These specific copy buttons are intended for the Stacks docs only, but I personally love the idea of introducing them to Stack Overflow, writ large. We have the s-codeblock component and we could enhance that component with some copy JS. I'll spread the idea around and see if it takes.

@MaxHorstmann
Copy link

@dancormier hey Dan, good to hear from you as well! Would be great to have this on code snippets on SO questions & answers, like on GitHub and many docs pages (random example) these days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge Pull requests that are in progress and should not be merged yet documentation work-in-progress A work in progress, not meant to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add copy to clipboard button to code blocks
6 participants