class Slack::BlockKit::Element::Checkboxes

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

Constants

TYPE

Public Class Methods

new(action_id:) { |self| ... } click to toggle source
# File lib/slack/block_kit/element/checkboxes.rb, line 15
def initialize(action_id:)
  @action_id = action_id
  @options = []

  yield(self) if block_given?
end

Public Instance Methods

as_json(*) click to toggle source
# File lib/slack/block_kit/element/checkboxes.rb, line 33
def as_json(*)
  {
    type: TYPE,
    action_id: @action_id,
    options: @options.map(&:as_json),
    initial_options: initial_options&.map(&:as_json),
    confirm: confirm&.as_json
  }.compact
end
option(value:, text:, initial: false, description: nil) click to toggle source
# File lib/slack/block_kit/element/checkboxes.rb, line 22
def option(value:, text:, initial: false, description: nil)
  @options << Composition::Option.new(
    value: value,
    text: text,
    description: description,
    initial: initial
  )

  self
end

Private Instance Methods

initial_options() click to toggle source
# File lib/slack/block_kit/element/checkboxes.rb, line 45
def initial_options
  initial = @options.select(&:initial?)

  initial.empty? ? nil : initial
end