Class: Pulse::Link

Inherits:
Component
  • Object
show all
Defined in:
app/components/pulse/link.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_SCHEME =
:tertiary
SCHEME_MAPPINGS =
{
  primary: 'pulse-text-primary hover:pulse-text-primary',
  secondary: 'pulse-text-secondary hover:pulse-text-secondary',
  tertiary: 'pulse-text-tertiary hover:pulse-text-tertiary',
  reversed: 'pulse-text-gray-300 hover:pulse-text-gray-300 ' \
            'focus:pulse-text-gray-300'
}.freeze
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys.freeze

Instance Method Summary collapse

Constructor Details

#initialize(href: nil, scheme: DEFAULT_SCHEME, bold: false, underline: true, condition: true, **options) ⇒ Link

Returns a new instance of Link.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/pulse/link.rb', line 24

def initialize(href: nil, scheme: DEFAULT_SCHEME, bold: false,
               underline: true, condition: true, **options)
  @condition = condition
  @options = options
  @options[:tag] = condition ? :a : :span
  @options[:href] = href if condition
  @options[:classes] = merge_classes(
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme,
                                      DEFAULT_SCHEME)],
    @options[:classes],
    'pulse-font-bold': bold,
    'pulse-underline hover:pulse-no-underline': condition && underline
  )
end

Instance Method Details

#before_renderObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/pulse/link.rb', line 39

def before_render
  if @options[:href].nil? && @condition && !Rails.env.production?
    raise ArgumentError, 'href is required'
  end

  return unless leading_visual

  @options[:classes] = class_names(
    @options[:classes],
    'pulse-flex pulse-items-center pulse-gap-1.5'
  )
end