|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { Component, input } from '@angular/core'; |
| 9 | +import { Component, inject, input } from '@angular/core'; |
10 | 10 | import { CommonModule } from '@angular/common'; |
11 | 11 | import { Highlight } from 'ngx-highlightjs'; |
12 | 12 | import { MatIconModule } from '@angular/material/icon'; |
13 | | -import { MatProgressBarModule } from '@angular/material/progress-bar'; |
| 13 | +import { MagicAiService } from '../../../magic-ai/magic-ai.service'; |
14 | 14 |
|
15 | 15 | @Component({ |
16 | 16 | selector: 'adev-code-snippet', |
17 | 17 | standalone: true, |
18 | | - imports: [CommonModule, Highlight, MatIconModule, MatProgressBarModule], |
19 | | - template: `@if (code() && language()) { |
| 18 | + imports: [CommonModule, Highlight, MatIconModule], |
| 19 | + template: ` |
| 20 | +
|
| 21 | +@if (!code() || !language() || !this.magicAiService.isStreamComplete()) { |
| 22 | + <div class="code-snippet-container"> |
| 23 | + <div class="placeholder-loading"> |
| 24 | + <p>Loading...</p> |
| 25 | + </div> |
| 26 | + </div> |
| 27 | +} @else { |
20 | 28 | <div class="code-snippet-container"> |
21 | 29 | <pre><code [highlight]="code()!" [language]="language()!"></code></pre> |
22 | 30 | <button class="copy-button" (click)="copyCode()"> |
23 | 31 | <mat-icon>content_copy</mat-icon> |
24 | 32 | </button> |
25 | 33 | </div> |
26 | | -} @else { |
27 | | - <div class="code-snippet-container"> |
28 | | - <mat-progress-bar mode="indeterminate"></mat-progress-bar> |
29 | | - </div> |
30 | 34 | }`, |
31 | 35 | styles: [`.code-snippet-container { |
32 | 36 | position: relative; |
@@ -63,10 +67,23 @@ import { MatProgressBarModule } from '@angular/material/progress-bar'; |
63 | 67 | code { |
64 | 68 | border: var(--adev-docs-border-default); |
65 | 69 | border-radius: var(--adev-docs-border-radius-md); |
| 70 | + margin: 10px 0; |
| 71 | +} |
| 72 | +
|
| 73 | +.placeholder-loading { |
| 74 | + background-color: #282c34; |
| 75 | + min-height: 30px; |
| 76 | + color: #abb2bf; |
| 77 | + border: var(--adev-docs-border-default); |
| 78 | + border-radius: var(--adev-docs-border-radius-md); |
| 79 | + padding: 16px; |
| 80 | + font-family: var(--default-mono-font-family); |
| 81 | + margin: 10px 0; |
66 | 82 | } |
67 | 83 | `], |
68 | 84 | }) |
69 | 85 | export class CodeSnippetComponent { |
| 86 | + magicAiService = inject(MagicAiService); |
70 | 87 | code = input<string | undefined>(); |
71 | 88 | language = input<string | undefined>(); |
72 | 89 |
|
|
0 commit comments