Class: BetterUi::Table::ColumnComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- BetterUi::Table::ColumnComponent
- Defined in:
- app/components/better_ui/table/column_component.rb
Overview
A data-holder component for defining table columns in collection mode.
ColumnComponent stores column configuration (key, label, alignment, formatter) and produces no rendered output. The parent TableComponent reads these configurations to build the table structure.
Constant Summary collapse
- ALIGNMENTS =
%i[left center right].freeze
- SORT_DIRECTIONS =
%i[asc desc].freeze
Constants inherited from ApplicationComponent
ApplicationComponent::SHADOWS, ApplicationComponent::VARIANTS, ApplicationComponent::VARIANT_BODY_DIVIDE, ApplicationComponent::VARIANT_DIVIDE, ApplicationComponent::VARIANT_HEADER_BG, ApplicationComponent::VARIANT_HEADER_TEXT, ApplicationComponent::VARIANT_HIGHLIGHTED, ApplicationComponent::VARIANT_HOVERABLE, ApplicationComponent::VARIANT_RING, ApplicationComponent::VARIANT_SORT_ICON, ApplicationComponent::VARIANT_STRIPED
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#cell_classes ⇒ Object
readonly
Returns the value of attribute cell_classes.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#header_classes ⇒ Object
readonly
Returns the value of attribute header_classes.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#sort_direction ⇒ Object
readonly
Returns the value of attribute sort_direction.
-
#sort_html ⇒ Object
readonly
Returns the value of attribute sort_html.
-
#sort_url ⇒ Object
readonly
Returns the value of attribute sort_url.
-
#sortable ⇒ Object
readonly
Returns the value of attribute sortable.
-
#sorted ⇒ Object
readonly
Returns the value of attribute sorted.
Instance Method Summary collapse
- #call ⇒ Object
- #display_label ⇒ Object
-
#initialize(key: nil, label: nil, align: :left, header_classes: nil, cell_classes: nil, sortable: false, sorted: false, sort_direction: :asc, sort_url: nil, sort_html: {}, &formatter) ⇒ ColumnComponent
constructor
A new instance of ColumnComponent.
- #value_for(item) ⇒ Object
Constructor Details
#initialize(key: nil, label: nil, align: :left, header_classes: nil, cell_classes: nil, sortable: false, sorted: false, sort_direction: :asc, sort_url: nil, sort_html: {}, &formatter) ⇒ ColumnComponent
Returns a new instance of ColumnComponent.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/components/better_ui/table/column_component.rb', line 26 def initialize(key: nil, label: nil, align: :left, header_classes: nil, cell_classes: nil, sortable: false, sorted: false, sort_direction: :asc, sort_url: nil, sort_html: {}, &formatter) @key = key @label = label @align = validate_align(align) @header_classes = header_classes @cell_classes = cell_classes @sortable = sortable @sorted = sorted @sort_direction = validate_sort_direction(sort_direction) @sort_url = sort_url @sort_html = sort_html || {} @formatter = formatter end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def align @align end |
#cell_classes ⇒ Object (readonly)
Returns the value of attribute cell_classes.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def cell_classes @cell_classes end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def formatter @formatter end |
#header_classes ⇒ Object (readonly)
Returns the value of attribute header_classes.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def header_classes @header_classes end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def key @key end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def label @label end |
#sort_direction ⇒ Object (readonly)
Returns the value of attribute sort_direction.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def sort_direction @sort_direction end |
#sort_html ⇒ Object (readonly)
Returns the value of attribute sort_html.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def sort_html @sort_html end |
#sort_url ⇒ Object (readonly)
Returns the value of attribute sort_url.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def sort_url @sort_url end |
#sortable ⇒ Object (readonly)
Returns the value of attribute sortable.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def sortable @sortable end |
#sorted ⇒ Object (readonly)
Returns the value of attribute sorted.
23 24 25 |
# File 'app/components/better_ui/table/column_component.rb', line 23 def sorted @sorted end |
Instance Method Details
#call ⇒ Object
42 43 44 |
# File 'app/components/better_ui/table/column_component.rb', line 42 def call "" end |
#display_label ⇒ Object
46 47 48 |
# File 'app/components/better_ui/table/column_component.rb', line 46 def display_label @label || @key&.to_s&.humanize || "" end |
#value_for(item) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/components/better_ui/table/column_component.rb', line 50 def value_for(item) if @formatter @formatter.call(item) elsif @key item.respond_to?(@key) ? item.public_send(@key) : item[@key] else "" end end |