gitlab-org--gitlab-foss/app/helpers/dropdowns_helper.rb

50 lines
1.6 KiB
Ruby
Raw Normal View History

2016-03-07 15:37:35 +00:00
module DropdownsHelper
2016-03-07 17:17:11 +00:00
def dropdown_tag(toggle_text, id: nil, toggle_class: nil, dropdown_class: nil, title: false, filter: false, placeholder: "", data: {}, &block)
2016-03-07 15:37:35 +00:00
content_tag :div, class: "dropdown" do
2016-03-07 17:17:11 +00:00
toggle_hash = data.merge({toggle: "dropdown"})
2016-03-07 15:37:35 +00:00
dropdown_output = ""
2016-03-07 17:17:11 +00:00
dropdown_output += content_tag :button, class: "dropdown-menu-toggle #{toggle_class}", id: id, type: "button", data: toggle_hash do
2016-03-07 15:37:35 +00:00
output = toggle_text
output << icon('chevron-down')
output.html_safe
end
2016-03-07 17:17:11 +00:00
dropdown_output += content_tag :div, class: "dropdown-menu dropdown-select #{dropdown_class}" do
2016-03-07 15:37:35 +00:00
output = ""
if title
output += content_tag :div, class: "dropdown-title" do
title_output = content_tag(:span, title)
title_output += content_tag :button, class: "dropdown-title-button dropdown-menu-close", aria: {label: "close"} do
icon('times')
end.html_safe
end
end
if filter
output += content_tag :div, class: "dropdown-input" do
filter_output = search_field_tag nil, nil, class: "dropdown-input-field", placeholder: placeholder
filter_output += icon('search')
filter_output.html_safe
end
end
output += content_tag :div, class: "dropdown-content" do
capture(&block) if block
end
output += content_tag :div, class: "dropdown-loading" do
icon('spinner spin')
end
output.html_safe
end
dropdown_output.html_safe
end
end
end