-
Notifications
You must be signed in to change notification settings - Fork 29
/
checkboxes.rb
55 lines (45 loc) · 1.33 KB
/
checkboxes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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:, focus_on_load: nil)
@action_id = action_id
@focus_on_load = focus_on_load
@options = []
yield(self) if block_given?
end
def option(value:, text:, initial: false, description: nil)
@options << Composition::Option.new(
value: value,
text: text,
description: description,
initial: initial
)
self
end
def as_json(*)
{
type: TYPE,
action_id: @action_id,
options: @options.map(&:as_json),
initial_options: initial_options&.map(&:as_json),
focus_on_load: @focus_on_load,
confirm: confirm&.as_json
}.compact
end
private
def initial_options
initial = @options.select(&:initial?)
initial.empty? ? nil : initial
end
end
end
end
end