Sha256: 6d3aa1007eeba6ce9bcb0cfc32fee99992048e77d38b4e079a0d5f22a5987c92

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Yattho
  module Alpha
    # A client-side mechanism to crop images.
    class ImageCrop < Yattho::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

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

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

2 entries across 2 versions & 1 rubygems

Version Path
yattho_view_components-0.1.1 app/components/yattho/alpha/image_crop.rb
yattho_view_components-0.0.1 app/components/yattho/alpha/image_crop.rb