ProductCardComponent

InfoGenerateCreated ByPackages

This code defines a Ruby class called `ProductCardComponent` that inherits from `ApplicationComponent`. The purpose of this class is to render a product card component with HTML structure and styles. It takes a `product` object as an argument during initialization and uses its attributes (image_url, name, description, and id) to populate the card. The `template` method builds the HTML structure of the card with a product image, name, description, and a

# 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
          a(href: "/products/#{@product.id}", class: "btn btn-primary") { "View Product" }
        end
      end
    end
  end
end