Class: MaquinaComponents::ComboboxHelper::ComboboxBuilder
- Inherits:
-
Object
- Object
- MaquinaComponents::ComboboxHelper::ComboboxBuilder
- Defined in:
- app/helpers/maquina_components/combobox_helper.rb
Overview
Builder class for constructing comboboxes
Instance Attribute Summary collapse
-
#combobox_id ⇒ Object
Returns the value of attribute combobox_id.
Instance Method Summary collapse
-
#content(align: :start, width: :default, **options) { ... } ⇒ Object
Defines the content popover.
-
#empty(text: "No results found.", **options) ⇒ Object
Shortcut to add empty directly (delegates to content builder).
-
#initialize(view_context, placeholder:) ⇒ ComboboxBuilder
constructor
A new instance of ComboboxBuilder.
-
#input(placeholder: "Search...", **options) ⇒ Object
Shortcut to add input directly (delegates to content builder).
-
#list(**options, &block) ⇒ Object
Shortcut to add list directly (delegates to content builder).
-
#to_html ⇒ Object
Generates the final HTML.
-
#trigger(variant: :outline, size: :default, **options) ⇒ Object
Defines the trigger button.
Constructor Details
#initialize(view_context, placeholder:) ⇒ ComboboxBuilder
Returns a new instance of ComboboxBuilder.
121 122 123 124 125 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 121 def initialize(view_context, placeholder:) @view = view_context @placeholder = placeholder @parts = [] end |
Instance Attribute Details
#combobox_id ⇒ Object
Returns the value of attribute combobox_id.
119 120 121 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 119 def combobox_id @combobox_id end |
Instance Method Details
#content(align: :start, width: :default, **options) { ... } ⇒ Object
Defines the content popover
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 149 def content(align: :start, width: :default, **, &block) content_builder = ComboboxContentBuilder.new(@view) @view.capture(content_builder, &block) @parts << @view.render( "components/combobox/content", id: combobox_id, align: align, width: width, ** ) { content_builder.to_html } end |
#empty(text: "No results found.", **options) ⇒ Object
Shortcut to add empty directly (delegates to content builder)
173 174 175 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 173 def empty(text: "No results found.", **) @current_content_builder&.empty(text: text, **) end |
#input(placeholder: "Search...", **options) ⇒ Object
Shortcut to add input directly (delegates to content builder)
163 164 165 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 163 def input(placeholder: "Search...", **) @current_content_builder&.input(placeholder: placeholder, **) end |
#list(**options, &block) ⇒ Object
Shortcut to add list directly (delegates to content builder)
168 169 170 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 168 def list(**, &block) @current_content_builder&.list(**, &block) end |
#to_html ⇒ Object
Generates the final HTML
178 179 180 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 178 def to_html @view.safe_join(@parts) end |
#trigger(variant: :outline, size: :default, **options) ⇒ Object
Defines the trigger button
132 133 134 135 136 137 138 139 140 141 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 132 def trigger(variant: :outline, size: :default, **) @parts << @view.render( "components/combobox/trigger", for_id: combobox_id, placeholder: @placeholder, variant: variant, size: size, ** ) end |