File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,19 @@ export default class HTMLCodeBlockElement extends HTMLElement {
74
74
#language: string = '' ;
75
75
/** Actual value of the accessor `controls` */
76
76
#controls: boolean = false ;
77
+ /** Click event handler of copy button */
78
+ #onClickButton = ( ( ) => {
79
+ let key = - 1 ;
80
+
81
+ return ( ) => {
82
+ clearTimeout ( key ) ;
83
+
84
+ this . #copyButton. textContent = 'Copied!' ;
85
+ key = window . setTimeout ( ( ) => {
86
+ this . #copyButton. textContent = 'Copy' ;
87
+ } , 1500 ) ;
88
+ } ;
89
+ } ) ( ) ;
77
90
/** Outputs the resulting syntax-highlighted markup to the DOM. */
78
91
#render = function ( this : HTMLCodeBlockElement ) {
79
92
if ( ! this . parentNode ) {
@@ -156,7 +169,6 @@ export default class HTMLCodeBlockElement extends HTMLElement {
156
169
}
157
170
158
171
set controls ( value : boolean ) {
159
- // TODO: コピーボタンの表示切り替え
160
172
this . #controls = value ;
161
173
162
174
if ( this . #controls) {
@@ -223,8 +235,10 @@ export default class HTMLCodeBlockElement extends HTMLElement {
223
235
const copyButton = ( ( ) => {
224
236
const button = document . createElement ( 'button' ) ;
225
237
238
+ button . type = 'button' ;
226
239
button . slot = 'copy-button' ;
227
240
button . textContent = 'Copy' ;
241
+ button . addEventListener ( 'click' , this . #onClickButton) ;
228
242
229
243
return button ;
230
244
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments