mirror of
https://github.com/mempool/mempool.git
synced 2025-01-10 07:26:46 +01:00
36 lines
1005 B
TypeScript
36 lines
1005 B
TypeScript
import { Component, ViewChild, ElementRef, AfterViewInit, Input, ChangeDetectionStrategy } from '@angular/core';
|
|
import * as ClipboardJS from 'clipboard';
|
|
import * as tlite from 'tlite';
|
|
|
|
@Component({
|
|
selector: 'app-clipboard',
|
|
templateUrl: './clipboard.component.html',
|
|
styleUrls: ['./clipboard.component.scss'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class ClipboardComponent implements AfterViewInit {
|
|
@ViewChild('btn') btn: ElementRef;
|
|
@ViewChild('buttonWrapper') buttonWrapper: ElementRef;
|
|
@Input() text: string;
|
|
copiedMessage: string = $localize`:@@clipboard.copied-message:Copied!`;
|
|
|
|
clipboard: any;
|
|
|
|
constructor() { }
|
|
|
|
ngAfterViewInit() {
|
|
this.clipboard = new ClipboardJS(this.btn.nativeElement);
|
|
this.clipboard.on('success', () => {
|
|
tlite.show(this.buttonWrapper.nativeElement);
|
|
setTimeout(() => {
|
|
tlite.hide(this.buttonWrapper.nativeElement);
|
|
}, 1000);
|
|
});
|
|
}
|
|
|
|
onDestroy() {
|
|
this.clipboard.destroy();
|
|
}
|
|
|
|
}
|