forked from hobbyfarm/ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy code to clipboard (hobbyfarm#202)
* Copy code to clipboard * linting
- Loading branch information
Showing
6 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/app/hf-markdown/copy-to-clipboard/copy-to-clipboard.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<span class="copy-code" (click)="clicked()" title="Copy to Clipboard" | ||
><cds-icon shape="copy" inverse *ngIf="!wasClicked"></cds-icon | ||
><cds-icon shape="check" inverse *ngIf="wasClicked"></cds-icon | ||
></span> |
3 changes: 3 additions & 0 deletions
3
src/app/hf-markdown/copy-to-clipboard/copy-to-clipboard.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.copy-code { | ||
cursor: pointer; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/app/hf-markdown/copy-to-clipboard/copy-to-clipboard.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { CtrService } from 'src/app/scenario/ctr.service'; | ||
|
||
@Component({ | ||
selector: 'app-copy-to-clipboard', | ||
templateUrl: './copy-to-clipboard.component.html', | ||
styleUrls: ['./copy-to-clipboard.component.scss'], | ||
}) | ||
export class CopyToClipboardComponent { | ||
@Input() ctrId: string; | ||
|
||
wasClicked = false; | ||
|
||
constructor(private ctrService: CtrService) {} | ||
|
||
clicked() { | ||
const code = this.ctrService.getCodeById(this.ctrId); | ||
navigator.clipboard.writeText(code).then(() => { | ||
this.wasClicked = true; | ||
setTimeout(() => { | ||
this.wasClicked = false; | ||
}, 2500); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters