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:
15
javascripts/copy-code.js
Normal file
15
javascripts/copy-code.js
Normal 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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user