Class: Polaris::Navigation::ItemComponent::SecondaryActionComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/navigation/item_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 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: nil, external: false, icon: nil, **system_arguments) ⇒ SecondaryActionComponent

Returns a new instance of SecondaryActionComponent.



66
67
68
69
70
71
# File 'app/components/polaris/navigation/item_component.rb', line 66

def initialize(url: nil, external: false, icon: nil, **system_arguments)
  @url = url
  @external = external
  @icon = icon
  @system_arguments = system_arguments
end

Instance Method Details

#callObject



90
91
92
93
94
95
96
97
98
99
100
# File 'app/components/polaris/navigation/item_component.rb', line 90

def call
  tag.span do
    render(Polaris::BaseComponent.new(**system_arguments)) do
      if @icon.present?
        render(Polaris::IconComponent.new(name: @icon))
      else
        content
      end
    end
  end
end

#system_argumentsObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/components/polaris/navigation/item_component.rb', line 73

def system_arguments
  @system_arguments.tap do |opts|
    if @url.present?
      opts[:tag] = "a"
      opts[:href] = @url
      opts[:target] = "_blank" if @external
    else
      opts[:tag] = "button"
      opts[:type] = "button"
    end
    opts[:classes] = class_names(
      @system_arguments[:classes],
      "Polaris-Navigation__SecondaryAction"
    )
  end
end