Class: Slack::BlockKit::Element::RadioButtons

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

Overview

A radio button group that allows a user to choose one item from a list of possible options.

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

Constant Summary collapse

TYPE =
'radio_buttons'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Composition::ConfirmationDialog::Confirmable

#confirmation_dialog, included

Constructor Details

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

Returns a new instance of RadioButtons.

Yields:

  • (_self)

Yield Parameters:



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

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 Attribute Details

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/slack/block_kit/element/radio_buttons.rb', line 14

def options
  @options
end

Instance Method Details

#as_jsonObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/slack/block_kit/element/radio_buttons.rb', line 37

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

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



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/slack/block_kit/element/radio_buttons.rb', line 24

def option(value:, text:, initial: false, emoji: nil)
  option = Composition::Option.new(
    value: value,
    text: text,
    initial: initial,
    emoji: emoji
  )

  @options << option

  self
end