Module: DropdownsHelper

Defined in:
app/helpers/dropdowns_helper.rb

Instance Method Summary collapse

Instance Method Details


105
106
107
108
109
110
111
# File 'app/helpers/dropdowns_helper.rb', line 105

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

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

def dropdown_filter(placeholder, search_id: nil)
   :div, class: "dropdown-input" do
    filter_output = search_field_tag search_id, nil, class: "dropdown-input-field qa-dropdown-input-field", placeholder: placeholder, autocomplete: 'off'
    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

113
114
115
116
117
118
119
120
121
# File 'app/helpers/dropdowns_helper.rb', line 113

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

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

def dropdown_input(placeholder, input_id: nil)
   :div, class: "dropdown-input" do
    filter_output = text_field_tag input_id, nil, class: "dropdown-input-field dropdown-no-filter", placeholder: placeholder, autocomplete: 'off'
    filter_output << icon('times', class: "dropdown-input-clear js-dropdown-input-clear", role: "button")

    filter_output.html_safe
  end
end

123
124
125
126
127
# File 'app/helpers/dropdowns_helper.rb', line 123

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

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

def dropdown_tag(toggle_text, options: {}, &block)
   :div, class: "dropdown #{options[:wrapper_class] if options.key?(:wrapper_class)}" do
    data_attr = { toggle: "dropdown" }

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

    dropdown_output = dropdown_toggle(toggle_text, data_attr, options)

    if options.key?(:toggle_link)
      dropdown_output = dropdown_toggle_link(toggle_text, data_attr, options)
    end

     = { class: "dropdown-menu dropdown-select #{options[:dropdown_class] if options.key?(:dropdown_class)}" }
    [:data] = { qa_selector: "#{options[:dropdown_qa_selector]}" } if options[:dropdown_qa_selector]

    dropdown_output << (:div, ) do
      output = []

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

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

      output << (:div, class: "dropdown-content #{options[:content_class] if options.key?(:content_class)}") do
        capture(&block) if block && !options.key?(:footer_content)
      end

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

      output << dropdown_loading
      output.join.html_safe
    end

    dropdown_output.html_safe
  end
end

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/dropdowns_helper.rb', line 64

def dropdown_title(title, options: {})
   :div, class: "dropdown-title" do
    title_output = []

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

    title_output << (:span, title)

    if options.fetch(:close, true)
      title_output << (:button, class: "dropdown-title-button dropdown-menu-close", aria: { label: "Close" }, type: "button") do
        sprite_icon('close', css_class: 'dropdown-menu-close-icon')
      end
    end

    title_output.join.html_safe
  end
end

50
51
52
53
54
55
56
57
# File 'app/helpers/dropdowns_helper.rb', line 50

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

59
60
61
62
# File 'app/helpers/dropdowns_helper.rb', line 59

def dropdown_toggle_link(toggle_text, data_attr, options = {})
  output = (:a, toggle_text, class: "dropdown-toggle-text #{options[:toggle_class] if options.key?(:toggle_class)}", id: (options[:id] if options.key?(:id)), data: data_attr)
  output.html_safe
end