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.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/components/primer/link_component.rb', line 40 def initialize(href: nil, tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, muted: false, underline: true, **system_arguments) @system_arguments = system_arguments @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
57 58 59 |
# File 'app/components/primer/link_component.rb', line 57 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
53 54 55 |
# File 'app/components/primer/link_component.rb', line 53 def call render(Primer::BaseComponent.new(**@system_arguments)) { content } end |