diff --git a/block-kit/README.md b/block-kit/README.md index 473ec44..7f6c143 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -19,4 +19,5 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes - **[Markdown](https://docs.slack.dev/reference/block-kit/blocks/markdown-block)**: Displays formatted markdown. [Implementation](./src/blocks/markdown.js). - **[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). - **[Section](https://docs.slack.dev/reference/block-kit/blocks/section-block)**: Displays text, possibly alongside elements. [Implementation](./src/blocks/section.js). +- **[Table](https://docs.slack.dev/reference/block-kit/blocks/table-block)**: Displays structured information in a table. [Implementation](./src/blocks/table.js). - **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/blocks/video.js). diff --git a/block-kit/src/blocks/table.js b/block-kit/src/blocks/table.js new file mode 100644 index 0000000..cf0a6a7 --- /dev/null +++ b/block-kit/src/blocks/table.js @@ -0,0 +1,82 @@ +/** + * Displays structured information in a table. + * + * @see {@link https://docs.slack.dev/reference/block-kit/blocks/table-block/} + */ + +/** + * A table block. + * + * @returns {import('@slack/types').TableBlock} + */ +export function example01() { + /** + * @type {import('@slack/types').TableBlock} + */ + const block = { + type: "table", + column_settings: [ + { + is_wrapped: true, + }, + { + align: "right", + }, + ], + rows: [ + [ + { + type: "raw_text", + text: "Header A", + }, + { + type: "raw_text", + text: "Header B", + }, + ], + [ + { + type: "raw_text", + text: "Data 1A", + }, + { + type: "rich_text", + elements: [ + { + type: "rich_text_section", + elements: [ + { + text: "Data 1B", + type: "link", + url: "https://slack.com", + }, + ], + }, + ], + }, + ], + [ + { + type: "raw_text", + text: "Data 2A", + }, + { + type: "rich_text", + elements: [ + { + type: "rich_text_section", + elements: [ + { + text: "Data 2B", + type: "link", + url: "https://slack.com", + }, + ], + }, + ], + }, + ], + ], + }; + return block; +} diff --git a/block-kit/tests/blocks/table.test.js b/block-kit/tests/blocks/table.test.js new file mode 100644 index 0000000..9ef73b3 --- /dev/null +++ b/block-kit/tests/blocks/table.test.js @@ -0,0 +1,75 @@ +import * as assert from "node:assert"; +import { describe, it } from "node:test"; +import { example01 } from "../../src/blocks/table.js"; + +describe("table", () => { + it("example01", () => { + const block = example01(); + const expected = { + type: "table", + column_settings: [ + { + is_wrapped: true, + }, + { + align: "right", + }, + ], + rows: [ + [ + { + type: "raw_text", + text: "Header A", + }, + { + type: "raw_text", + text: "Header B", + }, + ], + [ + { + type: "raw_text", + text: "Data 1A", + }, + { + type: "rich_text", + elements: [ + { + type: "rich_text_section", + elements: [ + { + text: "Data 1B", + type: "link", + url: "https://slack.com", + }, + ], + }, + ], + }, + ], + [ + { + type: "raw_text", + text: "Data 2A", + }, + { + type: "rich_text", + elements: [ + { + type: "rich_text_section", + elements: [ + { + text: "Data 2B", + type: "link", + url: "https://slack.com", + }, + ], + }, + ], + }, + ], + ], + }; + assert.deepStrictEqual(block, expected); + }); +});