Skip to content

Commit 208b88d

Browse files
committed
chore: add docs on new tables features
1 parent 743e8aa commit 208b88d

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

docs/pages/docs/advanced/tables.mdx

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Advanced Tables
3+
description: This section explains how to use more advanced features of tables.
4+
imageTitle: Advanced Tables
5+
---
6+
7+
import { Example } from "@/components/example";
8+
9+
# Advanced Tables
10+
11+
Tables by default are a simple way to display data in a grid. But, BlockNote also supports more advanced features like:
12+
13+
- Split cells
14+
- Cell background color
15+
- Cell text color
16+
- Header rows & columns
17+
18+
To keep the default table experience easy to use, these features are disabled by default.
19+
20+
You can enable them by passing the `tables` option when creating the editor.
21+
22+
```ts
23+
const editor = new BlockNoteEditor({
24+
tables: {
25+
splitCells: true,
26+
cellBackgroundColor: true,
27+
cellTextColor: true,
28+
headers: true,
29+
},
30+
});
31+
```
32+
33+
You can choose to enable only certain features, or none at all. Giving you the flexibility to use tables how you need in your app.
34+
35+
Here's an example of the editor with all features enabled:
36+
37+
<Example name="ui-components/advanced-tables" />
38+
39+
## Cell background color
40+
41+
To enable cell background color, you need to pass `cellBackgroundColor: true` to the `tables` option.
42+
43+
```ts
44+
const editor = new BlockNoteEditor({
45+
tables: {
46+
cellBackgroundColor: true,
47+
},
48+
});
49+
```
50+
51+
## Cell text color
52+
53+
To enable cell text color, you need to pass `cellTextColor: true` to the `tables` option.
54+
55+
```ts
56+
const editor = new BlockNoteEditor({
57+
tables: {
58+
cellTextColor: true,
59+
},
60+
});
61+
```
62+
63+
64+
## Header rows & columns
65+
66+
BlockNote supports headers in tables, which are the first row and/or first column of a table.
67+
68+
To enable it, you need to pass `headers: true` to the `tables` option.
69+
70+
```ts
71+
const editor = new BlockNoteEditor({
72+
tables: {
73+
headers: true,
74+
},
75+
});
76+
```
77+
78+
## Split cells
79+
80+
Splitting and merging cells is a common feature of more advanced table editors.
81+
82+
To enable it, you need to pass `splitCells: true` to the `tables` option.
83+
84+
```ts
85+
const editor = new BlockNoteEditor({
86+
tables: {
87+
splitCells: true,
88+
},
89+
});
90+
```
91+
92+

docs/pages/docs/editor-basics/setup.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ type BlockNoteEditorOptions = {
3737
schema?: BlockNoteSchema;
3838
setIdAttribute?: boolean;
3939
sideMenuDetection?: "viewport" | "editor";
40-
tabBehavior?: "prefer-navigate-ui" | "prefer-indent"
40+
tabBehavior?: "prefer-navigate-ui" | "prefer-indent";
41+
tables?: TableFeatures;
4142
trailingBlock?: boolean;
4243
uploadFile?: (file: File) => Promise<string>;
4344
};
@@ -77,6 +78,8 @@ The hook takes two optional parameters:
7778

7879
`tabBehavior`: Determines whether pressing the tab key should navigate toolbars for keyboard accessibility. When set to `"prefer-navigate-ui`, the user can navigate toolbars using Tab. Pressing Escape re-focuses the editor, and Tab now indents blocks. `"prefer-indent"` causes Tab to always indent blocks. Defaults to `prefer-navigate-ui`.
7980

81+
`tables`: Configuration for table features. Allowing you to enable more advanced table features like `splitCells`, `cellBackgroundColor`, `cellTextColor`, and `headers`.
82+
8083
`trailingBlock`: An option which user can pass with `false` value to disable the automatic creation of a trailing new block on the next line when the user types or edits any block. Defaults to `true` if undefined.
8184

8285
`uploadFile`: A function which handles file uploads and eventually returns the URL to the uploaded file. Used for [Image blocks](/docs/editor-basics/default-schema#image).

examples/03-ui-components/15-advanced-tables/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ This example enables the following features in tables:
99

1010
**Relevant Docs:**
1111

12+
- [Tables](/docs/advanced/tables)
1213
- [Editor Setup](/docs/editor-basics/setup)

0 commit comments

Comments
 (0)