-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3073 from aura-nw/baseline/main_20240305
Baseline/main 20240305
- Loading branch information
Showing
222 changed files
with
8,249 additions
and
3,566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Directive, ElementRef, Input } from '@angular/core'; | ||
import { NULL_ADDRESS } from '../constants/common.constant'; | ||
|
||
@Directive({ | ||
selector: 'copyBtn, [copyBtn]', | ||
}) | ||
export class CopyButtonDirective { | ||
@Input() copyBtn: string; | ||
@Input() isDisableCopy: boolean = false; | ||
@Input() btnClass: string[]; | ||
button; | ||
tooltip; | ||
|
||
constructor(private elRef: ElementRef) {} | ||
|
||
ngOnInit(): void { | ||
if (this.isDisableCopy || !this.copyBtn || this.copyBtn === NULL_ADDRESS) { | ||
return; | ||
} | ||
|
||
const element: HTMLElement = this.elRef.nativeElement; | ||
if (!element) return; | ||
const content = this.copyBtn; | ||
const parent = element.parentNode; | ||
const contain = document.createElement('div'); | ||
this.button = document.createElement('button'); | ||
|
||
const icon = document.createElement('i'); | ||
this.button.classList.add('button', 'button--xxs', 'position-relative', 'pr-0'); | ||
if (this.btnClass?.length > 0) { | ||
this.btnClass.forEach((c) => { | ||
this.button.classList.add(c); | ||
}); | ||
} | ||
icon.classList.add('ph', 'ph-copy', 'text--white', 'body-01'); | ||
contain.classList.add('d-inline-flex', 'align-items-center'); | ||
parent.replaceChild(contain, element); | ||
this.button.appendChild(icon); | ||
contain.appendChild(element); | ||
// tooltip | ||
this.tooltip = document.createElement('div'); | ||
this.tooltip.innerHTML = 'Copied!'; | ||
this.tooltip.classList.add('tooltip-copy'); | ||
this.button.appendChild(this.tooltip); | ||
contain.appendChild(this.button); | ||
|
||
// click show tooltip | ||
this.button.addEventListener('click', () => { | ||
this.tooltip.classList.add('show'); | ||
this.copyMessage(content); | ||
|
||
setTimeout(() => { | ||
this.tooltip.classList.remove('show'); | ||
}, 1000); | ||
}); | ||
} | ||
|
||
copyMessage(text: string) { | ||
const dummy = document.createElement('textarea'); | ||
document.body.appendChild(dummy); | ||
dummy.value = text; | ||
dummy.select(); | ||
document.execCommand('copy'); | ||
document.body.removeChild(dummy); | ||
} | ||
} |
Oops, something went wrong.