Class: MaquinaComponents::ComboboxHelper::ComboboxBuilder

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

Overview

Builder class for constructing comboboxes

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject

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

Parameters:

  • align (Symbol) (defaults to: :start)

    Horizontal alignment

  • width (Symbol) (defaults to: :default)

    Width preset

  • options (Hash)

    Additional options

Yields:

  • Block containing combobox content



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, **options, &block)
  content_builder = ComboboxContentBuilder.new(@view)
  @view.capture(content_builder, &block)

  @parts << @view.render(
    "components/combobox/content",
    id: combobox_id,
    align: align,
    width: width,
    **options
  ) { 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.", **options)
  @current_content_builder&.empty(text: text, **options)
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...", **options)
  @current_content_builder&.input(placeholder: placeholder, **options)
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(**options, &block)
  @current_content_builder&.list(**options, &block)
end

#to_htmlObject

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

Parameters:

  • variant (Symbol) (defaults to: :outline)

    Button variant

  • size (Symbol) (defaults to: :default)

    Button size

  • options (Hash)

    Additional options



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, **options)
  @parts << @view.render(
    "components/combobox/trigger",
    for_id: combobox_id,
    placeholder: @placeholder,
    variant: variant,
    size: size,
    **options
  )
end