Class: MaquinaComponents::DropdownMenuHelper::DropdownMenuBuilder
- Inherits:
-
Object
- Object
- MaquinaComponents::DropdownMenuHelper::DropdownMenuBuilder
- Defined in:
- app/helpers/maquina_components/dropdown_menu_helper.rb
Overview
Builder class for constructing dropdown menus
Instance Method Summary collapse
-
#content(align: :start, side: :bottom, width: :default, **options) { ... } ⇒ Object
Defines the menu content.
-
#initialize(view_context) ⇒ DropdownMenuBuilder
constructor
A new instance of DropdownMenuBuilder.
-
#to_html ⇒ Object
Generates the final HTML.
-
#trigger(variant: :outline, size: :default, as_child: false, **options) { ... } ⇒ Object
Defines the trigger button.
Constructor Details
#initialize(view_context) ⇒ DropdownMenuBuilder
Returns a new instance of DropdownMenuBuilder.
89 90 91 92 93 |
# File 'app/helpers/maquina_components/dropdown_menu_helper.rb', line 89 def initialize(view_context) @view = view_context @trigger_content = nil @content_block = nil end |
Instance Method Details
#content(align: :start, side: :bottom, width: :default, **options) { ... } ⇒ Object
Defines the menu content
114 115 116 117 118 |
# File 'app/helpers/maquina_components/dropdown_menu_helper.rb', line 114 def content(align: :start, side: :bottom, width: :default, **, &block) @content_options = {align: align, side: side, width: width, **} @content_builder = DropdownMenuContentBuilder.new(@view) @view.capture(@content_builder, &block) end |
#to_html ⇒ Object
Generates the final HTML
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/helpers/maquina_components/dropdown_menu_helper.rb', line 121 def to_html parts = [] if @trigger_content parts << @view.render( "components/dropdown_menu/trigger", **@trigger_options ) { @trigger_content } end if @content_builder parts << @view.render( "components/dropdown_menu/content", **@content_options ) { @content_builder.to_html } end @view.safe_join(parts) end |
#trigger(variant: :outline, size: :default, as_child: false, **options) { ... } ⇒ Object
Defines the trigger button
102 103 104 105 |
# File 'app/helpers/maquina_components/dropdown_menu_helper.rb', line 102 def trigger(variant: :outline, size: :default, as_child: false, **, &block) @trigger_options = {variant: variant, size: size, as_child: as_child, **} @trigger_content = @view.capture(&block) end |