Browse Source

UI: Improvement tb0copy-button component

pull/4695/head
Vladyslav Prykhodko 5 years ago
parent
commit
cf899b6ffd
  1. 4
      ui-ngx/src/app/shared/components/button/copy-button.component.html
  2. 2
      ui-ngx/src/app/shared/components/button/copy-button.component.scss
  3. 13
      ui-ngx/src/app/shared/components/button/copy-button.component.ts

4
ui-ngx/src/app/shared/components/button/copy-button.component.html

@ -20,8 +20,8 @@
[disabled]="disabled" [disabled]="disabled"
[matTooltip]="matTooltipText" [matTooltip]="matTooltipText"
[matTooltipPosition]="matTooltipPosition" [matTooltipPosition]="matTooltipPosition"
(mouseenter)="copied ? $event.stopImmediatePropagation():''" (mouseenter)="immediatePropagation($event)"
(mouseleave)="copied ? $event.stopImmediatePropagation():''" (mouseleave)="immediatePropagation($event)"
(click)="copy($event)"> (click)="copy($event)">
<mat-icon [svgIcon]="mdiIconSymbol" [ngStyle]="style" [ngClass]="{'copied': copied}"> <mat-icon [svgIcon]="mdiIconSymbol" [ngStyle]="style" [ngClass]="{'copied': copied}">
{{ iconSymbol }} {{ iconSymbol }}

2
ui-ngx/src/app/shared/components/button/copy-button.component.scss

@ -19,7 +19,7 @@
width: 32px; width: 32px;
line-height: 32px; line-height: 32px;
.mat-icon.copied{ .mat-icon.copied{
color: #00C851!important; color: #00C851 !important;
} }
} }
&:hover{ &:hover{

13
ui-ngx/src/app/shared/components/button/copy-button.component.ts

@ -14,9 +14,9 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { ChangeDetectorRef, Component, Input, ViewChild } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { ClipboardService } from 'ngx-clipboard'; import { ClipboardService } from 'ngx-clipboard';
import { MatTooltip, TooltipPosition } from '@angular/material/tooltip/tooltip'; import { MatTooltip, TooltipPosition } from '@angular/material/tooltip';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@Component({ @Component({
@ -52,6 +52,9 @@ export class CopyButtonComponent {
@Input() @Input()
style: {[key: string]: any} = {}; style: {[key: string]: any} = {};
@Output()
successCopied: EventEmitter<string>;
constructor(private clipboardService: ClipboardService, constructor(private clipboardService: ClipboardService,
private translate: TranslateService, private translate: TranslateService,
private cd: ChangeDetectorRef) { private cd: ChangeDetectorRef) {
@ -61,11 +64,11 @@ export class CopyButtonComponent {
copy($event: Event): void { copy($event: Event): void {
$event.stopPropagation(); $event.stopPropagation();
$event.preventDefault();
if (this.timer) { if (this.timer) {
clearTimeout(this.timer); clearTimeout(this.timer);
} }
this.clipboardService.copy(this.copyText); this.clipboardService.copy(this.copyText);
this.successCopied.emit(this.copyText);
this.copedIcon = 'done'; this.copedIcon = 'done';
this.copied = true; this.copied = true;
this.tooltip.show(); this.tooltip.show();
@ -92,4 +95,8 @@ export class CopyButtonComponent {
get matTooltipPosition(): TooltipPosition { get matTooltipPosition(): TooltipPosition {
return this.copied ? 'below' : this.tooltipPosition; return this.copied ? 'below' : this.tooltipPosition;
} }
immediatePropagation($event: Event): void {
this.copied ? $event.stopImmediatePropagation(): '';
}
} }

Loading…
Cancel
Save