Class: Maglev::Uikit::Form::ImageFieldComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Maglev::Uikit::Form::ImageFieldComponent
- Defined in:
- app/components/maglev/uikit/form/image_field_component.rb
Instance Attribute Summary collapse
-
#alt_text ⇒ Object
readonly
Returns the value of attribute alt_text.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#search_path ⇒ Object
readonly
Returns the value of attribute search_path.
Instance Method Summary collapse
- #alt_text? ⇒ Boolean
- #dom_id ⇒ Object
- #hidden_input_names ⇒ Object
- #image_url ⇒ Object
-
#initialize(name:, search_path:, options:, alt_text: nil) ⇒ ImageFieldComponent
constructor
A new instance of ImageFieldComponent.
- #spread_fields? ⇒ Boolean
- #value ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(name:, search_path:, options:, alt_text: nil) ⇒ ImageFieldComponent
Returns a new instance of ImageFieldComponent.
9 10 11 12 13 14 15 16 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 9 def initialize(name:, search_path:, options:, alt_text: nil) @name = name @search_path = search_path @value = [:value] @label = [:label] @alt_text = alt_text @spread_fields = [:spread_fields] || false end |
Instance Attribute Details
#alt_text ⇒ Object (readonly)
Returns the value of attribute alt_text.
7 8 9 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 7 def alt_text @alt_text end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 7 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 7 def name @name end |
#search_path ⇒ Object (readonly)
Returns the value of attribute search_path.
7 8 9 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 7 def search_path @search_path end |
Instance Method Details
#alt_text? ⇒ Boolean
18 19 20 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 18 def alt_text? alt_text.present? end |
#dom_id ⇒ Object
22 23 24 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 22 def dom_id name.to_s.parameterize.underscore end |
#hidden_input_names ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 40 def hidden_input_names return [] unless spread_fields? %w[id url filename width height byte_size].index_with do |key| "#{name}[#{key}]" end end |
#image_url ⇒ Object
36 37 38 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 36 def image_url spread_fields? ? value[:url] : value end |
#spread_fields? ⇒ Boolean
26 27 28 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 26 def spread_fields? @spread_fields end |
#value ⇒ Object
30 31 32 33 34 |
# File 'app/components/maglev/uikit/form/image_field_component.rb', line 30 def value return @value unless spread_fields? @value.is_a?(Hash) ? @value.compact_blank : { url: @value } end |