Sha256: 35dcc200c0249b0a2e57f686df19129847f264838dd26e65052a8331eff657ee

Contents?: true

Size: 1.5 KB

Versions: 28

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Primer
  # A client-side mechanism to crop images.
  class ImageCrop < Primer::Component
    # A loading indicator that is shown while the image is loading.
    # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
    renders_one :loading, lambda { |**system_arguments|
      deny_tag_argument(**system_arguments)
      system_arguments[:tag] = :div
      system_arguments[:"data-loading-slot"] = true

      Primer::BaseComponent.new(**system_arguments)
    }

    # @example Simple cropper
    #   <%= render(Primer::ImageCrop.new(src: "https://github.com/koddsson.png")) %>
    #
    # @example Square cropper
    #   <%= render(Primer::ImageCrop.new(src: "https://github.com/koddsson.png", rounded: false)) %>
    #
    # @example Cropper with a custom loader
    #   <%= render(Primer::ImageCrop.new(src: "https://github.com/koddsson.png", rounded: false)) do |cropper| %>
    #     <% cropper.loading(style: "width: 120px").with_content("Loading...") %>
    #   <% end %>
    #
    # @param src [String] The path of the image to crop.
    # @param rounded [Boolean] If the crop mask should be a circle. Defaults to true.
    # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
    def initialize(src:, rounded: true, **system_arguments)
      @system_arguments = deny_tag_argument(**system_arguments)
      @system_arguments[:tag] = "image-crop"
      @system_arguments[:src] = src
      @system_arguments[:rounded] = true if rounded
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
primer_view_components-0.0.89 app/components/primer/image_crop.rb
primer_view_components-0.0.88 app/components/primer/image_crop.rb
primer_view_components-0.0.87 app/components/primer/image_crop.rb
primer_view_components-0.0.86 app/components/primer/image_crop.rb
primer_view_components-0.0.85 app/components/primer/image_crop.rb
primer_view_components-0.0.84 app/components/primer/image_crop.rb
primer_view_components-0.0.83 app/components/primer/image_crop.rb
primer_view_components-0.0.82 app/components/primer/image_crop.rb
primer_view_components-0.0.81 app/components/primer/image_crop.rb
primer_view_components-0.0.80 app/components/primer/image_crop.rb
primer_view_components-0.0.79 app/components/primer/image_crop.rb
primer_view_components-0.0.78 app/components/primer/image_crop.rb
primer_view_components-0.0.77 app/components/primer/image_crop.rb
primer_view_components-0.0.76 app/components/primer/image_crop.rb
primer_view_components-0.0.75 app/components/primer/image_crop.rb
primer_view_components-0.0.74 app/components/primer/image_crop.rb
primer_view_components-0.0.73 app/components/primer/image_crop.rb
primer_view_components-0.0.72 app/components/primer/image_crop.rb
primer_view_components-0.0.71 app/components/primer/image_crop.rb
primer_view_components-0.0.70 app/components/primer/image_crop.rb