Class: Practical::Views::Navigation::NavigationLinkComponent

Inherits:
ApplicationComponent
  • Object
show all
Defined in:
app/components/practical/views/navigation/navigation_link_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href:, selected:, options: {}) ⇒ NavigationLinkComponent

Returns a new instance of NavigationLinkComponent.



8
9
10
11
12
# File 'app/components/practical/views/navigation/navigation_link_component.rb', line 8

def initialize(href:, selected:, options: {})
  self.href = href
  self.options = options
  self.selected = selected
end

Instance Attribute Details

#hrefObject

Returns the value of attribute href.



4
5
6
# File 'app/components/practical/views/navigation/navigation_link_component.rb', line 4

def href
  @href
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'app/components/practical/views/navigation/navigation_link_component.rb', line 4

def options
  @options
end

#selectedObject

Returns the value of attribute selected.



4
5
6
# File 'app/components/practical/views/navigation/navigation_link_component.rb', line 4

def selected
  @selected
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
# File 'app/components/practical/views/navigation/navigation_link_component.rb', line 31

def call
  tag.a(**finalized_options) {
    safe_join([
      (icon if icon?),
      tag.span{ content }
    ])
  }
end

#finalized_optionsObject



23
24
25
26
27
28
29
# File 'app/components/practical/views/navigation/navigation_link_component.rb', line 23

def finalized_options
  mix({
    href: href,
    class: helpers.class_names(flank_class, "navigation-link", "wa-accent"),
    data: {selected: selected?}
  }, options)
end

#flank_classObject



14
15
16
# File 'app/components/practical/views/navigation/navigation_link_component.rb', line 14

def flank_class
  return "wa-flank wa-gap-2xs" if icon?
end

#selected?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'app/components/practical/views/navigation/navigation_link_component.rb', line 18

def selected?
  return true if selected
  return nil
end