diff --git a/resources/ts/code-block-helper.ts b/resources/ts/code-block-helper.ts index 34f7e79c..993041d0 100644 --- a/resources/ts/code-block-helper.ts +++ b/resources/ts/code-block-helper.ts @@ -5,7 +5,7 @@ declare global { } // use Tailwind CSS class names -const baseButtonClassName: string[] = [ +const BASE_BUTTON_CLASS_NAME: string[] = [ 'fixed', 'size-8', 'flex', @@ -26,31 +26,41 @@ const baseButtonClassName: string[] = [ 'duration-200', ]; -const checkIcon: string = ` +const CHECK_ICON_SVG: string = ` `; -const clipboardIcon: string = ` +const CLIPBOARD_ICON_SVG: string = ` `; -const arrowsAngleExpandIcon: string = ` +const ARROWS_ANGLE_EXPAND_ICON_SVG: string = ` `; +const X_CIRCLE_FILL_ICON_SVG: string = ` + +`; + +const BACKGROUND_BACKDROP_ID: string = 'expand-code-block-background-backdrop'; +const MODAL_PANEL_ID: string = 'expand-code-block-modal-panel'; +const CLOSE_MODAL_BUTTON_ID: string = 'expand-code-block-close-modal-button'; + function createCopyCodeButton(code: string): HTMLButtonElement { // create copy button const copyButton: HTMLButtonElement = document.createElement('button'); - copyButton.classList.add(...baseButtonClassName); + copyButton.classList.add(...BASE_BUTTON_CLASS_NAME); // set button position copyButton.classList.add('top-2', 'right-2'); - copyButton.innerHTML = clipboardIcon; + copyButton.innerHTML = CLIPBOARD_ICON_SVG; // when copy button is clicked, copy code to clipboard copyButton.addEventListener('click', function (this: HTMLButtonElement) { @@ -61,10 +71,10 @@ function createCopyCodeButton(code: string): HTMLButtonElement { ); // change button icon to "Copied!" for 2 seconds - this.innerHTML = checkIcon; + this.innerHTML = CHECK_ICON_SVG; setTimeout( function (this: HTMLButtonElement) { - this.innerHTML = clipboardIcon; + this.innerHTML = CLIPBOARD_ICON_SVG; }.bind(this), 2000, ); @@ -73,14 +83,22 @@ function createCopyCodeButton(code: string): HTMLButtonElement { return copyButton; } -function modalTemplate(html: string, closeModalButtonId: string): string { +function modalTemplate(html: string): string { return `