Sha256: 284fc14d27a54e7f130af95322667407ed18989b69cf047bfb280661e0a5f49d

Contents?: true

Size: 1.17 KB

Versions: 15

Compression:

Stored size: 1.17 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 block
        content_tag :dd, class: "#{@value_class} blacklight-#{@key}", &block
      else
        content_tag :dd, value, class: "#{@value_class} blacklight-#{@key}"
      end
    end)

    # @param field [Blacklight::FieldPresenter]
    def initialize(field:, label_class: 'col-md-3', value_class: 'col-md-9')
      @field = field
      @key = @field.key.parameterize
      @label_class = label_class
      @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

15 entries across 15 versions & 1 rubygems

Version Path
blacklight-7.33.1 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.33.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.32.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.31.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.30.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.29.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.28.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.27.1 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.27.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.26.1 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.26.0 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.25.3 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.25.2 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.25.1 app/components/blacklight/metadata_field_layout_component.rb
blacklight-7.25.0 app/components/blacklight/metadata_field_layout_component.rb