Module: DropdownsHelper

Defined in:
app/helpers/dropdowns_helper.rb

Instance Method Summary collapse

Instance Method Details


80
81
82
83
84
85
86
# File 'app/helpers/dropdowns_helper.rb', line 80

def dropdown_content(&block)
  (:div, class: "dropdown-content") do
    if block
      capture(&block)
    end
  end
end

70
71
72
73
74
75
76
77
78
# File 'app/helpers/dropdowns_helper.rb', line 70

def dropdown_filter(placeholder)
   :div, class: "dropdown-input" do
    filter_output = search_field_tag nil, nil, class: "dropdown-input-field", placeholder: placeholder
    filter_output << icon('search', class: "dropdown-input-search")
    filter_output << icon('times', class: "dropdown-input-clear js-dropdown-input-clear", role: "button")

    filter_output.html_safe
  end
end

88
89
90
91
92
93
94
# File 'app/helpers/dropdowns_helper.rb', line 88

def dropdown_footer(&block)
  (:div, class: "dropdown-footer") do
    if block
      capture(&block)
    end
  end
end

96
97
98
99
100
# File 'app/helpers/dropdowns_helper.rb', line 96

def dropdown_loading
   :div, class: "dropdown-loading" do
    icon('spinner spin')
  end
end

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
# File 'app/helpers/dropdowns_helper.rb', line 2

def dropdown_tag(toggle_text, options: {}, &block)
   :div, class: "dropdown" do
    data_attr = { toggle: "dropdown" }

    if options.has_key?(:data)
      data_attr = options[:data].merge(data_attr)
    end

    dropdown_output = dropdown_toggle(toggle_text, data_attr, options)

    dropdown_output << (:div, class: "dropdown-menu dropdown-select #{options[:dropdown_class] if options.has_key?(:dropdown_class)}") do
      output = ""

      if options.has_key?(:title)
        output << dropdown_title(options[:title])
      end

      if options.has_key?(:filter)
        output << dropdown_filter(options[:placeholder])
      end

      output << (:div, class: "dropdown-content") do
        capture(&block) if block && !options.has_key?(:footer_content)
      end

      if block && options[:footer_content]
        output << (:div, class: "dropdown-footer") do
          capture(&block)
        end
      end

      output << dropdown_loading

      output.html_safe
    end

    dropdown_output.html_safe
  end
end

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/dropdowns_helper.rb', line 50

def dropdown_title(title, back: false)
   :div, class: "dropdown-title" do
    title_output = ""

    if back
      title_output << (:button, class: "dropdown-title-button dropdown-menu-back", aria: { label: "Go back" }, type: "button") do
        icon('arrow-left')
      end
    end

    title_output << (:span, title)

    title_output << (:button, class: "dropdown-title-button dropdown-menu-close", aria: { label: "Close" }, type: "button") do
      icon('times', class: 'dropdown-menu-close-icon')
    end

    title_output.html_safe
  end
end

42
43
44
45
46
47
48
# File 'app/helpers/dropdowns_helper.rb', line 42

def dropdown_toggle(toggle_text, data_attr, options)
  (:button, class: "dropdown-menu-toggle #{options[:toggle_class] if options.has_key?(:toggle_class)}", id: (options[:id] if options.has_key?(:id)), type: "button", data: data_attr) do
    output = (:span, toggle_text, class: "dropdown-toggle-text")
    output << icon('chevron-down')
    output.html_safe
  end
end