Sha256: ddb2c5c03a9c5eb000bec9e138b019dc4a20a51f3787ac6d913fb7bf8f14149e

Contents?: true

Size: 993 Bytes

Versions: 23

Compression:

Stored size: 993 Bytes

Contents

module GOVUKDesignSystemFormBuilder
  module Elements
    class Caption < Base
      include Traits::Localisation
      include Traits::HTMLAttributes
      include Traits::HTMLClasses

      def initialize(builder, object_name, attribute_name, text: nil, size: config.default_caption_size, **kwargs)
        super(builder, object_name, attribute_name)

        @text            = text(text)
        @size_class      = size_class(size)
        @html_attributes = kwargs
      end

      def html
        return unless active?

        tag.span(@text, **attributes(@html_attributes))
      end

    private

      def options
        { class: @size_class }
      end

      def active?
        @text.present?
      end

      def text(override)
        override || localised_text(:caption)
      end

      def size_class(size)
        fail ArgumentError, "invalid size '#{size}', must be xl, l or m" unless size.in?(%w(xl l m))

        %(#{brand}-caption-#{size})
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
govuk_design_system_formbuilder-5.8.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.7.1 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.7.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.6.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.5.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.4.1 lib/govuk_design_system_formbuilder/elements/caption.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/govuk_design_system_formbuilder-5.4.0/lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.3.3 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.3.2 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.3.1 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.3.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.2.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.1.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.1.0b1 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.0.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-5.0.0b1 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-4.1.1 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-4.1.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-4.0.0 lib/govuk_design_system_formbuilder/elements/caption.rb
govuk_design_system_formbuilder-4.0.0rc1 lib/govuk_design_system_formbuilder/elements/caption.rb