@@ -2,15 +2,16 @@ import {
22 CodeBlockStyle ,
33 CodeHighlightStyle ,
44 CopyButtonStyle ,
5- LineCountStyle ,
6- } from "./styles" ;
7- import React from "react" ;
8- import copy from "copy-to-clipboard" ;
5+ LineCountStyle
6+ } from './styles' ;
7+ import React from 'react' ;
8+ import copy from 'copy-to-clipboard' ;
9+ import { trackCopyClicks } from '../../utils/track' ;
910
10- const COPY = " copy" ;
11- const COPIED = " copied" ;
12- const FAILED = " failed to copy" ;
13- const CONSOLE = " console" ;
11+ const COPY = ' copy' ;
12+ const COPIED = ' copied' ;
13+ const FAILED = ' failed to copy' ;
14+ const CONSOLE = ' console' ;
1415
1516type CopyMessageType = typeof COPY | typeof COPIED | typeof FAILED ;
1617
@@ -29,7 +30,7 @@ class CodeBlock extends React.Component<CodeBlockProps, CodeBlockState> {
2930
3031 constructor ( props ) {
3132 super ( props ) ;
32- this . state = { copyMessage : COPY } ;
33+ this . state = { copyMessage : COPY } ;
3334 }
3435
3536 lineNumbers = ( ) => {
@@ -56,12 +57,13 @@ class CodeBlock extends React.Component<CodeBlockProps, CodeBlockState> {
5657 copyToClipboard = ( ) => {
5758 if ( this . element && this . element . textContent ) {
5859 copy ( this . element . textContent ) ;
59- this . setState ( { copyMessage : COPIED } ) ;
60+ trackCopyClicks ( this . element . textContent ) ;
61+ this . setState ( { copyMessage : COPIED } ) ;
6062 } else {
61- this . setState ( { copyMessage : FAILED } ) ;
63+ this . setState ( { copyMessage : FAILED } ) ;
6264 }
6365 setTimeout ( ( ) => {
64- this . setState ( { copyMessage : COPY } ) ;
66+ this . setState ( { copyMessage : COPY } ) ;
6567 } , 1500 ) ;
6668 } ;
6769
@@ -78,7 +80,7 @@ class CodeBlock extends React.Component<CodeBlockProps, CodeBlockState> {
7880 render ( ) {
7981 if ( this . props . children === undefined ) return < div > </ div > ;
8082 const oneLine =
81- this . props . lineCount === "1" || this . props . language === CONSOLE ;
83+ this . props . lineCount === '1' || this . props . language === CONSOLE ;
8284
8385 return (
8486 < CodeBlockStyle oneLine = { oneLine } >
0 commit comments