Skip to content

Commit

Permalink
Noissue. Transfer copy feature to a new component
Browse files Browse the repository at this point in the history
  • Loading branch information
const8ine committed Feb 5, 2025
1 parent 3c94cb8 commit 56f6ded
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="copy-field">
<input type="text" readonly [value]="value">
<button (click)="copyToClipboard()">
<span class="fa far fa-copy"></span>
</button>
</div>
<div #copiedMessage class="hidden">
{{ 'footer_donation_copied' | translate }}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "../../../styles";

.copy-field {
@include copy-field(30px, $color-gray, $color-white, $color-gray-very-light);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Component,
ElementRef,
Input,
ViewChild,
} from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { TranslateService } from '@ngx-translate/core';

@Component({
selector: 'app-copy-field',
templateUrl: './copy-field.component.html',
styleUrls: ['./copy-field.component.scss'],
})
export class CopyFieldComponent {
@Input() value = '';
@ViewChild('copiedMessage') copiedMessage: ElementRef;

constructor(
private snackBar: MatSnackBar,
public translate: TranslateService
) {}

copyToClipboard(): void {
void navigator.clipboard
.writeText(this.value)
.then(() => {
this.snackBar.open(
this.copiedMessage.nativeElement.textContent,
'',
{
horizontalPosition: 'center',
verticalPosition: 'top',
duration: 600,
}
);
});
}
}
2 changes: 2 additions & 0 deletions src/app/components/ui-components/ui-components.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CarouselComponent } from './components/carousel/carousel.component';
import { CarouselItemDirective } from './components/carousel/carousel-item.directive';
import { DirectivesModule } from "../../directives/directives.module";
import { PageSubtitleComponent } from './components/page-subtitle/page-subtitle.component';
import { CopyFieldComponent } from './components/copy-field/copy-field.component';

const components = [
AccordionComponent,
Expand All @@ -47,6 +48,7 @@ const components = [
BannerComponent,
CarouselComponent,
PageSubtitleComponent,
CopyFieldComponent,
];

@NgModule({
Expand Down

0 comments on commit 56f6ded

Please sign in to comment.