Skip to content

Commit b8f5b4a

Browse files
author
Thiago Bussola
committed
refactor(components/copy-button): changing clipboard button
changing clipboard button and changing copied text to icon
1 parent e4f2d43 commit b8f5b4a

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/app/shared/components/copy-button/copy-button.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
class="clipboard"
33
(click)="onCopy()"
44
[cdkCopyToClipboard]="elRef.nativeElement.lastElementChild.textContent"
5-
>{{buttonText | async}}</button>
6-
<ng-content></ng-content>
5+
>
6+
<mat-icon>{{ buttonIcon | async }}</mat-icon>
7+
</button>
8+
<ng-content></ng-content>

src/app/shared/components/copy-button/copy-button.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { BehaviorSubject, take, timer } from 'rxjs';
88
})
99
export class CopyButtonComponent {
1010
public elRef = inject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);
11-
public buttonText = new BehaviorSubject<string>('Copy');
11+
public buttonIcon = new BehaviorSubject<string>('content_copy');
1212

1313

1414
onCopy() {
15-
this.buttonText.next('Copied!');
15+
this.buttonIcon.next('check');
1616
timer(2000).pipe(take(1)).subscribe(() => {
17-
this.buttonText.next('Copy');
17+
this.buttonIcon.next('content_copy');
1818
});
1919
}
2020
}

src/app/shared/shared.module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import { HeaderAnchorDirective } from './directives/header-anchor.directive';
1414
import { ExtensionPipe } from './pipes/extension.pipe';
1515
import { CopyButtonComponent } from './components/copy-button/copy-button.component';
1616
import { ClipboardModule } from '@angular/cdk/clipboard';
17+
import { MatIconModule } from '@angular/material/icon';
1718

1819
@NgModule({
19-
imports: [CommonModule, ClipboardModule],
20+
imports: [CommonModule, ClipboardModule, MatIconModule],
2021
declarations: [
2122
ExtensionPipe,
2223
TabsComponent,
@@ -43,7 +44,7 @@ import { ClipboardModule } from '@angular/cdk/clipboard';
4344
BannerDevtoolsComponent,
4445
BannerCoursesAuthComponent,
4546
ThemeModeToggleComponent,
46-
CopyButtonComponent,
47+
CopyButtonComponent
4748
],
4849
providers: [StorageService],
4950
})

0 commit comments

Comments
 (0)