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

102 lines
3.0 KiB
Ruby
Raw Normal View History

2016-03-07 15:37:35 +00:00
module DropdownsHelper
2016-03-09 10:19:41 +00:00
def dropdown_tag(toggle_text, options: {}, &block)
2016-03-07 15:37:35 +00:00
content_tag :div, class: "dropdown" do
2016-03-09 10:19:41 +00:00
data_attr = { toggle: "dropdown" }
2016-03-07 17:17:11 +00:00
2016-03-09 10:19:41 +00:00
if options.has_key?(:data)
data_attr = options[:data].merge(data_attr)
2016-03-07 15:37:35 +00:00
end
2016-03-09 10:19:41 +00:00
dropdown_output = dropdown_toggle(toggle_text, data_attr, options)
2016-03-07 15:37:35 +00:00
2016-03-09 10:19:41 +00:00
dropdown_output << content_tag(:div, class: "dropdown-menu dropdown-select #{options[:dropdown_class] if options.has_key?(:dropdown_class)}") do
output = ""
2016-03-07 15:37:35 +00:00
2016-03-09 10:19:41 +00:00
if options.has_key?(:title)
output << dropdown_title(options[:title])
2016-03-07 15:37:35 +00:00
end
2016-03-09 10:19:41 +00:00
if options.has_key?(:filter)
output << dropdown_filter(options[:placeholder])
2016-03-07 15:37:35 +00:00
end
2016-03-09 10:19:41 +00:00
output << content_tag(:div, class: "dropdown-content") do
capture(&block) if block && !options.has_key?(:footer_content)
end
if block && options[:footer_content]
2016-03-09 10:19:41 +00:00
output << content_tag(:div, class: "dropdown-footer") do
capture(&block)
end
2016-03-07 15:37:35 +00:00
end
2016-03-09 10:19:41 +00:00
output << dropdown_loading
2016-03-07 15:37:35 +00:00
output.html_safe
end
dropdown_output.html_safe
end
end
2016-03-09 10:19:41 +00:00
def dropdown_toggle(toggle_text, data_attr, options = {})
2016-03-09 10:19:41 +00:00
content_tag(: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 = content_tag(:span, toggle_text, class: "dropdown-toggle-text")
output << icon('chevron-down')
output.html_safe
end
end
def dropdown_title(title, back: false)
content_tag :div, class: "dropdown-title" do
title_output = ""
if back
title_output << content_tag(:button, class: "dropdown-title-button dropdown-menu-back", aria: { label: "Go back" }, type: "button") do
icon('arrow-left')
end
end
title_output << content_tag(:span, title)
title_output << content_tag(:button, class: "dropdown-title-button dropdown-menu-close", aria: { label: "Close" }, type: "button") do
icon('times', class: 'dropdown-menu-close-icon')
2016-03-09 10:19:41 +00:00
end
title_output.html_safe
end
end
2016-06-09 09:44:17 +00:00
def dropdown_filter(placeholder, search_id: nil)
2016-03-09 10:19:41 +00:00
content_tag :div, class: "dropdown-input" do
filter_output = search_field_tag search_id, nil, class: "dropdown-input-field", placeholder: placeholder, autocomplete: 'off'
2016-03-18 16:53:15 +00:00
filter_output << icon('search', class: "dropdown-input-search")
filter_output << icon('times', class: "dropdown-input-clear js-dropdown-input-clear", role: "button")
2016-03-09 10:19:41 +00:00
filter_output.html_safe
end
end
def dropdown_content(&block)
content_tag(:div, class: "dropdown-content") do
if block
capture(&block)
end
end
end
def dropdown_footer(&block)
content_tag(:div, class: "dropdown-footer") do
if block
capture(&block)
end
end
end
def dropdown_loading
content_tag :div, class: "dropdown-loading" do
icon('spinner spin')
end
end
2016-03-07 15:37:35 +00:00
end