Skip to content

CodeCompare

The same data in two encodings, side by side from 900px, top aligned so the shorter one visibly ends sooner.

DataServer-rendered

Examples

Pretty JSON and TOON

Light

What the server sends6 lines

Pretty JSONjson
{
  "issues": [
    { "id": "ISS-142", "state": "open", "estimate": null },
    { "id": "ISS-143", "state": "closed", "estimate": null }
  ]
}

What your agent reads3 lines

TOON
issues[2]{id,state}:
  ISS-142,open
  ISS-143,closed
Same fields, same values. Empty columns are dropped and the rows become a table.
Dark

What the server sends6 lines

Pretty JSONjson
{
  "issues": [
    { "id": "ISS-142", "state": "open", "estimate": null },
    { "id": "ISS-143", "state": "closed", "estimate": null }
  ]
}

What your agent reads3 lines

TOON
issues[2]{id,state}:
  ISS-142,open
  ISS-143,closed
Same fields, same values. Empty columns are dropped and the rows become a table.
Example
<CodeCompare
  before={{ title: 'What the server sends', code: json, language: 'json', filename: 'Pretty JSON' }}
  after={{ title: 'What your agent reads', code: toon, filename: 'TOON' }}
  caption="Same fields, same values."
/>

Usage

Usage
import { CodeCompare } from '@switchboard/ui'

<CodeCompare before={{ title, code, language?, filename?, wrap? }} after={{ … }} caption?="…" />

Props

Every component also takes mix, for css() and mixins applied after its own style.

CodeCompare

CodeCompare props
PropTypeDefaultDescription
before*{ title; code; language?; filename?; wrap? }–Left (top on phones) pane.
after*{ title; code; language?; filename?; wrap? }–Right pane; its title is in accent ink.
captionRemixNode–What the panes show and where any numbers come from.

Also accepts every <figure> attribute. Each pane is a CodeBlock (copy, wrap toggle).

Accessibility

  • A <figure> with a <figcaption>; each pane states its title and line count in text.
  • Each <pre> is keyboard reachable and named by its CodeBlock label.

Guidance

Do

  • Show real output of the thing being compared, not a hand-tuned mock.

Don’t

  • Wrap tabular output: it hides the table shape the comparison is about.