# typed: false # frozen_string_literal: true module Ariadne module UI module Image # @example Default # # <%= render(Ariadne::ImageComponent.new(src: "https://github.com/github.png", alt: "GitHub")) %> # # @example Helper # # <%= ariadne_image(src: "https://github.com/github.png", alt: "GitHub") %> # # @example Lazy loading # # <%= render(Ariadne::ImageComponent.new(src: "https://github.com/github.png", alt: "GitHub", lazy: true)) %> # # @example Custom size # # <%= render(Ariadne::ImageComponent.new(src: "https://github.com/github.png", alt: "GitHub", attributes: { height: 100, width: 100 })) %> # # @param tag [Symbol, String] The rendered tag name # @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 classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] <%= link_to_attributes_docs %> class Component < Ariadne::BaseComponent option :src option :alt option :size, default: -> { :original } option :lazy, default: -> { false } accepts_html_attributes do |html_attrs| html_attrs[:class] = Ariadne::ViewComponents.tailwind_merger.merge([style(size: @size), html_attrs[:class]].join(" ")) html_attrs[:src] = @src html_attrs[:alt] = @alt next unless @lazy html_attrs[:loading] = :lazy html_attrs[:decoding] = :async end style do base do ["ariadne-object-cover", "ariadne-object-center"] end variants do size do xs { "ariadne-w-4" } sm { "ariadne-w-6" } md { "ariadne-w-8" } lg { "ariadne-w-12" } xl { "ariadne-w-16" } end end end erb_template <<~ERB /> ERB end end end end