ProductCardUIComponent

InfoGenerateCreated ByPackages

The given code defines a `ProductCardComponent` class that inherits from `ApplicationComponent` in Ruby, specifically in the context of a web application using a framework like Rails. The purpose of this class is to render a product card UI component that displays product information. The class is initialized with a `product` object, and its `template` method constructs an HTML card layout using nested div, figure, img, h2, p, and button elements. The card displays the product's image, name, description, and includes a 'Buy Now' button. The card's styling and layout are defined using CSS classes like `card`, `card-compact`, `w-96`, `bg-base-100`, `shadow-xl`, and others from a utility-first CSS framework (likely Tailwind CSS).

# frozen_string_literal: true

class ProductCardComponent < ApplicationComponent
  def initialize(product)
    @product = product
  end

  def template
    div(class: "card card-compact w-96 bg-base-100 shadow-xl") do
      figure { img(src: @product.image_url, alt: @product.name) }
      div(class: "card-body") do
        h2(class: "card-title") { @product.name }
        p { @product.description }
        div(class: "card-actions justify-end") do
          button(class: "btn btn-primary") { "Buy Now" }
        end
      end
    end
  end
end