Files
Picsur/frontend/src/app/components/copyfield/copyfield.component.ts

30 lines
863 B
TypeScript
Raw Normal View History

2022-03-21 21:21:21 +01:00
import { Clipboard } from '@angular/cdk/clipboard';
2022-02-28 23:18:07 +01:00
import { Component, Input } from '@angular/core';
2022-03-01 21:51:21 +01:00
import { SnackBarType } from 'src/app/models/snack-bar-type';
import { UtilService } from 'src/app/util/util.service';
2022-02-28 23:18:07 +01:00
@Component({
2022-03-03 22:48:03 +01:00
selector: 'copyfield',
templateUrl: './copyfield.component.html',
styleUrls: ['./copyfield.component.scss'],
2022-02-28 23:18:07 +01:00
})
export class CopyFieldComponent {
// Two paramets: name, value
2022-03-01 20:41:55 +01:00
@Input() label: string = 'Loading...';
@Input() value: string = 'Loading...';
2022-03-21 21:21:21 +01:00
constructor(private utilService: UtilService, private clipboard: Clipboard) {}
2022-02-28 23:18:07 +01:00
public copy() {
2022-03-21 21:21:21 +01:00
if (this.clipboard.copy(this.value)) {
this.utilService.showSnackBar(`Copied ${this.label}!`, SnackBarType.Info);
return;
2022-03-01 21:51:21 +01:00
}
2022-02-28 23:18:07 +01:00
2022-03-21 21:21:21 +01:00
return this.utilService.showSnackBar(
'Copying to clipboard failed',
SnackBarType.Error
);
2022-02-28 23:18:07 +01:00
}
}