Class: Maglev::Uikit::Form::SearchFormComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/maglev/uikit/form/search_form_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#button_class_names

Constructor Details

#initialize(name:, value:, search_path:, options: {}) ⇒ SearchFormComponent

Returns a new instance of SearchFormComponent.



9
10
11
12
13
14
15
16
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 9

def initialize(name:, value:, search_path:, options: {})
  @name = name
  @value = value
  @search_path = search_path
  @placeholder = options[:placeholder]
  @class_names = options[:class_names]
  @data = options[:data]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 7

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 7

def name
  @name
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



7
8
9
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 7

def placeholder
  @placeholder
end

#search_pathObject (readonly)

Returns the value of attribute search_path.



7
8
9
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 7

def search_path
  @search_path
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 7

def value
  @value
end

Instance Method Details

#class_namesObject



18
19
20
21
22
23
24
25
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 18

def class_names
  class_variants(
    base: %(
      inline-flex items-center py-2 px-4 rounded bg-gray-100 text-gray-800
      has-[:focus]:ring has-[:focus]:ring-inset has-[:focus]:ring-2 has-[:focus]:ring-editor-primary/50
    )
  ).render(class: @class_names || '')
end

#clear_button_class_namesObject



27
28
29
30
31
32
33
34
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 27

def clear_button_class_names(...)
  class_variants(
    base: 'ml-1 text-gray-500 cursor-pointer',
    variants: {
      invisible: 'invisible'
    }
  ).render(invisible: value_size.zero?)
end

#value_sizeObject



36
37
38
# File 'app/components/maglev/uikit/form/search_form_component.rb', line 36

def value_size
  value&.size || 0
end