Data display
JsonViewer
Shows JSON data as a tree that opens and closes. Deep levels start closed and show their item count.
import { JsonViewer } from "@percentsa/ui";Examples
- number: "INV-2026-0142"
- … } 3 items
- total: 1150
- paid: true
- refund: null
- … ] 2 items
}
Code
export function JsonViewerExample() {
const t = useT();
const invoice = {
number: "INV-2026-0142",
customer: { name: t("Sara Al-Qahtani", "سارة القحطاني"), city: t("Riyadh", "الرياض"), vatNumber: "300000000000003" },
total: 1150,
paid: true,
refund: null,
lines: [
{ description: t("Website design", "تصميم موقع"), quantity: 1, unitPrice: 800 },
{ description: t("Hosting, one year", "استضافة لمدة سنة"), quantity: 1, unitPrice: 200 },
],
};
return <JsonViewer value={invoice} className="w-full max-w-xl rounded-card border border-line bg-surface p-4" />;
}
const CONFIG = `services:
web:
image: example/web:1.4
ports:
- "8080:80"
depends_on:
- db
db:
image: example/db:16
volumes:
- data:/var/lib/db
`;
// A sample the app checks itself: the editor only marks the lines it is given.
const checkConfig = (text: string, message: string): CodeDiagnostic[] =>
text.split("\n").flatMap((line, i) => (/:latest\s*$/.test(line) ? [{ line: i + 1, message }] : []));