Class: Primer::LinkComponent

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

Overview

Use links for moving from one page to another. The Link component styles anchor tags with default blue styling and hover text-decoration.

Constant Summary

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(href:, muted: false, **kwargs) ⇒ LinkComponent

Returns a new instance of LinkComponent.

Examples:

40|Default

<%= render(Primer::LinkComponent.new(href: "http://www.google.com")) { "Link" } %>

40|Muted

<%= render(Primer::LinkComponent.new(href: "http://www.google.com", muted: true)) { "Link" } %>


15
16
17
18
19
20
21
22
23
# File 'app/components/primer/link_component.rb', line 15

def initialize(href:, muted: false, **kwargs)
  @kwargs = kwargs
  @kwargs[:tag] = :a
  @kwargs[:href] = href
  @kwargs[:classes] = class_names(
    @kwargs[:classes],
    "muted-link" => fetch_or_fallback([true, false], muted, false)
  )
end

Instance Method Details

#callObject



25
26
27
# File 'app/components/primer/link_component.rb', line 25

def call
  render(Primer::BaseComponent.new(**@kwargs)) { content }
end