Class: Primer::LinkComponent
- Defined in:
- app/components/primer/link_component.rb
Overview
Use Link for navigating from one page to another. Link styles anchor tags with default blue styling and hover text-decoration.
Constant Summary collapse
- DEFAULT_SCHEME =
:default- SCHEME_MAPPINGS =
{ DEFAULT_SCHEME => "", :primary => "Link--primary", :secondary => "Link--secondary" }.freeze
- DEFAULT_TAG =
:a- TAG_OPTIONS =
[DEFAULT_TAG, :span].freeze
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #before_render ⇒ Object
- #call ⇒ Object
-
#initialize(href: nil, tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, muted: false, underline: true, **system_arguments) ⇒ LinkComponent
constructor
A new instance of LinkComponent.
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Constructor Details
#initialize(href: nil, tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, muted: false, underline: true, **system_arguments) ⇒ LinkComponent
Returns a new instance of LinkComponent.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/components/primer/link_component.rb', line 63 def initialize(href: nil, tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, muted: false, underline: true, **system_arguments) @system_arguments = system_arguments @id = @system_arguments[:id] @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:href] = href @system_arguments[:classes] = class_names( @system_arguments[:classes], SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)], "Link" => tag == :span, "Link--muted" => muted, "no-underline" => !underline ) end |
Instance Method Details
#before_render ⇒ Object
79 80 81 |
# File 'app/components/primer/link_component.rb', line 79 def before_render raise ArgumentError, "href is required when using <a> tag" if @system_arguments[:tag] == :a && @system_arguments[:href].nil? && !Rails.env.production? end |
#call ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/components/primer/link_component.rb', line 83 def call if tooltip.present? render Primer::BaseComponent.new(tag: :span, position: :relative) do render(Primer::BaseComponent.new(**@system_arguments)) do content end.to_s + tooltip.to_s end else render(Primer::BaseComponent.new(**@system_arguments)) do content end end end |