Class: DaisyUI::Card::Figure

Inherits:
BaseComponent show all
Defined in:
app/components/daisy_ui/data_display/card/figure.rb

Overview

Figure component for the card, handling image display

Examples:

Basic usage with URL

<%= render(CardComponent.new) do |component| %>
  <% component.with_figure(img_url: "https://picsum.photos/400/200") %>
<% end %>

Custom image tag

<%= render(CardComponent.new) do |component| %>
  <% component.with_figure do |figure| %>
    <% figure.with_image do %>
      <%= image_tag "custom.jpg", class: "rounded-xl" %>
    <% end %>
  <% end %>
<% end %>

Instance Method Summary collapse

Constructor Details

#initialize(img_url: nil, img_alt: nil, **system_arguments) ⇒ Figure



27
28
29
30
31
# File 'app/components/daisy_ui/data_display/card/figure.rb', line 27

def initialize(img_url: nil, img_alt: nil, **system_arguments)
  @img_url = img_url
  @img_alt = img_alt
  super(**system_arguments)
end

Instance Method Details

#before_renderObject



33
34
35
# File 'app/components/daisy_ui/data_display/card/figure.rb', line 33

def before_render
  with_image { tag.img(src: @img_url, alt: @img_alt) } if @img_url && !image?
end

#callObject



37
38
39
40
41
# File 'app/components/daisy_ui/data_display/card/figure.rb', line 37

def call
  tag.figure(**system_arguments) do
    safe_join([image, content].compact)
  end
end