Skip to content

Commit 9b622be

Browse files
committed
feat(block-kit): add table block
1 parent 6802856 commit 9b622be

3 files changed

Lines changed: 158 additions & 0 deletions

File tree

block-kit/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
1919
- **[Markdown](https://docs.slack.dev/reference/block-kit/blocks/markdown-block)**: Displays formatted markdown. [Implementation](./src/blocks/markdown.js).
2020
- **[Rich text](https://docs.slack.dev/reference/block-kit/blocks/rich-text-block)**: Displays formatted, structured representation of text. [Implementation](./src/blocks/rich_text.js).
2121
- **[Section](https://docs.slack.dev/reference/block-kit/blocks/section-block)**: Displays text, possibly alongside elements. [Implementation](./src/blocks/section.js).
22+
- **[Table](https://docs.slack.dev/reference/block-kit/blocks/table-block)**: Displays structured information in a table. [Implementation](./src/blocks/table.js).
2223
- **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/blocks/video.js).

block-kit/src/blocks/table.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Displays structured information in a table.
3+
*
4+
* @see {@link https://docs.slack.dev/reference/block-kit/blocks/table-block/}
5+
*/
6+
7+
/**
8+
* A table block.
9+
*
10+
* @returns {import('@slack/types').TableBlock}
11+
*/
12+
export function example01() {
13+
/**
14+
* @type {import('@slack/types').TableBlock}
15+
*/
16+
const block = {
17+
type: "table",
18+
column_settings: [
19+
{
20+
is_wrapped: true,
21+
},
22+
{
23+
align: "right",
24+
},
25+
],
26+
rows: [
27+
[
28+
{
29+
type: "raw_text",
30+
text: "Header A",
31+
},
32+
{
33+
type: "raw_text",
34+
text: "Header B",
35+
},
36+
],
37+
[
38+
{
39+
type: "raw_text",
40+
text: "Data 1A",
41+
},
42+
{
43+
type: "rich_text",
44+
elements: [
45+
{
46+
type: "rich_text_section",
47+
elements: [
48+
{
49+
text: "Data 1B",
50+
type: "link",
51+
url: "https://slack.com",
52+
},
53+
],
54+
},
55+
],
56+
},
57+
],
58+
[
59+
{
60+
type: "raw_text",
61+
text: "Data 2A",
62+
},
63+
{
64+
type: "rich_text",
65+
elements: [
66+
{
67+
type: "rich_text_section",
68+
elements: [
69+
{
70+
text: "Data 2B",
71+
type: "link",
72+
url: "https://slack.com",
73+
},
74+
],
75+
},
76+
],
77+
},
78+
],
79+
],
80+
};
81+
return block;
82+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import * as assert from "node:assert";
2+
import { describe, it } from "node:test";
3+
import { example01 } from "../../src/blocks/table.js";
4+
5+
describe("table", () => {
6+
it("example01", () => {
7+
const block = example01();
8+
const expected = {
9+
type: "table",
10+
column_settings: [
11+
{
12+
is_wrapped: true,
13+
},
14+
{
15+
align: "right",
16+
},
17+
],
18+
rows: [
19+
[
20+
{
21+
type: "raw_text",
22+
text: "Header A",
23+
},
24+
{
25+
type: "raw_text",
26+
text: "Header B",
27+
},
28+
],
29+
[
30+
{
31+
type: "raw_text",
32+
text: "Data 1A",
33+
},
34+
{
35+
type: "rich_text",
36+
elements: [
37+
{
38+
type: "rich_text_section",
39+
elements: [
40+
{
41+
text: "Data 1B",
42+
type: "link",
43+
url: "https://slack.com",
44+
},
45+
],
46+
},
47+
],
48+
},
49+
],
50+
[
51+
{
52+
type: "raw_text",
53+
text: "Data 2A",
54+
},
55+
{
56+
type: "rich_text",
57+
elements: [
58+
{
59+
type: "rich_text_section",
60+
elements: [
61+
{
62+
text: "Data 2B",
63+
type: "link",
64+
url: "https://slack.com",
65+
},
66+
],
67+
},
68+
],
69+
},
70+
],
71+
],
72+
};
73+
assert.deepStrictEqual(block, expected);
74+
});
75+
});

0 commit comments

Comments
 (0)