Module: DropdownsHelper
- Defined in:
- app/helpers/dropdowns_helper.rb
Instance Method Summary collapse
- #dropdown_content(&block) ⇒ Object
- #dropdown_data_attr(options: {}) ⇒ Object
- #dropdown_filter(placeholder, search_id: nil) ⇒ Object
- #dropdown_footer(add_content_class: false, &block) ⇒ Object
- #dropdown_loading ⇒ Object
-
#dropdown_tag(toggle_text, options: {}, &block) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #dropdown_title(title, options: {}) ⇒ Object
-
#dropdown_toggle(toggle_text, data_attr, options = {}) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity.
- #dropdown_toggle_link(toggle_text, data_attr, options = {}) ⇒ Object
Instance Method Details
#dropdown_content(&block) ⇒ Object
139 140 141 142 143 144 145 |
# File 'app/helpers/dropdowns_helper.rb', line 139 def dropdown_content(&block) content_tag(:div, class: "dropdown-content") do if block capture(&block) end end end |
#dropdown_data_attr(options: {}) ⇒ Object
4 5 6 7 |
# File 'app/helpers/dropdowns_helper.rb', line 4 def dropdown_data_attr(options: {}) output = content_tag(:div, "", id: "js-template-selectors-menu", data: [:data]) output.html_safe end |
#dropdown_filter(placeholder, search_id: nil) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'app/helpers/dropdowns_helper.rb', line 128 def dropdown_filter(placeholder, search_id: nil) content_tag :div, class: "dropdown-input" do filter_output = search_field_tag search_id, nil, data: { testid: "dropdown-input-field" }, id: nil, class: "dropdown-input-field", placeholder: placeholder, autocomplete: 'off' filter_output << sprite_icon('search', css_class: 'dropdown-input-search') filter_output << sprite_icon('close', size: 16, css_class: 'dropdown-input-clear js-dropdown-input-clear') filter_output.html_safe end end |
#dropdown_footer(add_content_class: false, &block) ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'app/helpers/dropdowns_helper.rb', line 147 def (add_content_class: false, &block) content_tag(:div, class: "dropdown-footer") do if add_content_class content_tag(:div, capture(&block), class: "dropdown-footer-content") else capture(&block) end end end |
#dropdown_loading ⇒ Object
157 158 159 160 |
# File 'app/helpers/dropdowns_helper.rb', line 157 def dropdown_loading spinner = gl_loading_icon(size: "md", css_class: "gl-mt-7") content_tag(:div, spinner, class: "dropdown-loading") end |
#dropdown_tag(toggle_text, options: {}, &block) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
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 56 57 58 |
# File 'app/helpers/dropdowns_helper.rb', line 10 def dropdown_tag(toggle_text, options: {}, &block) content_tag :div, class: "dropdown #{[:wrapper_class] if .key?(:wrapper_class)}" do data_attr = { toggle: "dropdown" } if .key?(:data) data_attr = [:data].merge(data_attr) end dropdown_output = dropdown_toggle(toggle_text, data_attr, ) if .key?(:toggle_link) dropdown_output = dropdown_toggle_link(toggle_text, data_attr, ) end = { class: "dropdown-menu dropdown-select #{[:dropdown_class] if .key?(:dropdown_class)}" } [:data] ||= {} [:data][:testid] = ([:dropdown_testid]).to_s if [:dropdown_testid] dropdown_output << content_tag(:div, ) do output = [] if .key?(:title) output << dropdown_title([:title]) end if .key?(:filter) output << dropdown_filter([:placeholder]) end output << content_tag(:div, data: { testid: "dropdown-list-content" }, class: "dropdown-content #{[:content_class] if .key?(:content_class)}") do capture(&block) if block && !.key?(:footer_content) end if block && [:footer_content] output << content_tag(:div, class: "dropdown-footer") do capture(&block) end end output << dropdown_loading output.join.html_safe end dropdown_output.html_safe end end |
#dropdown_title(title, options: {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/helpers/dropdowns_helper.rb', line 87 def dropdown_title(title, options: {}) has_back = .fetch(:back, false) has_close = .fetch(:close, true) container_class = %w[dropdown-title gl-flex] margin_class = [] if has_back && has_close container_class << 'gl-justify-between' elsif has_back margin_class << 'gl-mr-auto' elsif has_close margin_class << 'gl-ml-auto' end container_class = container_class.join(' ') margin_class = margin_class.join(' ') content_tag :div, class: container_class do title_output = [] if has_back title_output << content_tag(:button, class: "dropdown-title-button dropdown-menu-back #{margin_class}", aria: { label: "Go back" }, type: "button") do sprite_icon('arrow-left') end end title_output << content_tag(:span, title, class: margin_class) if has_close title_output << content_tag(:button, class: "dropdown-title-button dropdown-menu-close #{margin_class}", aria: { label: "Close" }, type: "button") do sprite_icon('close', size: 16, css_class: 'dropdown-menu-close-icon') end end title_output.join.html_safe end end |
#dropdown_toggle(toggle_text, data_attr, options = {}) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/dropdowns_helper.rb', line 61 def dropdown_toggle(toggle_text, data_attr, = {}) default_label = data_attr[:default_label] content_tag( :button, disabled: [:disabled], class: "dropdown-menu-toggle #{[:toggle_class] if .key?(:toggle_class)}", id: ([:id] if .key?(:id)), type: "button", data: data_attr ) do output = content_tag(:span, toggle_text, class: "dropdown-toggle-text #{'is-default' if toggle_text == default_label}") output << sprite_icon('chevron-down', css_class: "dropdown-menu-toggle-icon") output.html_safe end end |
#dropdown_toggle_link(toggle_text, data_attr, options = {}) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'app/helpers/dropdowns_helper.rb', line 77 def dropdown_toggle_link(toggle_text, data_attr, = {}) output = content_tag( :a, toggle_text, class: "dropdown-toggle-text #{[:toggle_class] if .key?(:toggle_class)}", id: ([:id] if .key?(:id)), data: data_attr ) output.html_safe end |