Sha256: bfdc50979d84780f77f76fbcd552d6300df0209ff7edd2ed630c98ed20639e59

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbAdvancedTable
    class TableRow < Playbook::KitBase
      prop :id, type: Playbook::Props::String,
                default: ""
      prop :column_definitions, type: Playbook::Props::Array,
                                default: []
      prop :row
      prop :depth

      def classname
        generate_classname("pb_table_tr", "bg-white", subrow_depth_classname, separator: " ")
      end

      def td_classname
        generate_classname("id-cell", "chrome-styles", separator: " ")
      end

      def depth_accessors
        column_definitions.flat_map do |column|
          column[:cellAccessors] if column.key?(:cellAccessors)
        end.compact
      end

    private

      def custom_renderer_value(column, index)
        if index.zero?
          if depth.zero?
            row[column[:accessor].to_sym]
          else
            depth_accessors.each_with_index do |item, accessor_index|
              key = item.to_sym
              return row[key] if depth - 1 == accessor_index
            end
          end
        else
          row[column[:accessor].to_sym]
        end
      end

      def subrow_depth_classname
        depth.positive? ? "depth-sub-row-#{depth}" : ""
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
playbook_ui-14.9.0 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.18 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.17 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.16 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.15 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.14 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.13 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.12 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.11 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.9.0.pre.rc.10 app/pb_kits/playbook/pb_advanced_table/table_row.rb