Copies the content of a code block when its copy button is clicked.
(event: MouseEvent)
| 224 | |
| 225 | /** Copies the content of a code block when its copy button is clicked. */ |
| 226 | protected _handleClick(event: MouseEvent) { |
| 227 | const button = (event.target as HTMLElement).closest('.docs-markdown-copy-button'); |
| 228 | const code = button?.parentElement?.querySelector('code'); |
| 229 | |
| 230 | if (code) { |
| 231 | const message = this._clipboard.copy(code.textContent || '') |
| 232 | ? 'Copied code snippet' |
| 233 | : 'Failed to copy code snippet'; |
| 234 | this._snackbar.open(message, undefined, {duration: 2500}); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | ngOnDestroy() { |
| 239 | this._clearLiveExamples(); |