Class: Polaris::ShopifyNavigationComponent::ShopifyNavigationLinkComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/shopify_navigation_component.rb

Constant Summary

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from Polaris::StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(url:, auto_detect_active:, active: false, **system_arguments) ⇒ ShopifyNavigationLinkComponent

Returns a new instance of ShopifyNavigationLinkComponent.



25
26
27
28
29
30
# File 'app/components/polaris/shopify_navigation_component.rb', line 25

def initialize(url:, auto_detect_active:, active: false, **system_arguments)
  @url = url
  @auto_detect_active = auto_detect_active
  @active = active
  @system_arguments = system_arguments
end

Instance Method Details

#callObject



32
33
34
35
36
37
38
# File 'app/components/polaris/shopify_navigation_component.rb', line 32

def call
  tag.li(class: "shp-Navigation_Item", role: "presentation") do
    render(Polaris::BaseComponent.new(**system_arguments)) do
      tag.span(class: "shp-Navigation_LinkText") { content }
    end
  end
end

#detect_active(url) ⇒ Object



56
57
58
59
60
# File 'app/components/polaris/shopify_navigation_component.rb', line 56

def detect_active(url)
  return unless @auto_detect_active

  request.path.include?(url.split("?").first)
end

#system_argumentsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/polaris/shopify_navigation_component.rb', line 40

def system_arguments
  {
    tag: "a",
    href: @url,
    role: "tab",
    data: {polaris_unstyled: true},
    aria: {}
  }.deep_merge(@system_arguments).tap do |args|
    args[:aria][:selected] = @active || detect_active(@url)
    args[:classes] = class_names(
      args[:classes],
      "shp-Navigation_Link"
    )
  end
end