Class: MaquinaComponents::ComboboxHelper::ComboboxContentBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/maquina_components/combobox_helper.rb

Overview

Builder for combobox content

Instance Method Summary collapse

Constructor Details

#initialize(view_context) ⇒ ComboboxContentBuilder

Returns a new instance of ComboboxContentBuilder.



185
186
187
188
# File 'app/helpers/maquina_components/combobox_helper.rb', line 185

def initialize(view_context)
  @view = view_context
  @parts = []
end

Instance Method Details

#empty(text: "No results found.", **options) ⇒ Object

Adds the empty state

Parameters:

  • text (String) (defaults to: "No results found.")

    Empty state text

  • options (Hash)

    Additional options



220
221
222
223
224
225
226
# File 'app/helpers/maquina_components/combobox_helper.rb', line 220

def empty(text: "No results found.", **options)
  @parts << @view.render(
    "components/combobox/empty",
    text: text,
    **options
  )
end

#input(placeholder: "Search...", **options) ⇒ Object

Adds the search input

Parameters:

  • placeholder (String) (defaults to: "Search...")

    Input placeholder

  • options (Hash)

    Additional options



194
195
196
197
198
199
200
# File 'app/helpers/maquina_components/combobox_helper.rb', line 194

def input(placeholder: "Search...", **options)
  @parts << @view.render(
    "components/combobox/input",
    placeholder: placeholder,
    **options
  )
end

#list(**options) { ... } ⇒ Object

Adds the options list container

Parameters:

  • options (Hash)

    Additional options

Yields:

  • Block containing options



206
207
208
209
210
211
212
213
214
# File 'app/helpers/maquina_components/combobox_helper.rb', line 206

def list(**options, &block)
  list_builder = ComboboxListBuilder.new(@view)
  @view.capture(list_builder, &block)

  @parts << @view.render(
    "components/combobox/list",
    **options
  ) { list_builder.to_html }
end

#to_htmlObject

Generates the final HTML



229
230
231
# File 'app/helpers/maquina_components/combobox_helper.rb', line 229

def to_html
  @view.safe_join(@parts)
end