Sha256: 7d041ff34bdac4a9e1dd83a92938deb97f8acb0688e20c2bbe560c24f330b455

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Slack
  module BlockKit
    module Element
      # An element which allows selection of a time of day.
      #
      # On desktop clients, this time picker will take the form of a dropdown
      # list with free-text entry for precise choices. On mobile clients, the
      # time picker will use native time picker UIs.
      #
      # https://api.slack.com/reference/block-kit/block-elements#timepicker
      class Timepicker
        include Composition::ConfirmationDialog::Confirmable

        TYPE = 'timepicker'

        def initialize(action_id:, placeholder: nil, initial: nil, emoji: nil, focus_on_load: nil)
          @placeholder = placeholder_text(placeholder, emoji) if placeholder
          @initial_time = initial
          @action_id = action_id
          @focus_on_load = focus_on_load

          yield(self) if block_given?
        end

        def as_json(*)
          {
            type: TYPE,
            action_id: @action_id,
            placeholder: @placeholder&.as_json,
            initial_time: @initial_time,
            focus_on_load: @focus_on_load,
            confirm: confirm&.as_json
          }.compact
        end

        private

        def placeholder_text(text, emoji)
          return unless text

          Composition::PlainText.new(text: text, emoji: emoji)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slack-ruby-block-kit-0.24.0 lib/slack/block_kit/element/timepicker.rb
slack-ruby-block-kit-0.23.0 lib/slack/block_kit/element/timepicker.rb
slack-ruby-block-kit-0.22.0 lib/slack/block_kit/element/timepicker.rb
slack-ruby-block-kit-0.21.0 lib/slack/block_kit/element/timepicker.rb
slack-ruby-block-kit-0.20.0 lib/slack/block_kit/element/timepicker.rb