Sha256: 7ed96f5e20461cb10afa8a4b79f47a3de5f0ff310de684a6dca74e8ad66e0ebb

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

module GOVUKDesignSystemFormBuilder
  module Elements
    module CheckBoxes
      class CollectionCheckBox < Base
        using PrefixableArray

        include Traits::CollectionItem
        include Traits::Hint

        def initialize(builder, object_name, attribute_name, checkbox, hint_method = nil, link_errors: false)
          super(builder, object_name, attribute_name)

          @checkbox    = checkbox
          @item        = checkbox.object
          @value       = checkbox.value
          @hint_text   = retrieve(@item, hint_method)
          @link_errors = link_errors
        end

        def html
          content_tag('div', class: %(#{brand}-checkboxes__item)) do
            safe_join([check_box, label_element, hint_element])
          end
        end

      private

        def check_box
          @checkbox.check_box(**options)
        end

        def options
          {
            id: field_id(link_errors: @link_errors),
            class: %(#{brand}-checkboxes__input),
            aria: { describedby: hint_id }
          }
        end

        def label_element
          @label_element ||= Label.new(@builder, @object_name, @attribute_name, @checkbox, value: @value, link_errors: @link_errors)
        end

        def hint_element
          @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, @hint_text, @value, checkbox: true)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-1.2.6 lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb
govuk_design_system_formbuilder-1.2.5 lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb