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 {
7474 #language: string = '' ;
7575 /** Actual value of the accessor `controls` */
7676 #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+ } ) ( ) ;
7790 /** Outputs the resulting syntax-highlighted markup to the DOM. */
7891 #render = function ( this : HTMLCodeBlockElement ) {
7992 if ( ! this . parentNode ) {
@@ -156,7 +169,6 @@ export default class HTMLCodeBlockElement extends HTMLElement {
156169 }
157170
158171 set controls ( value : boolean ) {
159- // TODO: コピーボタンの表示切り替え
160172 this . #controls = value ;
161173
162174 if ( this . #controls) {
@@ -223,8 +235,10 @@ export default class HTMLCodeBlockElement extends HTMLElement {
223235 const copyButton = ( ( ) => {
224236 const button = document . createElement ( 'button' ) ;
225237
238+ button . type = 'button' ;
226239 button . slot = 'copy-button' ;
227240 button . textContent = 'Copy' ;
241+ button . addEventListener ( 'click' , this . #onClickButton) ;
228242
229243 return button ;
230244 } ) ( ) ;
You can’t perform that action at this time.
0 commit comments