1
0
mirror of synced 2025-12-22 11:26:57 -05:00

Add copy button to code blocks (#16052)

* Add deps

* Setup copy events

* Updoot

* Tweak styling

* Do a lil' proof-of-concept

* Updoot @github-docs/render-content

* Use SCSS variables for custom styles

* Adjust docs

* Ignore clipboard in check-deps

* Add copy annotation to quickstart workflow sample

Co-authored-by: Cynthia Rich <crichID@users.noreply.github.com>
This commit is contained in:
Jason Etcovitch
2020-10-16 10:55:35 -04:00
committed by GitHub
parent b92cafff5a
commit efed031ea4
9 changed files with 175 additions and 31 deletions

15
javascripts/copy-code.js Normal file
View File

@@ -0,0 +1,15 @@
import Clipboard from 'clipboard'
export default () => {
const clipboard = new Clipboard('button.js-btn-copy')
clipboard.on('success', evt => {
const btn = evt.trigger
const beforeTooltip = btn.getAttribute('aria-label')
btn.setAttribute('aria-label', 'Copied!')
setTimeout(() => {
btn.setAttribute('aria-label', beforeTooltip)
}, 2000)
})
}