Files
Picsur/frontend/src/app/components/copy-field/copy-field.component.ts

30 lines
889 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-06-05 12:20:16 +02:00
import { SnackBarType } from 'src/app/models/dto/snack-bar-type.dto';
2022-04-18 14:46:52 +02:00
import { UtilService } from 'src/app/util/util-module/util.service';
2022-02-28 23:18:07 +01:00
@Component({
2022-04-18 14:46:52 +02:00
selector: 'copy-field',
templateUrl: './copy-field.component.html',
styleUrls: ['./copy-field.component.scss'],
2022-02-28 23:18:07 +01:00
})
export class CopyFieldComponent {
2022-03-28 16:47:07 +02:00
// Two parameters: 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',
2022-06-05 12:20:16 +02:00
SnackBarType.Error,
2022-03-21 21:21:21 +01:00
);
2022-02-28 23:18:07 +01:00
}
}