Sha256: 897886b6ef3c60ace79317a9092fe39875126205af317410302f086613b0a149

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module GOVUKDesignSystemFormBuilder
  module Elements
    class Hint < Base
      using PrefixableArray

      include Traits::Hint
      include Traits::Localisation

      def initialize(builder, object_name, attribute_name, text, value = nil, radio: false, checkbox: false)
        super(builder, object_name, attribute_name)

        @value          = value
        @hint_text      = hint_text(text)
        @radio_class    = radio_class(radio)
        @checkbox_class = checkbox_class(checkbox)
      end

      def html
        return nil if @hint_text.blank?

        tag.span(@hint_text, class: hint_classes, id: hint_id)
      end

    private

      def hint_text(supplied)
        [
          supplied.presence,
          localised_text(:hint)
        ].compact.first
      end

      def hint_classes
        %w(hint).prefix(brand).push(@radio_class, @checkbox_class).compact
      end

      def radio_class(radio)
        radio ? %(#{brand}-radios__hint) : nil
      end

      def checkbox_class(checkbox)
        checkbox ? %(#{brand}-checkboxes__hint) : nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-1.2.0 lib/govuk_design_system_formbuilder/elements/hint.rb
govuk_design_system_formbuilder-1.2.0b4 lib/govuk_design_system_formbuilder/elements/hint.rb
govuk_design_system_formbuilder-1.2.0b2 lib/govuk_design_system_formbuilder/elements/hint.rb
govuk_design_system_formbuilder-1.2.0b1 lib/govuk_design_system_formbuilder/elements/hint.rb