Class: CCS::Components::GovUK::Logo

Inherits:
Base
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers
Defined in:
lib/ccs/components/govuk/logo.rb

Overview

GOV.UK Logo

This is used to generate the logo component from the GDS - Macros - Logo

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the logo

{}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(rebrand: false, use_logotype: true, use_tudor_crown: true) ⇒ Logo

Returns a new instance of Logo.

Parameters:

  • rebrand (Boolean) (defaults to: false)

    Flag for rebrand

  • use_logotype (Boolean) (defaults to: true)

    Flag for logotyp

  • use_tudor_crown (Boolean) (defaults to: true)

    Flag for tudor crown

  • options (Hash)

    options that will be used in customising the HTML



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ccs/components/govuk/logo.rb', line 36

def initialize(rebrand: false, use_logotype: true, use_tudor_crown: true, **)
  super(**)

  @rebrand = rebrand
  @use_logotype = use_logotype
  @use_tudor_crown = rebrand ? true : use_tudor_crown

  svg_width = @use_tudor_crown ? 32 : 36
  svg_width = rebrand ? svg_width + 130 : svg_width + 116 if @use_logotype

  @options[:attributes][:focusable] = 'false'
  @options[:attributes][:role] = @options[:attributes].dig(:aria, :label) ? 'img' : 'presentation'
  @options[:attributes][:xmlns] = 'http://www.w3.org/2000/svg'
  @options[:attributes][:viewBox] = "0 0 #{svg_width * 2} 60"
  @options[:attributes][:height] = '30'
  @options[:attributes][:width] = svg_width.to_s
  @options[:attributes][:fill] = 'currentcolor'
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Logo component

Returns:

  • (ActiveSupport::SafeBuffer)


59
60
61
62
63
64
65
# File 'lib/ccs/components/govuk/logo.rb', line 59

def render
  tag.svg(**options[:attributes]) do
    concat(tag.title(@options[:attributes].dig(:aria, :label))) if @options[:attributes].dig(:aria, :label)
    concat(use_tudor_crown ? tudor_crown : st_edwards_crown)
    concat(rebrand ? dot_logotype : logotype) if use_logotype
  end
end