Look and controls
A cell's style, the grid's colours, and controls of your own around it.
A cell’s style
A cell’s record carries how it is shown. A key that is left out means the usual.
| Style | Values |
|---|---|
bold | true |
italic | true |
align | left, center, right; by content when not set (numbers right) |
format | number, percent, eur, usd; automatic when not set |
decimals | 0 to 10 decimal places |
editor.setStyle({ format: 'eur' }) sets it on the selected cells; null puts a key back to
the usual. editor.toggle('bold') and editor.changeDecimals(1) are what a toolbar’s buttons
call. Numbers are shown with the reader’s separators: 1,234.50 in English, 1.234,50 in
German. The reader’s language is the browser’s, or the locale the editor was made with.
The grid’s look
The styles are one file of plain CSS, @klementine/svelte-sheet/sheet.css. Every class in it
starts with ks-, and what the grid takes from the page around it is a handful of custom
properties on .ks-root. Set them there to fit your app: a rule of yours wins over the
defaults wherever it stands, before the import or after it. (A value set on something around
the grid does not reach it.) The typeface is the page’s.
.ks-root {
--ks-ground: #ffffff; /* the cells */
--ks-head: #f5f3ee; /* the column letters and row numbers */
--ks-head-on: #e2ddd0; /* the letters and numbers of the selection */
--ks-ink: #24231d; /* what is written in the cells */
--ks-ink-quiet: #66625a; /* the letters and numbers, a cell that shows an error */
--ks-line: rgb(36 35 29 / 0.1); /* the lines between cells */
--ks-line-strong: rgb(36 35 29 / 0.18); /* under the letters, beside the numbers */
--ks-select: #24231d; /* the selection, and the cell open for typing */
} By default the cells are paper on the ground, lighter than the letters and numbers, and the
selection is drawn in the ink. The grid is light. <Grid scheme="dark"> makes it dark, and scheme="auto" follows the system; the defaults have a value for each. An app that sets all of
the properties from its own colours follows its own light and dark, and scheme changes
nothing.
Controls around the grid
Controls are your app’s. A control reads the editor and calls it, and stays in step by itself, because the editor’s values are reactive in a template.
<script lang="ts">
import { Editor, Grid } from '@klementine/svelte-sheet';
const editor = new Editor();
let grid: { focus(): void };
const anchor = $derived(editor.anchor.get());
const bold = $derived(editor.styleOf(anchor.row, anchor.col)?.bold === true);
</script>
<button
aria-pressed={bold}
onmousedown={(event) => event.preventDefault()}
onclick={() => editor.toggle('bold')}
>
Bold
</button>
<Grid bind:this={grid} {editor} label="Budget" /> One rule keeps typing alive: the grid keeps the keys. A press on a button must not take the
focus from the cell, so prevent its mousedown. A control that does take the focus (a menu, a
field above the grid) calls grid.focus() when it is done.
A formula bar is an input that types into the selected cell:
<input
value={editor.editing.get()?.text ??
toEditText(editor.input(anchor.row, anchor.col), editor.locale)}
onfocus={() => editor.startEditing('bar')}
oninput={(event) => editor.type(event.currentTarget.value, 'bar')}
onblur={() => editor.commit()}
/> toEditText shows what is typed the reader’s way (a decimal comma where that is usual), and
Enter, Tab and Escape end the entry as they do in the cell: hand the key to editor.key.
The spreadsheet example does all of this in full: a toolbar, a formula bar and a File menu, on bits-ui and one
plain stylesheet whose colours are properties on .sp.
Words
The grid says little itself: four labels, English by default. Pass your own as labels, all
of them or a few; what is left out stays English.
| Label | Where it is said |
|---|---|
grid | the grid’s name, when the sheet has no label of its own |
cell(cell, value) | the selected cell and what it shows: “B3: 1,200” |
emptyCell(cell) | the selected cell when it shows nothing |
resizeColumn(column) | the edge of a column’s letter, which is dragged |
Everything else is said by your controls, in your app’s language. The example’s controls take
one labels object with all their words.