Sha256: 9f52d467a9537f46c018ee71c872ed5ad4433104b0741f5016448ff7d6bf67b6

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Slack
  module BlockKit
    module Element
      # A radio button group that allows a user to choose one item from a list of possible options.
      #
      # https://api.slack.com/reference/messaging/block-elements#radio
      class RadioButtons
        include Composition::ConfirmationDialog::Confirmable

        TYPE = 'radio_buttons'

        attr_accessor :options, :initial_option

        def initialize(action_id:)
          @action_id = action_id

          yield(self) if block_given?
        end

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

          @options ||= []
          @options << option

          @initial_option = option if initial

          self
        end

        def as_json(*)
          {
            type: TYPE,
            action_id: @action_id,
            options: @options&.map(&:as_json),
            initial_option: @initial_option&.as_json,
            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/radio_buttons.rb