|
| 1 | +import { ChangeDetectionStrategy, Component, signal } from '@angular/core'; |
| 2 | +import { NgIcon, provideIcons } from '@ng-icons/core'; |
| 3 | +import { lucideDownload, lucideTerminal, lucideWrapText } from '@ng-icons/lucide'; |
| 4 | +import { HlmButton } from '@spartan-ng/helm/button'; |
| 5 | +import { HlmCodeBlockImports } from '@spartan-ng/helm/code-block'; |
| 6 | + |
| 7 | +@Component({ |
| 8 | + selector: 'spartan-code-block-actions', |
| 9 | + imports: [HlmCodeBlockImports, HlmButton, NgIcon], |
| 10 | + providers: [provideIcons({ lucideTerminal, lucideWrapText, lucideDownload })], |
| 11 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 12 | + template: ` |
| 13 | + <div class="w-full max-w-md"> |
| 14 | + <hlm-code-block> |
| 15 | + <hlm-code-block-header> |
| 16 | + <hlm-code-block-title> |
| 17 | + <ng-icon name="lucideTerminal" /> |
| 18 | + Terminal |
| 19 | + </hlm-code-block-title> |
| 20 | + <hlm-code-block-actions> |
| 21 | + <button |
| 22 | + hlmBtn |
| 23 | + variant="ghost" |
| 24 | + size="icon-xs" |
| 25 | + aria-label="Wrap lines" |
| 26 | + [attr.aria-pressed]="_wrap()" |
| 27 | + (click)="_wrap.set(!_wrap())" |
| 28 | + > |
| 29 | + <ng-icon name="lucideWrapText" /> |
| 30 | + </button> |
| 31 | + <button |
| 32 | + hlmBtn |
| 33 | + variant="ghost" |
| 34 | + size="icon-xs" |
| 35 | + aria-label="Download" |
| 36 | + (click)="_download(_output, 'lint.log')" |
| 37 | + > |
| 38 | + <ng-icon name="lucideDownload" /> |
| 39 | + </button> |
| 40 | + <button hlmCodeBlockCopyButton [value]="_output"></button> |
| 41 | + </hlm-code-block-actions> |
| 42 | + </hlm-code-block-header> |
| 43 | + <pre hlmCodeBlockContent [code]="_output" [wrap]="_wrap()"></pre> |
| 44 | + </hlm-code-block> |
| 45 | + </div> |
| 46 | + `, |
| 47 | +}) |
| 48 | +export class CodeBlockActions { |
| 49 | + protected readonly _wrap = signal(false); |
| 50 | + |
| 51 | + protected readonly _output = `$ pnpm lint |
| 52 | +apps/web/src/app/message-list.component.ts |
| 53 | + 18:22 error Unsafe call of an \`any\` typed value @typescript-eslint/no-unsafe-call |
| 54 | + 42:7 warning 'scrollToBottom' is assigned a value but never used @typescript-eslint/no-unused-vars |
| 55 | +
|
| 56 | +✖ 2 problems (1 error, 1 warning)`; |
| 57 | + |
| 58 | + protected _download(value: string, filename: string): void { |
| 59 | + const url = URL.createObjectURL(new Blob([value], { type: 'text/plain' })); |
| 60 | + const link = document.createElement('a'); |
| 61 | + link.href = url; |
| 62 | + link.download = filename; |
| 63 | + link.click(); |
| 64 | + URL.revokeObjectURL(url); |
| 65 | + } |
| 66 | +} |
0 commit comments