Sha256: 0b5f6d3e2978a0b9a94077521f2f0a1d2f0f270af2d7c17ba27b2ab1dab43ea2

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Slack
  module BlockKit
    module Element
      # An interactive element that inserts a button.
      # The button can be a trigger for anything from opening a simple link
      # to starting a complex workflow.
      #
      # https://api.slack.com/reference/messaging/block-elements#button
      class Button
        TYPE = 'button'

        attr_accessor :confirm

        def initialize(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
          @text = Composition::PlainText.new(text: text, emoji: emoji)
          @action_id = action_id
          @url = url
          @style = style
          @value = value

          yield(self) if block_given?
        end

        def confirmation_dialog
          @confirm = Composition::ConfirmationDialog.new

          yield(@confirm) if block_given?

          @confirm
        end

        def as_json(*)
          {
            type: TYPE,
            text: @text.as_json,
            action_id: @action_id,
            url: @url,
            value: @value,
            style: @style,
            confirm: @confirm&.as_json
          }.compact
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
slack-ruby-block-kit-0.10.0 lib/slack/block_kit/element/button.rb
slack-ruby-block-kit-0.9.0 lib/slack/block_kit/element/button.rb
slack-ruby-block-kit-0.8.0 lib/slack/block_kit/element/button.rb
slack-ruby-block-kit-0.7.0 lib/slack/block_kit/element/button.rb
slack-ruby-block-kit-0.6.1 lib/slack/block_kit/element/button.rb
slack-ruby-block-kit-0.6.0 lib/slack/block_kit/element/button.rb
slack-ruby-block-kit-0.5.0 lib/slack/block_kit/element/button.rb
slack-ruby-block-kit-0.4.0 lib/slack/block_kit/element/button.rb
slack_block_kit-0.3.3 lib/slack/block_kit/element/button.rb
slack_block_kit-0.3.2 lib/slack/block_kit/element/button.rb
slack_block_kit-0.3.1 lib/slack/block_kit/element/button.rb