Sha256: eaccdbd1a11f29291ba0677a20bf4c94812a4262beffe17397342e8a89c40c8e

Contents?: true

Size: 986 Bytes

Versions: 120

Compression:

Stored size: 986 Bytes

Contents

# frozen_string_literal: true

module Primer
  module Alpha
    # Use `Image` to render images.
    #
    # @accessibility
    #   Always provide a meaningful `alt`.
    class Image < Primer::Component
      status :alpha

      # @param src [String] The source url of the image.
      # @param alt [String] Specifies an alternate text for the image.
      # @param lazy [Boolean] Whether or not to lazily load the image.
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(src:, alt:, lazy: false, **system_arguments)
        @system_arguments = deny_tag_argument(**system_arguments)

        @src = src
        @system_arguments[:tag] = :img
        @system_arguments[:alt] = alt

        return unless lazy

        @system_arguments[:loading] = :lazy
        @system_arguments[:decoding] = :async
      end

      def call
        render(Primer::BaseComponent.new(src: image_path(@src), **@system_arguments))
      end
    end
  end
end

Version data entries

120 entries across 120 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.15.0 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.14.0 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.13.1 app/components/primer/alpha/image.rb
primer_view_components-0.13.2 app/components/primer/alpha/image.rb
primer_view_components-0.13.1 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.13.0 app/components/primer/alpha/image.rb
primer_view_components-0.13.0 app/components/primer/alpha/image.rb
primer_view_components-0.12.0 app/components/primer/alpha/image.rb
primer_view_components-0.11.0 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.12.1 app/components/primer/alpha/image.rb
primer_view_components-0.10.0 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.11.0 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.10.0 app/components/primer/alpha/image.rb
primer_view_components-0.9.0 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.9.1 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.9.0 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.8.0 app/components/primer/alpha/image.rb
primer_view_components-0.8.0 app/components/primer/alpha/image.rb
primer_view_components-0.7.0 app/components/primer/alpha/image.rb
openproject-primer_view_components-0.7.0 app/components/primer/alpha/image.rb