Data Spreadsheet
An Excel-like cell grid with lettered columns, numbered rows and cell-level selection — not a table, Carbon’s computational canvas.
Real scenarios
The component as it is used in a product — not a specimen grid.
Not a table — a canvas
Lettered columns, numbered rows, and cell-level selection: click any cell or walk with the arrow keys — the 2px blue ring, the coordinate box and the formula bar all follow you. Empty cells keep their slot so the grid never shifts.
Row 5 is the margin line — the data-total cells stay bold at every zoom, and the ruler column headers highlight with the active cell.
The whole family
Sparse data, header-less ruler and the compact ruler — the canvas shape never shifts under the data.
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| columns | letters | 'A – H' | Column headers are letters, not labels; A to H by default, growing with the input data. |
| activeCell | coordinates | 'A1' | The active cell reads through a 2px blue ring and its coordinates in the top-start corner box. |
| spreadsheetData | sparse 2D | null | A sparse 2D array; empty cells still hold their grid slot so the canvas never shifts. |
Snippet
<div class="cbsp" x-data="{ active: 'A1' }">
<header class="cbsp-ruler">
<span class="cbsp-ref" x-text="active">A1</span>
<span class="cbsp-formula" x-text="cell(active)">12,500</span>
</header>
<div class="cbsp-grid" role="grid">
<button role="gridcell" class="cbsp-cell" data-ref="A1">12,500</button>
</div>
</div>
<style>
.cbsp { border: 1px solid #8d8d8d; font: 400 .75rem/1 'IBM Plex Mono', monospace; }
.cbsp-ruler { display: flex; border-block-end: 1px solid #8d8d8d; }
.cbsp-ref { min-inline-size: 4rem; padding: .5rem; border-inline-end: 1px solid #8d8d8d; }
.cbsp-cell { inline-size: 6rem; block-size: 2rem; border: 1px solid #e0e0e0;
background: #fff; cursor: cell; text-align: start; }
.cbsp-cell[data-active] { outline: 2px solid #0f62fe; outline-offset: -2px; }
</style>
// app/Pages/Budget.jsx — Inertia page; renders the React snippet
// below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import BudgetSheet from '@/components/BudgetSheet';
export default function Budget() {
return (
<NabuXUIProvider locale="en" linkComponent={Link}>
<main className="nx-page">
<BudgetSheet />
</main>
</NabuXUIProvider>
);
}
// BudgetSheet.jsx — Carbon data spreadsheet: lettered columns, arrow-key selection
import { Fragment, useState } from 'react';
import '@nabuxai/ui-core/css';
const COLS = ['A', 'B', 'C', 'D'];
const ROWS = [1, 2, 3, 4];
// Sparse on purpose: empty cells keep their grid slot.
const DATA = {
A1: 'Berlin office', B1: 'January', C1: 'February', D1: 'March',
A2: 'Revenue', B2: '84,000', C2: '91,500', D2: '88,200',
A3: 'Infrastructure', B3: '22,400', C3: '22,400', D3: '23,900',
A4: 'Margin', B4: '61,600', C4: '69,100', D4: '64,300',
};
export default function BudgetSheet() {
const [active, setActive] = useState('B2');
// Arrow keys walk the grid; the ring, ref box and formula bar follow.
const move = (event) => {
const delta = { ArrowUp: [0, -1], ArrowDown: [0, 1], ArrowLeft: [-1, 0], ArrowRight: [1, 0] }[event.key];
if (!delta) return;
event.preventDefault();
const c = COLS.indexOf(active[0]);
const r = Number(active.slice(1));
const col = COLS[Math.min(COLS.length - 1, Math.max(0, c + delta[0]))];
const row = Math.min(ROWS.length, Math.max(1, r + delta[1]));
setActive(col + row);
};
return (
<>
<style>{`
.cbsp { max-inline-size: 32rem; border: 1px solid #8d8d8d; background: #f4f4f4;
font: 400 .75rem/1 'IBM Plex Mono', Menlo, monospace; }
.cbsp-ruler { display: flex; border-block-end: 1px solid #8d8d8d; }
.cbsp-ref { display: grid; place-items: center; min-inline-size: 3.5rem; padding: .5rem;
border-inline-end: 1px solid #8d8d8d; font-weight: 600; background: #e0e0e0; }
.cbsp-formula { flex: 1; display: flex; align-items: center; gap: .5rem; padding: .5rem .625rem; }
.cbsp-formula b { font-weight: 400; color: #525252; }
.cbsp-grid { display: grid; grid-template-columns: 3rem repeat(4, minmax(5rem, 1fr)); }
.cbsp-colhead, .cbsp-rowhead { display: grid; place-items: center; block-size: 2rem; color: #525252;
background: #e0e0e0; border-inline-end: 1px solid #e0e0e0;
border-block-end: 1px solid #e0e0e0; }
.cbsp-colhead[data-hi], .cbsp-rowhead[data-hi] { background: #bdd3f5; color: #161616; }
.cbsp-cell { display: flex; align-items: center; min-block-size: 2rem; padding-inline: .625rem;
border-inline-end: 1px solid #e0e0e0; border-block-end: 1px solid #e0e0e0;
background: #f4f4f4; color: #161616; text-align: start; cursor: cell; font: inherit; }
.cbsp-cell[data-num] { justify-content: flex-end; }
.cbsp-cell[data-active='true'] { outline: 2px solid #0f62fe; outline-offset: -2px; background: #e8e8e8; }
`}</style>
<div className="cbsp" role="grid" aria-label="Quarterly budget" onKeyDown={move}>
<div className="cbsp-ruler">
<span className="cbsp-ref">{active}</span>
<span className="cbsp-formula"><b>ƒx</b><span>{DATA[active] ?? '—'}</span></span>
</div>
<div className="cbsp-grid">
<span className="cbsp-colhead" aria-hidden="true" />
{COLS.map((c) => (
<span key={c} className="cbsp-colhead" data-hi={c === active[0]}>{c}</span>
))}
{ROWS.map((r) => (
<Fragment key={r}>
<span className="cbsp-rowhead" data-hi={r === Number(active.slice(1))}>{r}</span>
{COLS.map((c) => (
<button type="button" role="gridcell" key={c} className="cbsp-cell"
data-ref={c + r} data-active={active === c + r}
data-num={c !== 'A'} onClick={() => setActive(c + r)}>
{DATA[c + r] ?? ''}
</button>
))}
</Fragment>
))}
</div>
</div>
</>
);
}
<!-- BudgetSheet.vue — Carbon data spreadsheet: lettered columns, arrow-key selection -->
<script setup lang="ts">
import { ref } from 'vue';
import '@nabuxai/ui-core/css';
const cols = ['A', 'B', 'C', 'D'];
const rows = [1, 2, 3, 4];
// Sparse on purpose: empty cells keep their grid slot.
const data: Record<string, string> = {
A1: 'Berlin office', B1: 'January', C1: 'February', D1: 'March',
A2: 'Revenue', B2: '84,000', C2: '91,500', D2: '88,200',
A3: 'Infrastructure', B3: '22,400', C3: '22,400', D3: '23,900',
A4: 'Margin', B4: '61,600', C4: '69,100', D4: '64,300',
};
const active = ref('B2');
// Arrow keys walk the grid; the ring, ref box and formula bar follow.
function move(e: KeyboardEvent) {
const deltas: Record<string, [number, number]> = {
ArrowUp: [0, -1], ArrowDown: [0, 1], ArrowLeft: [-1, 0], ArrowRight: [1, 0],
};
const delta = deltas[e.key];
if (!delta) return;
e.preventDefault();
const c = cols.indexOf(active.value[0]);
const r = Number(active.value.slice(1));
const col = cols[Math.min(cols.length - 1, Math.max(0, c + delta[0]))];
const row = Math.min(rows.length, Math.max(1, r + delta[1]));
active.value = col + row;
}
</script>
<template>
<div class="cbsp" role="grid" aria-label="Quarterly budget" @keydown="move">
<div class="cbsp-ruler">
<span class="cbsp-ref">{{ active }}</span>
<span class="cbsp-formula"><b>ƒx</b><span>{{ data[active] ?? '—' }}</span></span>
</div>
<div class="cbsp-grid">
<span class="cbsp-colhead" aria-hidden="true"></span>
<span v-for="c in cols" :key="c" class="cbsp-colhead" :data-hi="c === active[0]">{{ c }}</span>
<template v-for="r in rows" :key="r">
<span class="cbsp-rowhead" :data-hi="r === Number(active.slice(1))">{{ r }}</span>
<button v-for="c in cols" :key="c" type="button" role="gridcell" class="cbsp-cell"
:data-ref="c + r" :data-active="active === c + r" :data-num="c !== 'A'"
@click="active = c + r">
{{ data[c + r] ?? '' }}
</button>
</template>
</div>
</div>
</template>
<style scoped>
.cbsp { max-inline-size: 32rem; border: 1px solid #8d8d8d; background: #f4f4f4;
font: 400 .75rem/1 'IBM Plex Mono', Menlo, monospace; }
.cbsp-ruler { display: flex; border-block-end: 1px solid #8d8d8d; }
.cbsp-ref { display: grid; place-items: center; min-inline-size: 3.5rem; padding: .5rem;
border-inline-end: 1px solid #8d8d8d; font-weight: 600; background: #e0e0e0; }
.cbsp-formula { flex: 1; display: flex; align-items: center; gap: .5rem; padding: .5rem .625rem; }
.cbsp-formula b { font-weight: 400; color: #525252; }
.cbsp-grid { display: grid; grid-template-columns: 3rem repeat(4, minmax(5rem, 1fr)); }
.cbsp-colhead, .cbsp-rowhead { display: grid; place-items: center; block-size: 2rem; color: #525252;
background: #e0e0e0; border-inline-end: 1px solid #e0e0e0;
border-block-end: 1px solid #e0e0e0; }
.cbsp-colhead[data-hi], .cbsp-rowhead[data-hi] { background: #bdd3f5; color: #161616; }
.cbsp-cell { display: flex; align-items: center; min-block-size: 2rem; padding-inline: .625rem;
border-inline-end: 1px solid #e0e0e0; border-block-end: 1px solid #e0e0e0;
background: #f4f4f4; color: #161616; text-align: start; cursor: cell; font: inherit; }
.cbsp-cell[data-num] { justify-content: flex-end; }
.cbsp-cell[data-active='true'] { outline: 2px solid #0f62fe; outline-offset: -2px; background: #e8e8e8; }
</style>
<!-- BudgetSheet.svelte — Carbon data spreadsheet: lettered columns, arrow-key selection -->
<script lang="ts">
import '@nabuxai/ui-core/css';
const cols = ['A', 'B', 'C', 'D'];
const rows = [1, 2, 3, 4];
// Sparse on purpose: empty cells keep their grid slot.
const data: Record<string, string> = {
A1: 'Berlin office', B1: 'January', C1: 'February', D1: 'March',
A2: 'Revenue', B2: '84,000', C2: '91,500', D2: '88,200',
A3: 'Infrastructure', B3: '22,400', C3: '22,400', D3: '23,900',
A4: 'Margin', B4: '61,600', C4: '69,100', D4: '64,300',
};
let active = $state('B2');
// Arrow keys walk the grid; the ring, ref box and formula bar follow.
function move(e: KeyboardEvent) {
const deltas: Record<string, [number, number]> = {
ArrowUp: [0, -1], ArrowDown: [0, 1], ArrowLeft: [-1, 0], ArrowRight: [1, 0],
};
const delta = deltas[e.key];
if (!delta) return;
e.preventDefault();
const c = cols.indexOf(active[0]);
const r = Number(active.slice(1));
const col = cols[Math.min(cols.length - 1, Math.max(0, c + delta[0]))];
const row = Math.min(rows.length, Math.max(1, r + delta[1]));
active = col + row;
}
</script>
<div class="cbsp" role="grid" aria-label="Quarterly budget" onkeydown={move}>
<div class="cbsp-ruler">
<span class="cbsp-ref">{active}</span>
<span class="cbsp-formula"><b>ƒx</b><span>{data[active] ?? '—'}</span></span>
</div>
<div class="cbsp-grid">
<span class="cbsp-colhead" aria-hidden="true"></span>
{#each cols as c (c)}
<span class="cbsp-colhead" data-hi={c === active[0]}>{c}</span>
{/each}
{#each rows as r (r)}
<span class="cbsp-rowhead" data-hi={r === Number(active.slice(1))}>{r}</span>
{#each cols as c (c)}
<button type="button" role="gridcell" class="cbsp-cell" data-ref={c + r}
data-active={active === c + r} data-num={c !== 'A'} onclick={() => (active = c + r)}>
{data[c + r] ?? ''}
</button>
{/each}
{/each}
</div>
</div>
<style>
.cbsp { max-inline-size: 32rem; border: 1px solid #8d8d8d; background: #f4f4f4;
font: 400 .75rem/1 'IBM Plex Mono', Menlo, monospace; }
.cbsp-ruler { display: flex; border-block-end: 1px solid #8d8d8d; }
.cbsp-ref { display: grid; place-items: center; min-inline-size: 3.5rem; padding: .5rem;
border-inline-end: 1px solid #8d8d8d; font-weight: 600; background: #e0e0e0; }
.cbsp-formula { flex: 1; display: flex; align-items: center; gap: .5rem; padding: .5rem .625rem; }
.cbsp-formula b { font-weight: 400; color: #525252; }
.cbsp-grid { display: grid; grid-template-columns: 3rem repeat(4, minmax(5rem, 1fr)); }
.cbsp-colhead, .cbsp-rowhead { display: grid; place-items: center; block-size: 2rem; color: #525252;
background: #e0e0e0; border-inline-end: 1px solid #e0e0e0;
border-block-end: 1px solid #e0e0e0; }
.cbsp-colhead[data-hi], .cbsp-rowhead[data-hi] { background: #bdd3f5; color: #161616; }
.cbsp-cell { display: flex; align-items: center; min-block-size: 2rem; padding-inline: .625rem;
border-inline-end: 1px solid #e0e0e0; border-block-end: 1px solid #e0e0e0;
background: #f4f4f4; color: #161616; text-align: start; cursor: cell; font: inherit; }
.cbsp-cell[data-num] { justify-content: flex-end; }
.cbsp-cell[data-active='true'] { outline: 2px solid #0f62fe; outline-offset: -2px; background: #e8e8e8; }
</style>