Class: RubyUIAdmin::UI::Select
- Defined in:
- app/components/ruby_ui_admin/ui/select.rb
Overview
Convenience wrapper around RubyUI's NativeSelect: takes an array of [label, value]
options (plus selected:/include_blank:) instead of explicit option components,
so call sites stay terse. Renders the styled native select with a custom chevron.
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options: [], selected: nil, include_blank: false, **attrs) ⇒ Select
constructor
A new instance of Select.
- #view_template ⇒ Object
Constructor Details
#initialize(options: [], selected: nil, include_blank: false, **attrs) ⇒ Select
Returns a new instance of Select.
9 10 11 12 13 14 |
# File 'app/components/ruby_ui_admin/ui/select.rb', line 9 def initialize(options: [], selected: nil, include_blank: false, **attrs) @options = @selected = selected @include_blank = include_blank super(**attrs) end |
Instance Method Details
#view_template ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/components/ruby_ui_admin/ui/select.rb', line 16 def view_template render NativeSelect.new(**attrs) do render(NativeSelectOption.new(value: "")) { "—" } if @include_blank @options.each do |(label, value)| opts = {value: value} opts[:selected] = true if value.to_s == @selected.to_s render(NativeSelectOption.new(**opts)) { label.to_s } end end end |