-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathblock_table.go
More file actions
55 lines (46 loc) · 1.52 KB
/
block_table.go
File metadata and controls
55 lines (46 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package slack
// TableBlock defines a block that lets you use a table to display your data.
//
// More Information: https://docs.slack.dev/reference/block-kit/blocks/table-block/
type TableBlock struct {
Type MessageBlockType `json:"type"`
BlockID string `json:"block_id,omitempty"`
Rows [][]*RichTextBlock `json:"rows"`
ColumnSettings []ColumnSetting `json:"column_settings,omitempty"`
}
type ColumnAlignment string
const (
ColumnAlignmentLeft ColumnAlignment = "left"
ColumnAlignmentCenter ColumnAlignment = "center"
ColumnAlignmentRight ColumnAlignment = "right"
)
type ColumnSetting struct {
Align ColumnAlignment `json:"align"`
IsWrapped bool `json:"is_wrapped"`
}
// BlockType returns the type of the block
func (s TableBlock) BlockType() MessageBlockType {
return s.Type
}
// ID returns the ID of the block
func (s TableBlock) ID() string {
return s.BlockID
}
// WithColumnSettings sets the column settings for the Table Block
func (s *TableBlock) WithColumnSettings(columnSettings ...ColumnSetting) *TableBlock {
s.ColumnSettings = columnSettings
return s
}
// AddRow adds a new row of cells to the Table Block
func (s *TableBlock) AddRow(cells ...*RichTextBlock) *TableBlock {
s.Rows = append(s.Rows, append([]*RichTextBlock{}, cells...))
return s
}
// NewTableBlock returns an instance of a Table Block type
func NewTableBlock(blockID string) *TableBlock {
return &TableBlock{
Type: MBTTable,
BlockID: blockID,
Rows: make([][]*RichTextBlock, 0),
}
}