Sha256: 2aac7f2fb04491d767fb3e425e7a6c0e355f7d76f96282ae20c494b395f35190

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Blacklight
  class MetadataFieldLayoutComponent < Blacklight::Component
    include Blacklight::ContentAreasShim

    with_collection_parameter :field
    renders_one :label
    renders_many :values, (lambda do |value: nil, &block|
      if @value_tag.nil?
        block&.call || value
      elsif block
        content_tag @value_tag, class: "#{@value_class} blacklight-#{@key}", &block
      else
        content_tag @value_tag, value, class: "#{@value_class} blacklight-#{@key}"
      end
    end)

    # @param field [Blacklight::FieldPresenter]
    def initialize(field:, value_tag: 'dd', label_class: 'col-md-3', value_class: 'col-md-9')
      @field = field
      @key = @field.key.parameterize
      @label_class = label_class
      @value_tag = value_tag
      @value_class = value_class
    end

    def value(*args, **kwargs, &block)
      return set_slot(:values, nil, *args, **kwargs, &block) if block_given?

      Deprecation.warn(Blacklight::MetadataFieldLayoutComponent, 'The `value` content area is deprecated; render from the values slot instead')

      values.first
    end

    def with(slot_name, *args, **kwargs, &block)
      if slot_name == :value
        super(:values, *args, **kwargs, &block)
      else
        super
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
blacklight-7.40.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.39.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.38.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.37.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.36.2 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.36.1 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.36.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.35.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.34.0 app/components/blacklight/metadata_field_layout_component.rb