Class: GovukComponent::PanelComponent::Action

Inherits:
Base
  • Object
show all
Includes:
GovukLinkHelper, GovukVisuallyHiddenHelper
Defined in:
app/components/govuk_component/panel_component.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods included from GovukVisuallyHiddenHelper

#govuk_visually_hidden

Methods included from GovukLinkHelper

#govuk_breadcrumb_link_to, #govuk_button_classes, #govuk_button_link_to, #govuk_button_to, #govuk_footer_link_to, #govuk_link_classes, #govuk_link_to, #govuk_mail_to

Methods inherited from Base

#brand, #class_prefix

Constructor Details

#initialize(text:, href:, type: :button, classes: [], html_attributes: {}) ⇒ Action

Returns a new instance of Action.



73
74
75
76
77
78
79
# File 'app/components/govuk_component/panel_component.rb', line 73

def initialize(text:, href:, type: :button, classes: [], html_attributes: {})
  @text = text
  @href = href
  @type = type

  super(classes:, html_attributes:)
end

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href.



71
72
73
# File 'app/components/govuk_component/panel_component.rb', line 71

def href
  @href
end

#textObject (readonly)

Returns the value of attribute text.



71
72
73
# File 'app/components/govuk_component/panel_component.rb', line 71

def text
  @text
end

#typeObject (readonly)

Returns the value of attribute type.



71
72
73
# File 'app/components/govuk_component/panel_component.rb', line 71

def type
  @type
end

Instance Method Details

#callObject



85
86
87
88
89
90
91
# File 'app/components/govuk_component/panel_component.rb', line 85

def call
  case type.to_sym
  when :button then govuk_button_link_to(text, href, inverse: true, **html_attributes)
  when :link then govuk_link_to(text, href, inverse: true, **html_attributes)
  else fail ArgumentError, "unrecognised type (must be :link or :button)"
  end
end

#default_attributesObject



81
82
83
# File 'app/components/govuk_component/panel_component.rb', line 81

def default_attributes
  {}
end