Class: CCS::Components::GovUK::SummaryList::Card

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/summary_list/card.rb,
lib/ccs/components/govuk/summary_list/card/title.rb,
lib/ccs/components/govuk/summary_list/card/actions.rb

Overview

GOV.UK Summary card

This is used for generating the summary cards component from the GDS - Components - Summary cards

Defined Under Namespace

Classes: Actions, Title

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the summary card

{ class: 'govuk-summary-card' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, actions: nil, **options) ⇒ Card

Returns a new instance of Card.

Parameters:

  • title (Hash) (defaults to: nil)

    attributes for the title, see Title#initialize for more details.

  • actions (Hash) (defaults to: nil)

    attributes for the actions, see Actions#initialize for more details.

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the summary card HTML

  • :attributes (Hash)

    any additional attributes that will be added as part of the HTML



33
34
35
36
37
38
# File 'lib/ccs/components/govuk/summary_list/card.rb', line 33

def initialize(title: nil, actions: nil, **options)
  super(**options)

  @title = Title.new(context: @context, **title) if title
  @actions = Actions.new(context: @context, card_title: title&.dig(:text), **actions) if actions
end

Instance Method Details

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

Generates the HTML for the GOV.UK Summary card

Yields:

  • the HTML for the summary list

Returns:

  • (ActiveSupport::SafeBuffer)


46
47
48
49
50
51
52
53
54
# File 'lib/ccs/components/govuk/summary_list/card.rb', line 46

def render(&block)
  tag.div(**@options[:attributes]) do
    concat(tag.div(class: 'govuk-summary-card__title-wrapper') do
      concat(title.render) if title
      concat(actions.render) if actions
    end)
    concat(tag.div(class: 'govuk-summary-card__content', &block))
  end
end