Code Block

Displays code, terminal output and diffs with an optional header, line numbers and a copy button.

app/hello.component.ts
import { Component, input } from '@angular/core';

@Component({
  selector: 'app-hello',
  template: `<p>Hello, {{ name() }}!</p>`,
})
export class HelloComponent {
  readonly name = input('Angular');
}

Installation

ng g @spartan-ng/cli:ui code-block

Usage

import { HlmCodeBlockImports } from '@spartan-ng/helm/code-block';
<hlm-code-block>
  <hlm-code-block-header>
    <hlm-code-block-title>Terminal</hlm-code-block-title>
    <hlm-code-block-actions>
      <button hlmCodeBlockCopyButton [value]="output"></button>
    </hlm-code-block-actions>
  </hlm-code-block-header>
  <pre hlmCodeBlockContent [code]="output"></pre>
</hlm-code-block>

Examples

Basic

$ pnpm build
> ng build

✔ Browser application bundle generation complete.

Initial chunk files | Names     |  Raw size
polyfills.js        | polyfills |  34.52 kB
main.js             | main      | 210.45 kB

Output location: dist/app
Terminal
$ pnpm add -D @spartan-ng/cli
Packages: +14
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0

Actions

Terminal
$ pnpm lint
apps/web/src/app/message-list.component.ts
  18:22  error    Unsafe call of an `any` typed value  @typescript-eslint/no-unsafe-call
  42:7   warning  'scrollToBottom' is assigned a value but never used  @typescript-eslint/no-unused-vars

✖ 2 problems (1 error, 1 warning)

Floating Actions

$ pnpm add @spartan-ng/brain
Progress: resolved 412, reused 398, downloaded 14, added 14, done
dependencies:
+ @angular/cdk 20.2.0
+ @spartan-ng/brain 1.0.0
+ @spartan-ng/helm 1.0.0
Done in 2.8s using pnpm v10.18.0

Line Numbers

{  "name": "chat",  "private": true,  "scripts": {    "start": "ng serve",    "build": "ng build"  }}

Start Line

app/dashboard/dashboard.component.ts
  if (!this._session) {    this._router.navigate(['/login']);  }
  return this._db.project.findMany({    where: { ownerId: this._session.userId },    orderBy: { updatedAt: 'desc' },  });}

Wrap

Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'Angular'. Current value: 'Angular 20'. Find more at https://angular.dev/errors/NG0100
Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'Angular'. Current value: 'Angular 20'. Find more at https://angular.dev/errors/NG0100

Highlighted Lines

					
						{
					
						  "projects": {
					
						    "app": {
					
						      "architect": {
					
						        "build": {
					
						          "options": {
					
						            "outputPath": "dist/app",
					
						            "index": "src/index.html",
					
						            "browser": "src/main.ts"
					
						          }
					
						        }
					
						      }
					
						    }
					
						  }
					
						}
					

Diff

app/greeting.component.ts
					
						export class GreetingComponent {
					
						  protected readonly greeting = "Hello, " + this.name;
					
						  protected readonly greeting = computed(() => `Hello, ${this.name()}! Welcome back.`);
					
						  readonly name = input('Angular');
					
						}
					

Height

Logs
[01] GET /api/health 200 in 12ms
[02] GET /api/health 200 in 19ms
[03] GET /api/health 200 in 26ms
[04] GET /api/health 200 in 33ms
[05] GET /api/health 200 in 40ms
[06] GET /api/health 200 in 47ms
[07] GET /api/health 200 in 14ms
[08] GET /api/health 200 in 21ms
[09] GET /api/health 200 in 28ms
[10] GET /api/health 200 in 35ms
[11] GET /api/health 200 in 42ms
[12] GET /api/health 200 in 49ms
[13] GET /api/health 200 in 16ms
[14] GET /api/health 200 in 23ms
[15] GET /api/health 200 in 30ms
[16] GET /api/health 200 in 37ms
[17] GET /api/health 200 in 44ms
[18] GET /api/health 200 in 51ms
[19] GET /api/health 200 in 18ms
[20] GET /api/health 200 in 25ms
[21] GET /api/health 200 in 32ms
[22] GET /api/health 200 in 39ms
[23] GET /api/health 200 in 46ms
[24] GET /api/health 200 in 53ms
[25] GET /api/health 200 in 20ms
[26] GET /api/health 200 in 27ms
[27] GET /api/health 200 in 34ms
[28] GET /api/health 200 in 41ms
[29] GET /api/health 200 in 48ms
[30] GET /api/health 200 in 55ms
[31] GET /api/health 200 in 22ms
[32] GET /api/health 200 in 29ms
[33] GET /api/health 200 in 36ms
[34] GET /api/health 200 in 43ms
[35] GET /api/health 200 in 50ms
[36] GET /api/health 200 in 57ms
[37] GET /api/health 200 in 24ms
[38] GET /api/health 200 in 31ms
[39] GET /api/health 200 in 38ms
[40] GET /api/health 200 in 45ms

Size

Terminal
$ pnpm add @spartan-ng/brain
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0
Terminal
$ pnpm add @spartan-ng/brain
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0

Destructive

Error
TypeError: Cannot read properties of undefined (reading 'pipe')
    at MessageListComponent.ngOnInit (app/message-list.component.ts:18:22)
    at callHook (core.mjs:16305:18)

RTL

To enable RTL support in spartan-ng, see the RTL configuration guide.

ثبّت الحزم، ثم شغّل خادم التطوير.

الطرفية
pnpm add @spartan-ng/brain
pnpm start

Helm API

HlmCodeBlockActions

Selector: [hlmCodeBlockActions],hlm-code-block-actions

ExportAs: hlmCodeBlockActions

HlmCodeBlockContent

Selector: pre[hlmCodeBlockContent]

ExportAs: hlmCodeBlockContent

Inputs

PropTypeDefaultDescription
wrap boolean false -
lineNumbers boolean false -
startLine number 1 -
code string - When set, the code is rendered line by line instead of projecting `<ng-content />`.

HlmCodeBlockCopyButton

Selector: button[hlmCodeBlockCopyButton]

ExportAs: hlmCodeBlockCopyButton

Inputs

PropTypeDefaultDescription
value string '' -
copyText string 'Copy' -
copiedText string 'Copied' -
variant ButtonVariants['variant'] this._config.variant -
size ButtonVariants['size'] this._config.size -

HlmCodeBlockFooter

Selector: [hlmCodeBlockFooter],hlm-code-block-footer

ExportAs: hlmCodeBlockFooter

HlmCodeBlockHeader

Selector: [hlmCodeBlockHeader],hlm-code-block-header

ExportAs: hlmCodeBlockHeader

HlmCodeBlockLine

Selector: span[hlmCodeBlockLine]

ExportAs: hlmCodeBlockLine

Inputs

PropTypeDefaultDescription
variant CodeBlockLineVariants['variant'] 'default' -

HlmCodeBlockTitle

Selector: [hlmCodeBlockTitle],hlm-code-block-title

ExportAs: hlmCodeBlockTitle

HlmCodeBlock

Selector: [hlmCodeBlock],hlm-code-block

ExportAs: hlmCodeBlock

Inputs

PropTypeDefaultDescription
variant CodeBlockVariants['variant'] 'default' -
size 'default' | 'sm' 'default' -
Collapsible Checkbox