Class: Slack::BlockKit::Layout::Section

Inherits:
Object
  • Object
show all
Includes:
MultiSelectElements
Defined in:
lib/slack/block_kit/layout/section.rb,
lib/slack/block_kit/layout/section/multi_select_elements.rb

Overview

A section is one of the most flexible blocks available - it can be used as a simple text block, in combination with text fields, or side-by-side with any of the available block elements.

api.slack.com/reference/messaging/blocks#section

Defined Under Namespace

Modules: MultiSelectElements

Constant Summary collapse

TYPE =
'section'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MultiSelectElements

#multi_channels_select, #multi_conversations_select, #multi_external_select, #multi_static_select, #multi_users_select

Constructor Details

#initialize(block_id: nil) {|_self| ... } ⇒ Section

Returns a new instance of Section.

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
23
24
# File 'lib/slack/block_kit/layout/section.rb', line 17

def initialize(block_id: nil)
  @block_id = block_id
  @fields = nil
  @accessory = nil
  @text = nil

  yield(self) if block_given?
end

Instance Attribute Details

#accessoryObject

Returns the value of attribute accessory.



15
16
17
# File 'lib/slack/block_kit/layout/section.rb', line 15

def accessory
  @accessory
end

#fieldsObject

Returns the value of attribute fields.



15
16
17
# File 'lib/slack/block_kit/layout/section.rb', line 15

def fields
  @fields
end

#textObject

Returns the value of attribute text.



15
16
17
# File 'lib/slack/block_kit/layout/section.rb', line 15

def text
  @text
end

Instance Method Details

#accessorise(element) ⇒ Object



195
196
197
198
199
# File 'lib/slack/block_kit/layout/section.rb', line 195

def accessorise(element)
  @accessory = element

  self
end

#as_jsonObject



201
202
203
204
205
206
207
208
209
# File 'lib/slack/block_kit/layout/section.rb', line 201

def as_json(*)
  {
    type: TYPE,
    text: @text&.as_json,
    block_id: @block_id,
    fields: @fields&.map(&:as_json),
    accessory: @accessory&.as_json
  }.compact
end

#button(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/slack/block_kit/layout/section.rb', line 54

def button(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
  element = Element::Button.new(
    text: text,
    action_id: action_id,
    style: style,
    emoji: emoji,
    url: url,
    value: value
  )

  yield(element) if block_given?

  accessorise(element)
end

#channel_select(placeholder:, action_id:, initial: nil, emoji: nil, response_url_enabled: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/slack/block_kit/layout/section.rb', line 69

def channel_select(placeholder:, action_id:, initial: nil, emoji: nil, response_url_enabled: nil)
  element = Element::ChannelsSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    emoji: emoji,
    response_url_enabled: response_url_enabled
  )

  yield(element) if block_given?

  accessorise(element)
end

#checkboxes(action_id:) {|element| ... } ⇒ Object

Yields:

  • (element)


171
172
173
174
175
176
177
178
179
# File 'lib/slack/block_kit/layout/section.rb', line 171

def checkboxes(action_id:)
  element = Element::Checkboxes.new(
    action_id: action_id
  )

  yield(element) if block_given?

  accessorise(element)
end

#conversation_select(placeholder:, action_id:, initial: nil, emoji: nil, default_to_current_conversation: nil, response_url_enabled: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/slack/block_kit/layout/section.rb', line 83

def conversation_select(placeholder:, action_id:, initial: nil, emoji: nil, default_to_current_conversation: nil, response_url_enabled: nil)
  element = Element::ConversationsSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    emoji: emoji,
    default_to_current_conversation: default_to_current_conversation,
    response_url_enabled: response_url_enabled
  )

  yield(element) if block_given?

  accessorise(element)
end

#datepicker(action_id:, placeholder: nil, initial: nil, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/slack/block_kit/layout/section.rb', line 98

def datepicker(action_id:, placeholder: nil, initial: nil, emoji: nil)
  element = Element::Datepicker.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    emoji: emoji
  )

  yield(element) if block_given?

  accessorise(element)
end

#external_select(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/slack/block_kit/layout/section.rb', line 124

def external_select(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil)
  element = Element::ExternalSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    min_query_length: min_query_length,
    emoji: emoji
  )

  yield(element) if block_given?

  accessorise(element)
end

#image(url:, alt_text:) ⇒ Object



191
192
193
# File 'lib/slack/block_kit/layout/section.rb', line 191

def image(url:, alt_text:)
  accessorise(Element::Image.new(image_url: url, alt_text: alt_text))
end

#mrkdwn(text:, verbatim: nil) ⇒ Object



48
49
50
51
52
# File 'lib/slack/block_kit/layout/section.rb', line 48

def mrkdwn(text:, verbatim: nil)
  @text = Composition::Mrkdwn.new(text: text, verbatim: verbatim)

  self
end

#mrkdwn_field(text:, verbatim: nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/slack/block_kit/layout/section.rb', line 34

def mrkdwn_field(text:, verbatim: nil)
  @fields ||= []

  @fields << Composition::Mrkdwn.new(text: text, verbatim: verbatim)

  self
end

#overflow_menu(action_id:) {|element| ... } ⇒ Object

Yields:

  • (element)


138
139
140
141
142
143
144
# File 'lib/slack/block_kit/layout/section.rb', line 138

def overflow_menu(action_id:)
  element = Element::OverflowMenu.new(action_id: action_id)

  yield(element) if block_given?

  accessorise(element)
end

#plain_text(text:, emoji: nil) ⇒ Object



42
43
44
45
46
# File 'lib/slack/block_kit/layout/section.rb', line 42

def plain_text(text:, emoji: nil)
  @text = Composition::PlainText.new(text: text, emoji: emoji)

  self
end

#plaintext_field(text:, emoji: nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/slack/block_kit/layout/section.rb', line 26

def plaintext_field(text:, emoji: nil)
  @fields ||= []

  @fields << Composition::PlainText.new(text: text, emoji: emoji)

  self
end

#radio_buttons(action_id:) {|element| ... } ⇒ Object

Yields:

  • (element)


181
182
183
184
185
186
187
188
189
# File 'lib/slack/block_kit/layout/section.rb', line 181

def radio_buttons(action_id:)
  element = Element::RadioButtons.new(
    action_id: action_id
  )

  yield(element) if block_given?

  accessorise(element)
end

#static_select(placeholder:, action_id:, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


146
147
148
149
150
151
152
153
154
155
156
# File 'lib/slack/block_kit/layout/section.rb', line 146

def static_select(placeholder:, action_id:, emoji: nil)
  element = Element::StaticSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    emoji: emoji
  )

  yield(element) if block_given?

  accessorise(element)
end

#timepicker(action_id:, placeholder: nil, initial: nil, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/slack/block_kit/layout/section.rb', line 111

def timepicker(action_id:, placeholder: nil, initial: nil, emoji: nil)
  element = Element::Timepicker.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    emoji: emoji
  )

  yield(element) if block_given?

  accessorise(element)
end

#users_select(placeholder:, action_id:, initial: nil, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/slack/block_kit/layout/section.rb', line 158

def users_select(placeholder:, action_id:, initial: nil, emoji: nil)
  element = Element::UsersSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    emoji: emoji,
    initial: initial
  )

  yield(element) if block_given?

  accessorise(element)
end