Examples
Use one editor contract across languages, themes, and form states.
Language examples
Edit JSON and shell source with the same adapter-based editor contract.
Language examples (Plain CSS)
code-editor-language-example.component.ts
ts
import { Component, signal } from '@angular/core';
import { TngCodeEditorComponent } from '@tailng-ui/components';
@Component({
selector: 'app-code-editor-language-example',
standalone: true,
imports: [TngCodeEditorComponent],
templateUrl: './code-editor-language-example.component.html',
styleUrl: './code-editor-language-example.component.css',
})
export class CodeEditorLanguageExampleComponent {
readonly jsonSource = signal('{\n "retries": 3,\n "mode": "safe"\n}');
readonly shellSource = signal('pnpm run test:components\npnpm run build:docs');
readonly codeTheme = signal<'github-dark' | 'github-light'>('github-light');
}code-editor-language-example.component.html
html
<div class="code-editor-example-grid">
<div class="code-editor-example-card">
<label for="json-source">JSON settings</label>
<tng-code-editor
id="json-source"
language="json"
adapter="shiki"
[theme]="codeTheme()"
[sanitizeHtml]="false"
[rows]="6"
[value]="jsonSource()"
(valueChange)="jsonSource.set($event)"
/>
</div>
<div class="code-editor-example-card">
<label for="shell-source">Shell commands</label>
<tng-code-editor
id="shell-source"
language="shell"
adapter="shiki"
[theme]="codeTheme()"
[sanitizeHtml]="false"
[rows]="6"
[value]="shellSource()"
(valueChange)="shellSource.set($event)"
/>
</div>
</div>code-editor-language-example.component.css
css
.code-editor-example-grid {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
}
.code-editor-example-card {
display: grid;
gap: 0.75rem;
padding: 1rem;
border: 1px solid var(--tng-semantic-border-subtle);
border-radius: 0.875rem;
background: var(--tng-semantic-background-surface);
}
.code-editor-example-card label,
.code-editor-example-card > span {
color: var(--tng-semantic-foreground-primary);
font-weight: 650;
}Language examples (Tailwind CSS)
code-editor-language-example.component.ts
ts
import { Component, signal } from '@angular/core';
import { TngCodeEditorComponent } from '@tailng-ui/components';
@Component({
selector: 'app-code-editor-language-example',
standalone: true,
imports: [TngCodeEditorComponent],
templateUrl: './code-editor-language-example.component.html',
styleUrl: './code-editor-language-example.component.css',
})
export class CodeEditorLanguageExampleComponent {
readonly jsonSource = signal('{\n "retries": 3,\n "mode": "safe"\n}');
readonly shellSource = signal('pnpm run test:components\npnpm run build:docs');
readonly codeTheme = signal<'github-dark' | 'github-light'>('github-light');
}code-editor-language-example.component.html
html
<div class="grid gap-4 lg:grid-cols-2">
<div class="grid gap-3 rounded-2xl border border-[var(--tng-semantic-border-subtle)] bg-[var(--tng-semantic-background-surface)] p-4">
<label for="json-source" class="font-semibold text-[var(--tng-semantic-foreground-primary)]">JSON settings</label>
<tng-code-editor
id="json-source"
language="json"
adapter="shiki"
[theme]="codeTheme()"
[sanitizeHtml]="false"
[rows]="6"
[value]="jsonSource()"
(valueChange)="jsonSource.set($event)"
/>
</div>
<div class="grid gap-3 rounded-2xl border border-[var(--tng-semantic-border-subtle)] bg-[var(--tng-semantic-background-surface)] p-4">
<label for="shell-source" class="font-semibold text-[var(--tng-semantic-foreground-primary)]">Shell commands</label>
<tng-code-editor
id="shell-source"
language="shell"
adapter="shiki"
[theme]="codeTheme()"
[sanitizeHtml]="false"
[rows]="6"
[value]="shellSource()"
(valueChange)="shellSource.set($event)"
/>
</div>
</div>code-editor-language-example.component.css
css
/* No component CSS is required; Tailwind utilities style the example layout. */Readonly and disabled
Compare selectable readonly source with a fully disabled editor.
Readonly and disabled (Plain CSS)
code-editor-form-states-example.component.ts
ts
import { Component, signal } from '@angular/core';
import { TngCodeEditorComponent } from '@tailng-ui/components';
@Component({
selector: 'app-code-editor-form-states-example',
standalone: true,
imports: [TngCodeEditorComponent],
templateUrl: './code-editor-form-states-example.component.html',
styleUrl: './code-editor-form-states-example.component.css',
})
export class CodeEditorFormStatesExampleComponent {
readonly jsonSource = signal('{ "mode": "readonly" }');
readonly shellSource = signal('echo "Disabled command"');
readonly codeTheme = signal<'github-dark' | 'github-light'>('github-light');
}code-editor-form-states-example.component.html
html
<div class="code-editor-example-grid">
<div class="code-editor-example-card">
<span>Readonly and selectable</span>
<tng-code-editor
ariaLabel="Readonly source"
language="json"
adapter="shiki"
[theme]="codeTheme()"
[sanitizeHtml]="false"
[rows]="4"
[readonly]="true"
[value]="jsonSource()"
/>
</div>
<div class="code-editor-example-card">
<span>Disabled</span>
<tng-code-editor
ariaLabel="Disabled source"
language="shell"
adapter="shiki"
[theme]="codeTheme()"
[sanitizeHtml]="false"
[rows]="4"
[disabled]="true"
[value]="shellSource()"
/>
</div>
</div>code-editor-form-states-example.component.css
css
.code-editor-example-grid {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
}
.code-editor-example-card {
display: grid;
gap: 0.75rem;
padding: 1rem;
border: 1px solid var(--tng-semantic-border-subtle);
border-radius: 0.875rem;
background: var(--tng-semantic-background-surface);
}
.code-editor-example-card label,
.code-editor-example-card > span {
color: var(--tng-semantic-foreground-primary);
font-weight: 650;
}Readonly and selectable
Disabled
Readonly and disabled (Tailwind CSS)
code-editor-form-states-example.component.ts
ts
import { Component, signal } from '@angular/core';
import { TngCodeEditorComponent } from '@tailng-ui/components';
@Component({
selector: 'app-code-editor-form-states-example',
standalone: true,
imports: [TngCodeEditorComponent],
templateUrl: './code-editor-form-states-example.component.html',
styleUrl: './code-editor-form-states-example.component.css',
})
export class CodeEditorFormStatesExampleComponent {
readonly jsonSource = signal('{ "mode": "readonly" }');
readonly shellSource = signal('echo "Disabled command"');
readonly codeTheme = signal<'github-dark' | 'github-light'>('github-light');
}code-editor-form-states-example.component.html
html
<div class="grid gap-4 lg:grid-cols-2">
<div class="grid gap-3 rounded-2xl border border-[var(--tng-semantic-border-subtle)] bg-[var(--tng-semantic-background-surface)] p-4">
<span class="font-semibold text-[var(--tng-semantic-foreground-primary)]">Readonly and selectable</span>
<tng-code-editor
ariaLabel="Readonly source"
language="json"
adapter="shiki"
[theme]="codeTheme()"
[sanitizeHtml]="false"
[rows]="4"
[readonly]="true"
[value]="jsonSource()"
/>
</div>
<div class="grid gap-3 rounded-2xl border border-[var(--tng-semantic-border-subtle)] bg-[var(--tng-semantic-background-surface)] p-4">
<span class="font-semibold text-[var(--tng-semantic-foreground-primary)]">Disabled</span>
<tng-code-editor
ariaLabel="Disabled source"
language="shell"
adapter="shiki"
[theme]="codeTheme()"
[sanitizeHtml]="false"
[rows]="4"
[disabled]="true"
[value]="shellSource()"
/>
</div>
</div>code-editor-form-states-example.component.css
css
/* No component CSS is required; Tailwind utilities style the example layout. */ Readonly and selectable
Disabled
Plain fallback
Turn highlighting off when source editing is useful without loading a language adapter.
Plain fallback (Plain CSS)
code-editor-fallback-example.component.ts
ts
import { Component, signal } from '@angular/core';
import { TngCodeEditorComponent } from '@tailng-ui/components';
@Component({
selector: 'app-code-editor-fallback-example',
standalone: true,
imports: [TngCodeEditorComponent],
templateUrl: './code-editor-fallback-example.component.html',
styleUrl: './code-editor-fallback-example.component.css',
})
export class CodeEditorFallbackExampleComponent {
readonly plainSource = signal('<unsafe> remains visible as text');
}code-editor-fallback-example.component.html
html
<div class="code-editor-example-card">
<label for="plain-source">Plain source</label>
<p>Highlighting is disabled, so no language adapter is loaded.</p>
<tng-code-editor
id="plain-source"
[highlight]="false"
[rows]="4"
[value]="plainSource()"
(valueChange)="plainSource.set($event)"
/>
</div>code-editor-fallback-example.component.css
css
.code-editor-example-grid {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
}
.code-editor-example-card {
display: grid;
gap: 0.75rem;
padding: 1rem;
border: 1px solid var(--tng-semantic-border-subtle);
border-radius: 0.875rem;
background: var(--tng-semantic-background-surface);
}
.code-editor-example-card label,
.code-editor-example-card > span {
color: var(--tng-semantic-foreground-primary);
font-weight: 650;
}Highlighting is disabled, so no language adapter is loaded.
Plain fallback (Tailwind CSS)
code-editor-fallback-example.component.ts
ts
import { Component, signal } from '@angular/core';
import { TngCodeEditorComponent } from '@tailng-ui/components';
@Component({
selector: 'app-code-editor-fallback-example',
standalone: true,
imports: [TngCodeEditorComponent],
templateUrl: './code-editor-fallback-example.component.html',
styleUrl: './code-editor-fallback-example.component.css',
})
export class CodeEditorFallbackExampleComponent {
readonly plainSource = signal('<unsafe> remains visible as text');
}code-editor-fallback-example.component.html
html
<div class="grid gap-3 rounded-2xl border border-[var(--tng-semantic-border-subtle)] bg-[var(--tng-semantic-background-surface)] p-4">
<label for="plain-source" class="font-semibold text-[var(--tng-semantic-foreground-primary)]">Plain source</label>
<p class="m-0 text-sm text-[var(--tng-semantic-foreground-secondary)]">Highlighting is disabled, so no language adapter is loaded.</p>
<tng-code-editor
id="plain-source"
[highlight]="false"
[rows]="4"
[value]="plainSource()"
(valueChange)="plainSource.set($event)"
/>
</div>code-editor-fallback-example.component.css
css
/* No component CSS is required; Tailwind utilities style the example layout. */Highlighting is disabled, so no language adapter is loaded.