DiffViewer
Bounded controlled unified or split diff rows.
beta
Examples
Unified
studio.toml changes: 1–5 / 5
| Old | New | Change | Content |
|---|---|---|---|
| 1 | 1 | listen = ":8080" | |
| 2 | − | log_level = "debug" | |
| 2 | + | log_level = "info" | |
| 3 | + | timeout = "30s" | |
| 3 | 4 | region = "eu-central" |
<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
| Old | New | Change | Old | New |
|---|---|---|---|---|
| 10 | 10 | 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) | ||
| 12 | 12 | } | } |
<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
<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
| Old | New | Change | Content |
|---|---|---|---|
| 4 | − | replicas = 2 | |
| 4 | + | replicas = 3 | |
| 5 | 5 | memory = "512MB" |
<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 DiffViewer from '@tcpsystems/ui/foundation/DiffViewer';| Prop | Type | Default |
|---|---|---|
lines | DiffLine[] | none |
layout? | 'unified' | 'split' | 'unified' |
start? | number | 0 |
limit? | number | 200 |
label? | string | 'Changes' |
emptyLabel? | string | 'No changes' |
previousHref? | string | none |
nextHref? | string | none |
previousLabel? | string | 'Previous lines' |
nextLabel? | string | 'Next lines' |
oldLabel? | string | 'Old' |
newLabel? | string | 'New' |
changeLabel? | string | 'Change' |
contentLabel? | string | 'Content' |
summary? | string | none |
| Hook | Kind |
|---|---|
.tcp-diff | Root class |
data-kind | Data attribute |
data-layout | Data attribute |