Class: Slack::BlockKit::Element::Checkboxes

Inherits:
Object
  • Object
show all
Includes:
Composition::ConfirmationDialog::Confirmable
Defined in:
lib/slack/block_kit/element/checkboxes.rb

Overview

A checkbox group that allows a user to choose multiple items from a list of possible options.

api.slack.com/reference/messaging/block-elements#checkboxes

Constant Summary collapse

TYPE =
'checkboxes'

Instance Method Summary collapse

Methods included from Composition::ConfirmationDialog::Confirmable

#confirmation_dialog, included

Constructor Details

#initialize(action_id:, focus_on_load: nil) {|_self| ... } ⇒ Checkboxes

Returns a new instance of Checkboxes.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
20
21
# File 'lib/slack/block_kit/element/checkboxes.rb', line 15

def initialize(action_id:, focus_on_load: nil)
  @action_id = action_id
  @focus_on_load = focus_on_load
  @options = []

  yield(self) if block_given?
end

Instance Method Details

#as_jsonObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/slack/block_kit/element/checkboxes.rb', line 34

def as_json(*)
  {
    type: TYPE,
    action_id: @action_id,
    options: @options.map(&:as_json),
    initial_options: initial_options&.map(&:as_json),
    focus_on_load: @focus_on_load,
    confirm: confirm&.as_json
  }.compact
end

#option(value:, text:, initial: false, description: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/slack/block_kit/element/checkboxes.rb', line 23

def option(value:, text:, initial: false, description: nil)
  @options << Composition::Option.new(
    value: value,
    text: text,
    description: description,
    initial: initial
  )

  self
end