Class: Pulse::Table::Cell
- Defined in:
- app/components/pulse/table/cell.rb
Overview
Renders a table cell
Constant Summary collapse
- HEAD_DEFAULT_SCHEME =
:xs- HEAD_SCHEME_MAPPINGS =
{ sm: 'pulse-px-3 pulse-py-4 print:pulse-px-2 print:pulse-py-3 ' \ 'pulse-text-sm print:pulse-text-xs pulse-font-base', xs: 'pulse-px-2 pulse-py-4 print:pulse-py-2 pulse-text-xs ' \ 'print:pulse-text-2xs pulse-font-medium' }.freeze
- HEAD_SCHEME_OPTIONS =
HEAD_SCHEME_MAPPINGS.keys.freeze
- DEFAULT_CELL_CLASSES =
'pulse-text-start first:pulse-ps-4 ' \ 'last:pulse-pe-4 pulse-px-2 pulse-text-gray ' \ 'print:first:pulse-ps-2 print:last:pulse-pe-2'
- DEFAULT_TH_CLASSES =
'pulse-uppercase pulse-tracking-wider'- DEFAULT_TD_CLASSES =
'pulse-py-2 pulse-whitespace-nowrap ' \ 'pulse-text-sm print:pulse-text-xs pulse-text-gray'
Constants inherited from Component
Constants included from AttributesHelper
AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#additional_params ⇒ Object
readonly
Returns the value of attribute additional_params.
-
#current_sort_column ⇒ Object
readonly
Returns the value of attribute current_sort_column.
-
#current_sort_direction ⇒ Object
readonly
Returns the value of attribute current_sort_direction.
-
#footer ⇒ Object
readonly
Returns the value of attribute footer.
-
#sort_by ⇒ Object
readonly
Returns the value of attribute sort_by.
Instance Method Summary collapse
- #active ⇒ Object
- #dir ⇒ Object
- #direction ⇒ Object
- #header_or_footer? ⇒ Boolean
- #icon ⇒ Object
-
#initialize(sort_by: nil, current_sort_column: nil, current_sort_direction: nil, additional_params: {}, head_scheme: HEAD_DEFAULT_SCHEME, footer: nil, title_classes: '', **options) ⇒ Cell
constructor
A new instance of Cell.
- #options ⇒ Object
- #sort_dir ⇒ Object
- #sortable? ⇒ Boolean
- #title_classes ⇒ Object
- #url_options ⇒ Object
Methods inherited from Component
generate_id, #merge_attributes, #merge_classes
Methods included from SvgHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean
Methods included from AttributesHelper
#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Constructor Details
#initialize(sort_by: nil, current_sort_column: nil, current_sort_direction: nil, additional_params: {}, head_scheme: HEAD_DEFAULT_SCHEME, footer: nil, title_classes: '', **options) ⇒ Cell
Returns a new instance of Cell.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/components/pulse/table/cell.rb', line 26 def initialize(sort_by: nil, current_sort_column: nil, current_sort_direction: nil, additional_params: {}, head_scheme: HEAD_DEFAULT_SCHEME, footer: nil, title_classes: '', **) @sort_by = sort_by @current_sort_column = current_sort_column @current_sort_direction = current_sort_direction @additional_params = additional_params @footer = @title_classes = title_classes @options = @options[:classes] = merge_classes( DEFAULT_CELL_CLASSES, ? DEFAULT_TH_CLASSES : DEFAULT_TD_CLASSES, ? HEAD_SCHEME_MAPPINGS[head_scheme] : '', [:classes] ) end |
Instance Attribute Details
#additional_params ⇒ Object (readonly)
Returns the value of attribute additional_params.
7 8 9 |
# File 'app/components/pulse/table/cell.rb', line 7 def additional_params @additional_params end |
#current_sort_column ⇒ Object (readonly)
Returns the value of attribute current_sort_column.
7 8 9 |
# File 'app/components/pulse/table/cell.rb', line 7 def current_sort_column @current_sort_column end |
#current_sort_direction ⇒ Object (readonly)
Returns the value of attribute current_sort_direction.
7 8 9 |
# File 'app/components/pulse/table/cell.rb', line 7 def current_sort_direction @current_sort_direction end |
#footer ⇒ Object (readonly)
Returns the value of attribute footer.
7 8 9 |
# File 'app/components/pulse/table/cell.rb', line 7 def @footer end |
#sort_by ⇒ Object (readonly)
Returns the value of attribute sort_by.
7 8 9 |
# File 'app/components/pulse/table/cell.rb', line 7 def sort_by @sort_by end |
Instance Method Details
#active ⇒ Object
57 58 59 |
# File 'app/components/pulse/table/cell.rb', line 57 def active sort_by && sort_by == current_sort_column end |
#dir ⇒ Object
65 66 67 |
# File 'app/components/pulse/table/cell.rb', line 65 def dir current_sort_direction end |
#direction ⇒ Object
81 82 83 |
# File 'app/components/pulse/table/cell.rb', line 81 def direction params[:sort].nil? || params[:sort] == sort_by ? sort_dir : nil end |
#header_or_footer? ⇒ Boolean
73 74 75 |
# File 'app/components/pulse/table/cell.rb', line 73 def @options[:tag] == 'th' || @footer end |
#icon ⇒ Object
69 70 71 |
# File 'app/components/pulse/table/cell.rb', line 69 def icon active ? "sort_#{dir}" : 'sort' end |
#options ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/components/pulse/table/cell.rb', line 45 def { tag: 'td' }.deep_merge(@options).tap do |args| args[:classes] = class_names( args[:classes] ) end end |
#sort_dir ⇒ Object
85 86 87 |
# File 'app/components/pulse/table/cell.rb', line 85 def sort_dir params[:direction] == 'asc' ? 'desc' : 'asc' end |
#sortable? ⇒ Boolean
61 62 63 |
# File 'app/components/pulse/table/cell.rb', line 61 def sortable? sort_by && params[:q].blank? end |
#title_classes ⇒ Object
53 54 55 |
# File 'app/components/pulse/table/cell.rb', line 53 def title_classes ? @title_classes : '' end |
#url_options ⇒ Object
77 78 79 |
# File 'app/components/pulse/table/cell.rb', line 77 def { sort: sort_by, direction: }.merge(additional_params) end |