EnhancedHtmlTableComponent

InfoGeneratePackages

The provided code defines a Ruby class named `TableComponent`, which inherits from `ApplicationComponent`. This class is designed to generate an HTML table within a `div` container that has a horizontal overflow. The table is supposed to render a header with four columns: a non-labelled one, 'Name', 'Job', and 'Favorite Color'. In the body of the table, there are three rows with the following contents: 1) An index number, 'Cy Ganderton', 'Quality Control Specialist', and 'Blue'; 2) An index number, 'Hart Hagerty', 'Desktop Support Technician', and 'Purple', with this row having a 'hover' class that likely adds a visual effect when the row is hovered over; 3) An index number, 'Brice Swyre', 'Tax Accountant', and 'Red'. The class has comment-based documentation at the top, indicating that the table can be modified with various classes ('table-zebra', 'table-pin-rows', 'table-pin-cols', different sizes, and 'hover' for tr elements) to apply different visual styles or functionalities, although the implementation of these styles is not directly shown in the provided code snippet.

# frozen_string_literal: true

# Table component options:
# tables can be modified by:
# table-zebra: adds zebra striping to the table
# table-pin-rows: make all rows sticky
# table-pin-cols: make all columns sticky
# size: table-xs, table-sm, table-md, table-lg
# trs can be modified with: "hover" to add hover effect
class TableComponent < ApplicationComponent
  def template
    div(class: "overflow-x-auto") do
      table(class: "table") do
        thead do
          tr do
            th
            th { "Name" }
            th { "Job" }
            th { "Favorite Color" }
          end
        end
        tbody do
          tr do
            th { "1" }
            td { "Cy Ganderton" }
            td { "Quality Control Specialist" }
            td { "Blue" }
          end
          tr(class: "hover") do
            th { "2" }
            td { "Hart Hagerty" }
            td { "Desktop Support Technician" }
            td { "Purple" }
          end
          tr do
            th { "3" }
            td { "Brice Swyre" }
            td { "Tax Accountant" }
            td { "Red" }
          end
        end
      end
    end
  end
end