ProductCardComponent

InfoGenerateCreated ByPackages

This Ruby class, `ProductCardComponent`, inherits from `ApplicationComponent` and is designed to generate a product card, typically for display on a web page. The constructor takes a `product` object as an argument, which it uses to populate various elements of the card, such as the image, name, and description of the product. The card is created using a series of HTML tags and CSS classes for styling. It includes an image of the product, the product name as a title, a description, and a button that redirects the user to the product's URL when clicked.

# 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", onclick: "window.location='#{@product.url}'") { "View Product" }
        end
      end
    end
  end
end