Sha256: 421a2ec9e879ade9b3467f10ffcf746f30058877d5878b6fd83e198fe32c85bb

Contents?: true

Size: 1.6 KB

Versions: 37

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Primer
  module Alpha
    # 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::Alpha::ImageCrop.new(src: Primer::ExampleImage::BASE64_SRC)) %>
      #
      # @example Square cropper
      #   <%= render(Primer::Alpha::ImageCrop.new(src: Primer::ExampleImage::BASE64_SRC, rounded: false)) %>
      #
      # @example Cropper with a custom loader
      #   <%= render(Primer::Alpha::ImageCrop.new(src: Primer::ExampleImage::BASE64_SRC, rounded: false)) do |cropper| %>
      #     <% cropper.with_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
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.6.3 app/components/primer/alpha/image_crop.rb
primer_view_components-0.6.0 app/components/primer/alpha/image_crop.rb
primer_view_components-0.5.1 app/components/primer/alpha/image_crop.rb
primer_view_components-0.5.0 app/components/primer/alpha/image_crop.rb
primer_view_components-0.4.0 app/components/primer/alpha/image_crop.rb
primer_view_components-0.3.1 app/components/primer/alpha/image_crop.rb
primer_view_components-0.3.0 app/components/primer/alpha/image_crop.rb
primer_view_components-0.2.0 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.9 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.8 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.7 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.6 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.5 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.4 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.3 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.2 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.1 app/components/primer/alpha/image_crop.rb
primer_view_components-0.1.0 app/components/primer/alpha/image_crop.rb
primer_view_components-0.0.123 app/components/primer/alpha/image_crop.rb
primer_view_components-0.0.122 app/components/primer/alpha/image_crop.rb