Skip to content
tcpsystemsui

Theme

Colour scheme
Accent
Density
Radius
Esc

DiffViewer

Bounded controlled unified or split diff rows.

beta

Examples

Unified

studio.toml changes: 1–5 / 5

studio.toml changes
OldNewChangeContent
11
listen = ":8080"
2−
log_level = "debug"
2+
log_level = "info"
3+
timeout = "30s"
34
region = "eu-central"
Unified.svelte
<script lang="ts">
	import DiffViewer from '@tcpsystems/ui/foundation/DiffViewer';
	const lines = [
		{ kind: 'context', text: 'listen = ":8080"', oldLine: 1, newLine: 1 },
		{ kind: 'removed', text: 'log_level = "debug"', oldLine: 2 },
		{ kind: 'added', text: 'log_level = "info"', newLine: 2 },
		{ kind: 'added', text: 'timeout = "30s"', newLine: 3 },
		{ kind: 'context', text: 'region = "eu-central"', oldLine: 3, newLine: 4 }
	] as const;
</script>

<DiffViewer lines={[...lines]} label="studio.toml changes" />

Split

handler.go changes: 1–4 / 4

handler.go changes
OldNewChangeOldNew
1010
func Handle(w http.ResponseWriter, r *http.Request) {
func Handle(w http.ResponseWriter, r *http.Request) {
11−
	w.WriteHeader(200)
11+
	w.WriteHeader(http.StatusOK)
1212
}
}
Split.svelte
<script lang="ts">
	import DiffViewer from '@tcpsystems/ui/foundation/DiffViewer';
	const lines = [
		{ kind: 'context', text: 'func Handle(w http.ResponseWriter, r *http.Request) {', oldLine: 10, newLine: 10 },
		{ kind: 'removed', text: '\tw.WriteHeader(200)', oldLine: 11 },
		{ kind: 'added', text: '\tw.WriteHeader(http.StatusOK)', newLine: 11 },
		{ kind: 'context', text: '}', oldLine: 12, newLine: 12 }
	] as const;
</script>

<DiffViewer lines={[...lines]} layout="split" label="handler.go changes" />

Empty

Config changes: 0–0 / 0

No changes since the last deploy

Empty.svelte
<script lang="ts">
	import DiffViewer from '@tcpsystems/ui/foundation/DiffViewer';
</script>

<DiffViewer lines={[]} label="Config changes" emptyLabel="No changes since the last deploy" />

Layout toggle

Job spec changes: 1–3 / 3

Job spec changes
OldNewChangeContent
4−
replicas = 2
4+
replicas = 3
55
memory = "512MB"
Layout toggle.svelte
<script lang="ts">
	import DiffViewer from '@tcpsystems/ui/foundation/DiffViewer';
	import Button from '@tcpsystems/ui/foundation/Button';
	let layout = $state<'unified' | 'split'>('unified');
	const lines = [
		{ kind: 'removed', text: 'replicas = 2', oldLine: 4 },
		{ kind: 'added', text: 'replicas = 3', newLine: 4 },
		{ kind: 'context', text: 'memory = "512MB"', oldLine: 5, newLine: 5 }
	] as const;
</script>

<Button onclick={() => (layout = layout === 'unified' ? 'split' : 'unified')}>Show {layout === 'unified' ? 'split' : 'unified'}</Button>
<DiffViewer lines={[...lines]} {layout} label="Job spec changes" />

API

Import
import DiffViewer from '@tcpsystems/ui/foundation/DiffViewer';
PropTypeDefault
linesDiffLine[]none
layout?'unified' | 'split''unified'
start?number0
limit?number200
label?string'Changes'
emptyLabel?string'No changes'
previousHref?stringnone
nextHref?stringnone
previousLabel?string'Previous lines'
nextLabel?string'Next lines'
oldLabel?string'Old'
newLabel?string'New'
changeLabel?string'Change'
contentLabel?string'Content'
summary?stringnone
HookKind
.tcp-diffRoot class
data-kindData attribute
data-layoutData attribute