Class: Maglev::Uikit::Form::LinkComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Maglev::Uikit::Form::LinkComponent
- Defined in:
- app/components/maglev/uikit/form/link_component.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .default_link_type_klass ⇒ Object
- .link_type_component(input_name:, value:, path:) ⇒ Object
- .link_type_klasses_map ⇒ Object
Instance Method Summary collapse
- #dom_id ⇒ Object
- #error ⇒ Object
-
#initialize(name:, path:, options: {}) ⇒ LinkComponent
constructor
Value: { link_type:, link_id:, href:, text: }.
- #label ⇒ Object
- #link_text ⇒ Object
- #link_type_component ⇒ Object
- #placeholder ⇒ Object
- #turbo_frame_id ⇒ Object
- #value ⇒ Object
- #value? ⇒ Boolean
- #with_text? ⇒ Boolean
Methods inherited from BaseComponent
Constructor Details
#initialize(name:, path:, options: {}) ⇒ LinkComponent
Value: { link_type:, link_id:, href:, text: }
10 11 12 13 14 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 10 def initialize(name:, path:, options: {}) @name = name @options = @path = path.gsub(':id', dom_id) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 7 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 7 def path @path end |
Class Method Details
.default_link_type_klass ⇒ Object
78 79 80 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 78 def self.default_link_type_klass Maglev::Uikit::Form::Link::UrlLinkComponent end |
.link_type_component(input_name:, value:, path:) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 60 def self.link_type_component(input_name:, value:, path:) # Default to url if the link type is not found (shouldn't happen) klass = link_type_klasses_map.fetch(value[:link_type]&.to_sym, default_link_type_klass) return unless klass klass.new(input_name: input_name, link: value, path: path) end |
.link_type_klasses_map ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 69 def self.link_type_klasses_map { email: Maglev::Uikit::Form::Link::EmailLinkComponent, url: Maglev::Uikit::Form::Link::UrlLinkComponent, page: Maglev::Uikit::Form::Link::PageLinkComponent, static_page: Maglev::Uikit::Form::Link::StaticPageLinkComponent } end |
Instance Method Details
#dom_id ⇒ Object
16 17 18 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 16 def dom_id name.to_s.parameterize.underscore end |
#error ⇒ Object
40 41 42 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 40 def error [:error] end |
#label ⇒ Object
28 29 30 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 28 def label [:label] end |
#link_text ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 48 def link_text { name: "#{name}[text]", value: value[:text], placeholder: t('maglev.uikit.form.link.text_placeholder') }.merge([:link_text] || {}) end |
#link_type_component ⇒ Object
56 57 58 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 56 def link_type_component self.class.link_type_component(input_name: name, value: value, path: path) end |
#placeholder ⇒ Object
36 37 38 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 36 def placeholder [:placeholder].presence || t('maglev.uikit.form.link.placeholder') end |
#turbo_frame_id ⇒ Object
20 21 22 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 20 def turbo_frame_id "#{dom_id}-frame" end |
#value ⇒ Object
24 25 26 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 24 def value ([:value] || {}).with_indifferent_access end |
#value? ⇒ Boolean
32 33 34 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 32 def value? value&.compact_blank.present? end |
#with_text? ⇒ Boolean
44 45 46 |
# File 'app/components/maglev/uikit/form/link_component.rb', line 44 def with_text? !![:with_text] end |