Sha256: 24b6b75a90fe259145aac0d6c0b626efe0725188749c8021eee2c9b740d38487

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Slack
  module BlockKit
    module Element
      # A checkbox group that allows a user to choose multiple items from
      # a list of possible options.
      #
      # https://api.slack.com/reference/messaging/block-elements#checkboxes
      class Checkboxes
        include Composition::ConfirmationDialog::Confirmable

        TYPE = 'checkboxes'

        def initialize(action_id:)
          @action_id = action_id
          @options = []
          @initial_options = []

          yield(self) if block_given?
        end

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

          self
        end

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

          self
        end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack-ruby-block-kit-0.11.0 lib/slack/block_kit/element/checkboxes.rb