Class: DesignSystem::Generic::LinkComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/design_system/generic/link_component.rb

Overview

Link (or button-styled link) rendered by ds_link_to. Mirrors the polymorphic Rails link_to signature: with a block the first argument is the URL, otherwise it is the link text. A :type option selects a button style (defined per brand). The link_context switches the default link class (e.g. inside a notification banner).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CssHelper

#css_class_options_merge

Methods included from BrandDerivable

#brand

Constructor Details

#initialize(name = nil, options = nil, html_options = nil, link_context: nil) ⇒ LinkComponent

Returns a new instance of LinkComponent.



9
10
11
12
13
14
15
# File 'app/components/design_system/generic/link_component.rb', line 9

def initialize(name = nil, options = nil, html_options = nil, link_context: nil)
  super()
  @name = name
  @options = options || {}
  @html_options = html_options || {}
  @link_context = link_context
end

Instance Attribute Details

#html_optionsObject (readonly)

Returns the value of attribute html_options.



17
18
19
# File 'app/components/design_system/generic/link_component.rb', line 17

def html_options
  @html_options
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'app/components/design_system/generic/link_component.rb', line 17

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'app/components/design_system/generic/link_component.rb', line 17

def options
  @options
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/design_system/generic/link_component.rb', line 19

def call
  if content.present?
    type = options.delete(:type)
    options[:class] = prep_link_classes(type)
    link_to(name, options, html_options) { content }
  else
    type = html_options.delete(:type)
    html_options[:class] = prep_link_classes(type)
    link_to(name, options, html_options)
  end
end