Sha256: c898c59bd59bca2bee703e3e86e1d96e1c755399069ecb6543a2a4e657ddb794

Contents?: true

Size: 1.39 KB

Versions: 21

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Primer
  # Use `Image` to render images.
  #
  # @accessibility
  #   Always provide a meaningful `alt`.
  class Image < Primer::Component
    # @example Default
    #
    #   <%= render(Primer::Image.new(src: "https://github.com/github.png", alt: "GitHub")) %>
    #
    # @example Helper
    #
    #   <%= primer_image(src: "https://github.com/github.png", alt: "GitHub") %>
    #
    # @example Lazy loading
    #
    #   <%= render(Primer::Image.new(src: "https://github.com/github.png", alt: "GitHub", lazy: true)) %>
    #
    # @example Custom size
    #
    #   <%= render(Primer::Image.new(src: "https://github.com/github.png", alt: "GitHub", height: 100, width: 100)) %>
    #
    # @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 = system_arguments

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

      return unless lazy

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

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
primer_view_components-0.0.61 app/components/primer/image.rb
primer_view_components-0.0.60 app/components/primer/image.rb
primer_view_components-0.0.59 app/components/primer/image.rb
primer_view_components-0.0.58 app/components/primer/image.rb
primer_view_components-0.0.57 app/components/primer/image.rb
primer_view_components-0.0.56 app/components/primer/image.rb
primer_view_components-0.0.55 app/components/primer/image.rb
primer_view_components-0.0.54 app/components/primer/image.rb
primer_view_components-0.0.53 app/components/primer/image.rb
primer_view_components-0.0.52 app/components/primer/image.rb
primer_view_components-0.0.51 app/components/primer/image.rb
primer_view_components-0.0.50 app/components/primer/image.rb
primer_view_components-0.0.49 app/components/primer/image.rb
primer_view_components-0.0.48 app/components/primer/image.rb
primer_view_components-0.0.47 app/components/primer/image.rb
primer_view_components-0.0.46 app/components/primer/image.rb
primer_view_components-0.0.45 app/components/primer/image.rb
primer_view_components-0.0.44 app/components/primer/image.rb
primer_view_components-0.0.43 app/components/primer/image.rb
primer_view_components-0.0.42 app/components/primer/image.rb