Sha256: 13685ca9feab0b49b728fe63bd15f430c0c47d7c5a593bd309951356d6add096

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

module GovukDesignSystem
  module DetailsHelper
    # Generates the HTML for the
    # [Details component](https://design-system.service.gov.uk/components/details/)
    # from the GOV.UK Design System.
    #
    # The method name and parameters are camelCased to follow the convention of
    # the Nunjucks macros from the GOV.UK Design System, to make it easier to
    # copy and paste templates from the Prototyping Kit.
    #
    #
    # Implementation based on https://github.com/alphagov/govuk-frontend/blob/master/src/govuk/components/details/
    #
    def govukDetails(summaryText: nil, summaryHtml: nil, text: nil, html: nil, id: nil, open: nil, classes: "", attributes: {})
      attributes.merge!("class" => class_names("govuk-details", classes), id: id, "data-module" => "govuk-details")
      attributes["open"] = "open" if open

      content_tag("details", attributes) do
        summary = content_tag("summary", class: "govuk-details__summary") do
          content_tag("span", class: "govuk-details__summary-text") do
            summaryHtml || summaryText
          end
        end
        content = content_tag("div", class: "govuk-details__text") do
          html || text || yield
        end

        summary + content
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
govuk-design-system-rails-0.10.3 app/helpers/govuk_design_system/details_helper.rb
govuk-design-system-rails-0.10.2 app/helpers/govuk_design_system/details_helper.rb
govuk-design-system-rails-0.10.1 app/helpers/govuk_design_system/details_helper.rb