Class: Yattho::Beta::Link
- Defined in:
- app/components/yattho/beta/link.rb
Overview
Use ‘Link` for navigating from one page to another. `Link` styles anchor tags with default blue styling and hover text-decoration.
Direct Known Subclasses
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) ⇒ Link
constructor
A new instance of Link.
Methods inherited from Component
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) ⇒ Link
Returns a new instance of Link.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/components/yattho/beta/link.rb', line 64 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
81 82 83 84 85 86 |
# File 'app/components/yattho/beta/link.rb', line 81 def before_render return unless @system_arguments[:tag] == :a && @system_arguments[:href].nil? && !Rails.env.production? raise ArgumentError, "href is required when using <a> tag" end |
#call ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/components/yattho/beta/link.rb', line 88 def call if tooltip.present? render Yattho::BaseComponent.new(tag: :span, position: :relative) do render(Yattho::BaseComponent.new(**@system_arguments)) do content end.to_s + tooltip.to_s end else render(Yattho::BaseComponent.new(**@system_arguments)) do content end end end |