Module: Spree::Admin::DropdownHelper

Defined in:
app/helpers/spree/admin/dropdown_helper.rb

Instance Method Summary collapse

Instance Method Details



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

def dropdown(options = {}, &block)
  options[:class] = ['dropdown'] + Array(options[:class])

  # Extract direction option for backward compatibility and convert to Floating UI placement
  placement = case options.delete(:direction)
  when 'left'
    'bottom-end'
  when 'top'
    'top-start'
  when 'top-left'
    'top-end'
  else
    options[:placement] || 'bottom-start'
  end

  # Extract portal option
  portal = options.delete(:portal)

  data_attrs = {
    controller: 'dropdown',
    dropdown_placement_value: placement
  }

  # Add portal value if explicitly set
  data_attrs[:dropdown_portal_value] = portal unless portal.nil?

  options[:data] = data_attrs.merge(options[:data] || {})
  (:div, options, &block)
end


44
45
46
47
48
49
50
51
# File 'app/helpers/spree/admin/dropdown_helper.rb', line 44

def dropdown_menu(options = {}, &block)
  options[:class] = ['dropdown-container hidden'] + Array(options[:class])
  options[:data] = {
    dropdown_target: 'menu'
  }.merge(options[:data] || {})

  (:div, options, &block)
end


34
35
36
37
38
39
40
41
42
# File 'app/helpers/spree/admin/dropdown_helper.rb', line 34

def dropdown_toggle(options = {}, &block)
  options[:type] = 'button'
  options[:class] = ['btn'] + Array(options[:class])
  options[:data] = {
    action: 'dropdown#toggle click@window->dropdown#hide',
    dropdown_target: 'toggle'
  }.merge(options[:data] || {})
  button_tag(options, &block)
end