Class: PhlexKit::NativeSelect

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/native_select/native_select.rb

Overview

Styled native via mix. size: is the kit's lone selector here (default | sm) — SIZES.fetch fails loud on anything else.

Constant Summary collapse

SIZES =

size => extra class appended after the base select class (nil = default).

{
  default: nil,
  sm: "sm"
}.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(size: :default, **attrs) ⇒ NativeSelect

Returns a new instance of NativeSelect.



24
25
26
27
# File 'app/components/phlex_kit/native_select/native_select.rb', line 24

def initialize(size: :default, **attrs)
  @size = size.to_sym
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/components/phlex_kit/native_select/native_select.rb', line 29

def view_template(&block)
  div(class: "pk-native-select") do
    select(**mix({
      class: classes,
      data: {
        phlex_kit__form_field_target: "input",
        action: "change->phlex-kit--form-field#onChange invalid->phlex-kit--form-field#onInvalid"
      }
    }, @attrs), &block)
    render PhlexKit::NativeSelectIcon.new
  end
end