Class: OkonomiUiKit::Components::DropdownButton::DropdownBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/okonomi_ui_kit/components/dropdown_button.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ DropdownBuilder

Returns a new instance of DropdownBuilder.



56
57
58
59
60
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 56

def initialize(view)
  @view = view
  @items = []
  @is_first = true
end

Instance Attribute Details

#is_first ⇒ Object (readonly)

Returns the value of attribute is_first.



54
55
56
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 54

def is_first
  @is_first
end

#items ⇒ Object (readonly)

Returns the value of attribute items.



54
55
56
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 54

def items
  @items
end

#view ⇒ Object (readonly)

Returns the value of attribute view.



54
55
56
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 54

def view
  @view
end

Instance Method Details

#button_tag(content_or_options = nil, options = nil, &block) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 104

def button_tag(content_or_options = nil, options = nil, &block)
  # Handle the different argument patterns for button_tag
  if content_or_options.is_a?(Hash)
    options = content_or_options
    content = nil
  else
    content = content_or_options
  end
  
  options ||= {}
  
  # Handle icon extraction
  icon = options.delete(:icon) if options.is_a?(Hash)
  
  # Ensure type is button for button_tag
  options[:type] ||= "button"
  
  item = {
    type: :button_tag,
    name: content,
    options: options,
    block: block,
    is_first: @is_first,
    icon: icon
  }
  @items << item
  @is_first = false
end

#button_to(name = nil, options = {}, html_options = {}, &block) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 83

def button_to(name = nil, options = {}, html_options = {}, &block)
  # Handle icon extraction
  if html_options.is_a?(Hash)
    icon = html_options.delete(:icon)
  else
    icon = nil
  end

  item = {
    type: :button,
    name: name,
    options: options,
    html_options: html_options,
    block: block,
    is_first: @is_first,
    icon: icon
  }
  @items << item
  @is_first = false
end

#divider ⇒ Object



133
134
135
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 133

def divider
  @items << { type: :divider }
end


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 62

def link_to(name = nil, options = nil, html_options = nil, &block)
  # Handle icon extraction
  if html_options.is_a?(Hash)
    icon = html_options.delete(:icon)
  else
    icon = nil
  end

  item = {
    type: :link,
    name: name,
    options: options,
    html_options: html_options || {},
    block: block,
    is_first: @is_first,
    icon: icon
  }
  @items << item
  @is_first = false
end


141
142
143
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 141

def menu_items
  @items
end

#primary_item ⇒ Object



137
138
139
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 137

def primary_item
  @items.find { |item| item[:is_first] && item[:type] != :divider }
end