Module: MaquinaComponents::ComboboxHelper
- Defined in:
- app/helpers/maquina_components/combobox_helper.rb
Overview
Combobox Helper
Provides a builder pattern for creating combobox components with a clean API.
Defined Under Namespace
Classes: ComboboxBuilder, ComboboxContentBuilder, ComboboxListBuilder
Instance Method Summary collapse
-
#combobox(id: nil, name: nil, value: nil, placeholder: "Select...", css_classes: "", **html_options) {|ComboboxBuilder| ... } ⇒ String
Renders a combobox using the builder pattern.
-
#combobox_simple(options:, placeholder: "Select...", search_placeholder: "Search...", empty_text: "No results found.", value: nil, name: nil, trigger_options: {}, content_options: {}) ⇒ String
Renders a simple combobox from data.
Instance Method Details
#combobox(id: nil, name: nil, value: nil, placeholder: "Select...", css_classes: "", **html_options) {|ComboboxBuilder| ... } ⇒ String
Renders a combobox using the builder pattern
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 60 def combobox(id: nil, name: nil, value: nil, placeholder: "Select...", css_classes: "", **, &block) builder = ComboboxBuilder.new(self, placeholder: placeholder) combobox_id = id || "combobox-#{SecureRandom.hex(4)}" builder.combobox_id = combobox_id capture(builder, &block) render "components/combobox", id: combobox_id, name: name, value: value, placeholder: placeholder, css_classes: css_classes, ** do |_id| builder.to_html end end |
#combobox_simple(options:, placeholder: "Select...", search_placeholder: "Search...", empty_text: "No results found.", value: nil, name: nil, trigger_options: {}, content_options: {}) ⇒ String
Renders a simple combobox from data
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 89 def combobox_simple( options:, placeholder: "Select...", search_placeholder: "Search...", empty_text: "No results found.", value: nil, name: nil, trigger_options: {}, content_options: {} ) combobox(placeholder: placeholder, value: value, name: name) do |cb| cb.trigger(**) cb.content(**) do cb.input(placeholder: search_placeholder) cb.list do .each do |opt| selected = value.present? && opt[:value].to_s == value.to_s cb.option(value: opt[:value], selected: selected, disabled: opt[:disabled]) do opt[:label] || opt[:value] end end end cb.empty(text: empty_text) end end end |