Module: CCS::FrontendHelpers::GovUKFrontend::Label

Included in:
CCS::FrontendHelpers::GovUKFrontend
Defined in:
lib/ccs/frontend_helpers/govuk_frontend/label.rb

Overview

GOV.UK label

This helper is used for generating the label component from the Government Design Systems

Instance Method Summary collapse

Instance Method Details

#govuk_label(attribute, text = nil, **options) { ... } ⇒ ActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK label component

Parameters:

  • attribute (String, Symbol)

    the attribute of the input that requires a label

  • text (String) (defaults to: nil)

    (nil) the text for the label If nil, then a block will be rendered

  • form (ActionView::Helpers::FormBuilder)

    (nil) optional form builder used to create the label

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the label HTML

  • :is_page_heading (Boolean) — default: false

    if the label is also the heading it will rendered in a h1

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML

Yields:

  • HTML that will be generated for the label

Returns:

  • (ActiveSupport::SafeBuffer)


23
24
25
# File 'lib/ccs/frontend_helpers/govuk_frontend/label.rb', line 23

def govuk_label(attribute, text = nil, **options, &)
  Components::GovUK::Label.new(context: self, attribute: attribute, text: text, **options).render(&)
end