Class: CCS::Components::GovUK::Details

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/details.rb

Overview

GOV.UK Details

This is used to generate the details component from the GDS - Components - Details

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the details

{ class: 'govuk-details' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(summary_text:, **options) ⇒ Details

Returns a new instance of Details.

Parameters:

  • summary_text (String)

    the summary text for the details element

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the details HTML

  • :attributes (Hash) — default: { data: { module: 'govuk-details' } }

    any additional attributes that will added as part of the HTML



27
28
29
30
31
# File 'lib/ccs/components/govuk/details.rb', line 27

def initialize(summary_text:, **options)
  super(**options)

  @summary_text = summary_text
end

Instance Method Details

#render { ... } ⇒ ActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Details component

Yields:

  • HTML that will be contained within the ‘govuk-details__text’ div

Returns:

  • (ActiveSupport::SafeBuffer)

    the HTML for the GOV.UK Details which can then be rendered on the page



40
41
42
43
44
45
# File 'lib/ccs/components/govuk/details.rb', line 40

def render(&block)
  tag.details(**options[:attributes]) do
    concat(tag.summary(tag.span(summary_text, class: 'govuk-details__summary-text'), class: 'govuk-details__summary'))
    concat(tag.div(class: 'govuk-details__text', &block))
  end
end