Sha256: eb3dcf39eee5e5d0e2d87aeb1e3d24b870f03f51a502d4aae2b00c3bb4236c6a

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 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
      prop :collapsible_trail, type: Playbook::Props::Boolean,
                               default: true
      prop :table_data_attributes, type: Playbook::Props::HashProp,
                                   default: {}

      def data
        Hash(prop(:data)).merge(table_data_attributes)
      end

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

      def td_classname(column)
        classes = %w[id-cell chrome-styles]
        classes << "last-cell" if column[:is_last_in_group]
        classes.join(" ")
      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)
        return nil unless column[:accessor].present?

        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
            nil
          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

17 entries across 17 versions & 1 rubygems

Version Path
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5341 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5340 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5339 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.12.0.pre.rc.3 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.12.0.pre.rc.2 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.12.0.pre.rc.1 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.12.0.pre.rc.0 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.10.0.pre.alpha.PLAY1774timelinelabelstepspacing5315 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.10.0.pre.alpha.PLAY1774timelinelabelstepspacing5314 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.10.0.pre.alpha.PLAY1750pbcontenttagkitbutton5308 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.11.1 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.11.0.pre.rc.17 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.11.0 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.11.0.pre.rc.16 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.10.0.pre.alpha.play16825301 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.11.0.pre.rc.15 app/pb_kits/playbook/pb_advanced_table/table_row.rb
playbook_ui-14.11.0.pre.rc.14 app/pb_kits/playbook/pb_advanced_table/table_row.rb