Sha256: 757b6e8426d45a97d7d24c9f5ac8e3e0142ce329591ef9a8a062564b037b6ec8

Contents?: true

Size: 893 Bytes

Versions: 7

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

module PandaCms
  module Admin
    class TableComponent < ViewComponent::Base
      attr_reader :columns

      def initialize(term:, rows:)
        @term = term
        @rows = rows
        @columns = []
      end

      def column(label, &)
        @columns << Column.new(label, &)
      end

      private

      # Ensures @columns gets populated [https://dev.to/rolandstuder/supercharged-table-component-built-with-viewcomponent-3j6i]
      def before_render
        content
      end
    end

    class Column
      attr_reader :label, :cell

      def initialize(label, &block)
        @label = label
        @cell = block
      end
    end

    class TagColumn < Column
      attr_reader :label, :cell

      def initialize(label, &block)
        @label = label
        @cell = PandaCms::Admin::TagComponent.new(status: block)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
panda_cms-0.6.3 app/components/panda_cms/admin/table_component.rb
panda_cms-0.6.2 app/components/panda_cms/admin/table_component.rb
panda_cms-0.6.1 app/components/panda_cms/admin/table_component.rb
panda_cms-0.6.0 app/components/panda_cms/admin/table_component.rb
panda_cms-0.5.10 app/components/panda_cms/admin/table_component.rb
panda_cms-0.5.9 app/components/panda_cms/admin/table_component.rb
panda_cms-0.5.8 app/components/panda_cms/admin/table_component.rb