|
9 | 9 | [](https://github.com/Rafferty97/solid-tabular/blob/main/LICENSE) |
10 | 10 | [](https://pnpm.io/) |
11 | 11 |
|
12 | | -Spreadsheet-like table UI |
13 | 12 |
|
14 | | -## Quick start |
| 13 | +Spreadsheet-like table UI for SolidJS. |
15 | 14 |
|
16 | | -Install it: |
| 15 | +⚠️ This library is currently in early development, and breaking changes will definitely occur. |
| 16 | + |
| 17 | +## Features |
| 18 | + |
| 19 | +- 🚀 **Virtualization**: Efficiently renders large datasets using `@tanstack/solid-virtual`. |
| 20 | +- 🖱️ **Selection**: Excel-like cell and range selection. |
| 21 | +- ✏️ **Editing**: In-place cell editing. |
| 22 | +- 📏 **Resizing**: Draggable column resizing. |
| 23 | +- 📋 **Clipboard**: Copy and paste support. |
| 24 | +- ⌨️ **Keyboard Navigation**: Arrow keys, Tab, Enter, etc. |
| 25 | +- 🎨 **Customizable**: CSS variables for theming. |
| 26 | + |
| 27 | +## Installation |
17 | 28 |
|
18 | 29 | ```bash |
19 | | -npm i solid-tabular |
20 | | -# or |
21 | | -yarn add solid-tabular |
| 30 | +npm install solid-tabular |
22 | 31 | # or |
23 | 32 | pnpm add solid-tabular |
| 33 | +# or |
| 34 | +yarn add solid-tabular |
24 | 35 | ``` |
25 | 36 |
|
26 | | -Use it: |
| 37 | +## Basic Usage |
| 38 | + |
| 39 | +The example below shows how to display a static data table with default column widths. |
27 | 40 |
|
28 | 41 | ```tsx |
29 | | -import solid-tabular from 'solid-tabular' |
| 42 | +import { createSignal } from 'solid-js' |
| 43 | +import { Table, ActiveRange } from 'solid-tabular' |
| 44 | +import 'solid-tabular/dist/index.css' |
| 45 | + |
| 46 | +function App() { |
| 47 | + const [activeRange, setActiveRange] = createSignal<ActiveRange>() |
| 48 | + |
| 49 | + const columns = ['A', 'B', 'C'] |
| 50 | + |
| 51 | + const [data, setData] = createSignal([ |
| 52 | + ['A1', 'B1', 'C1'], |
| 53 | + ['A2', 'B2', 'C2'], |
| 54 | + ['A3', 'B3', 'C3'], |
| 55 | + ]) |
| 56 | + |
| 57 | + return ( |
| 58 | + <div style={{ height: '500px' }}> |
| 59 | + <Table |
| 60 | + columns={columns} |
| 61 | + numRows={data().length} |
| 62 | + getCellValue={(row, col) => data()[row][columns.indexOf(col)]} |
| 63 | + activeRange={activeRange()} |
| 64 | + setActiveRange={setActiveRange} |
| 65 | + /> |
| 66 | + </div> |
| 67 | + ) |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +## API |
| 72 | + |
| 73 | +### `Table` Component |
| 74 | + |
| 75 | +The `Table` component is the main entry point, and has two generic type parameters `Column` and `Value`. |
| 76 | + |
| 77 | +| Prop | Type | Description | |
| 78 | +|------|------|-------------| |
| 79 | +| `columns` | `Column[]` | Array of column objects. | |
| 80 | +| `numRows` | `number` | Total number of rows. | |
| 81 | +| `getCellValue` | `(row: number, column: Column) => Value` | Function to get the value for a cell. | |
| 82 | +| `setCellValue` | `(row: number, column: Column, value: Value) => void` | Function to update the value of a cell. | |
| 83 | +| `activeRange` | `ActiveRange` | The current selection state. | |
| 84 | +| `setActiveRange` | `(range: ActiveRange) => void` | Callback to update the selection state. | |
| 85 | +| `columnsResizeable` | `boolean` | Enables column resizing. | |
| 86 | +| `columnsEditable` | `boolean` | Enables column operations (insert/delete/rename). | |
| 87 | +| `rowsEditable` | `boolean` | Enables row operations (insert/delete). | |
| 88 | +| `cellHeight` | `number` | Height of cells in pixels (default: 29). | |
| 89 | +| `getColumnSize` | `(column: Column) => number` | Get column width. | |
| 90 | +| `setColumnSize` | `(column: Column, width: number) => void` | Set column width. | |
| 91 | +| `resetColumnSize` | `(column: Column) => void` | Reset column width. | |
| 92 | +| `getColumnName` | `(column: Column) => string` | Get column name. | |
| 93 | +| `setColumnName` | `(column: Column, name: string) => void` | Set column name. | |
| 94 | +| `insertColumns` | `(index: number, count: number) => void` | Insert columns. | |
| 95 | +| `insertRows` | `(index: number, count: number) => void` | Insert rows. | |
| 96 | +| `removeColumns` | `(index: number, count: number) => void` | Remove columns. | |
| 97 | +| `removeRows` | `(index: number, count: number) => void` | Remove rows. | |
| 98 | +| `onCopy` | `(min: CellIndex, max: CellIndex) => void` | Called when cells are copied. | |
| 99 | +| `onPaste` | `(min: CellIndex, max: CellIndex) => void` | Called when cells are pasted. | |
| 100 | +| `onClear` | `(min: CellIndex, max: CellIndex) => void` | Called when cells are cleared (delete key). | |
| 101 | + |
| 102 | +### Theming |
| 103 | + |
| 104 | +You can customize the appearance using CSS variables: |
| 105 | + |
| 106 | +```css |
| 107 | +.my-table { |
| 108 | + /* General */ |
| 109 | + --solid-tabular-font: 0.875rem 'Segoe UI', 'Helvetica Neue', Arial, sans-serif; |
| 110 | + --solid-tabular-bg-color: oklch(92.8% 0.006 264.531); |
| 111 | + --solid-tabular-text-color: black; |
| 112 | + |
| 113 | + /* Cells */ |
| 114 | + --solid-tabular-cell-color: white; |
| 115 | + --solid-tabular-cell-hover-color: oklch(96.7% 0.003 264.542); |
| 116 | + --solid-tabular-border-color: oklch(87.2% 0.01 258.338); |
| 117 | + --solid-tabular-placeholder-color: oklch(70.7% 0.022 261.325); |
| 118 | + |
| 119 | + /* Headers */ |
| 120 | + --solid-tabular-header-color: var(--solid-tabular-cell-color); |
| 121 | + --solid-tabular-rownum-color: inherit; |
| 122 | + --solid-tabular-font-size-row-num: 1em; |
| 123 | + |
| 124 | + /* Selection & Accents */ |
| 125 | + --solid-tabular-accent-color: oklch(45.7% 0.24 277.023); |
| 126 | + --solid-tabular-shade-color: rgba(0, 0, 0, 0.12); |
| 127 | +} |
30 | 128 | ``` |
| 129 | + |
0 commit comments