Class: Ariadne::LinkComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/ariadne/link_component.rb

Overview

Use Link for navigating from one page to another. Link styles anchor tags with default styling and hover text-decoration.

Constant Summary collapse

DEFAULT_TAG =
:a
TAG_OPTIONS =
[DEFAULT_TAG, :span].freeze
DEFAULT_CLASSES =
"ariadne-cursor-pointer"
DEFAULT_ACTIONABLE_CLASSES =
" ariadne-cursor-pointer ariadne-underline ariadne-decoration-double ariadne-font-semibold hover:ariadne-text-button-text-color focus:ariadne-outline-none focus:ariadne-ring-2 focus:ariadne-ring-offset-2 focus:ariadne-ring-purple-500"

Constants inherited from Component

Component::BASE_BODY_CLASSES, Component::BASE_HTML_CLASSES, Component::BASE_MAIN_CLASSES, Component::BASE_WRAPPER_CLASSES, Component::INVALID_ARIA_LABEL_TAGS

Constants included from ActionViewExtensions::FormHelper

ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE

Instance Method Summary collapse

Methods included from ActionViewExtensions::FormHelper

#ariadne_form_with

Methods included from ClassNameHelper

#class_names

Methods included from LoggerHelper

#logger, #silence_deprecations?, #silence_warnings?

Methods included from FetchOrFallbackHelper

#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer

Constructor Details

#initialize(tag: DEFAULT_TAG, href:, actionable: false, classes: "", attributes: {}) ⇒ LinkComponent

Returns a new instance of LinkComponent.

Examples:

Default

<%= render(Ariadne::LinkComponent.new(href: "#")) { "Link" } %>

Span as link

<%= render(Ariadne::LinkComponent.new(tag: :span, href: "#")) { "Span as a link" } %>

With tooltip

@description
  Use tooltips sparingly and as a last resort. Consult the <%= link_to_component(Ariadne::TooltipComponent) %> documentation for more information.
@code
  <%= render(Ariadne::LinkComponent.new(href: "#", attributes: { id: "link-with-tooltip" })) do |c| %>
    <% c.tooltip(text: "Tooltip text") %>
    Link
  <% end %>

Parameters:

  • tag (String) (defaults to: DEFAULT_TAG)

    <%= one_of(Ariadne::LinkComponent::TAG_OPTIONS) %>

  • href (String)

    URL to be used for the link.

  • actionable (Boolean) (defaults to: false)

    If true, adds additional classes to the link to make it more aware.

  • classes (String) (defaults to: "")

    <%= link_to_classes_docs %>

  • attributes (Hash) (defaults to: {})

    <%= link_to_attributes_docs %>



47
48
49
50
51
52
53
54
55
56
57
# File 'app/components/ariadne/link_component.rb', line 47

def initialize(tag: DEFAULT_TAG, href:,  actionable: false, classes: "", attributes: {})
  @tag = check_incoming_tag(DEFAULT_TAG, tag)

  @attributes = attributes
  @attributes[:href] = href

  @id = @attributes[:id]

  @classes = class_names(DEFAULT_CLASSES, classes)
  @classes << DEFAULT_ACTIONABLE_CLASSES if actionable
end

Instance Method Details

#callObject



59
60
61
62
63
# File 'app/components/ariadne/link_component.rb', line 59

def call
  render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) do
    content.to_s + tooltip.to_s
  end
end