Class: GovukComponent::TagComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/tag_component.rb

Constant Summary collapse

COLOURS =
%w(grey green turquoise blue red purple pink orange yellow).freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Attributes included from GovukComponent::Traits::CustomHtmlAttributes

#html_attributes

Instance Method Summary collapse

Methods included from GovukComponent::Traits::CustomClasses

#classes

Methods included from Govuk::Components::Helpers::CssUtilities

#combine_classes

Constructor Details

#initialize(text: nil, colour: nil, classes: [], html_attributes: {}) ⇒ TagComponent

Returns a new instance of TagComponent.



6
7
8
9
10
11
# File 'app/components/govuk_component/tag_component.rb', line 6

def initialize(text: nil, colour: nil, classes: [], html_attributes: {})
  super(classes: classes, html_attributes: html_attributes)

  @text   = text
  @colour = colour
end

Instance Attribute Details

#colourObject (readonly)

Returns the value of attribute colour.



2
3
4
# File 'app/components/govuk_component/tag_component.rb', line 2

def colour
  @colour
end

#textObject (readonly)

Returns the value of attribute text.



2
3
4
# File 'app/components/govuk_component/tag_component.rb', line 2

def text
  @text
end

Instance Method Details

#callObject



13
14
15
# File 'app/components/govuk_component/tag_component.rb', line 13

def call
  tag.strong(tag_content, class: classes.append(colour_class), **html_attributes)
end