Class: TableCellComponent
- Defined in:
- app/components/table_cell_component.rb
Overview
TableCell — a table cell (td or th).
Usage:
TableRow {
TableCell { text "Data" }
TableCell(aligned: "right", collapsing: true) { text "10 hours ago" }
TableCell(heading: true, colspan: 3) { text "Section" }
}
Constant Summary collapse
- NUMBERS =
%w[one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen].freeze
Constants inherited from Component
Instance Method Summary collapse
Methods inherited from Component
default, #initialize, #render_in, slot
Constructor Details
This class inherits a constructor from Component
Instance Method Details
#to_s ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/components/table_cell_component.rb', line 31 def to_s width_word = width && width.between?(1, 16) ? NUMBERS[width - 1] : nil classes = [ (aligned && "#{aligned} aligned"), ("collapsing" if collapsing), ("single line" if single_line), ("positive" if positive), ("negative" if negative), ("warning" if warning), ("error" if error), ("active" if active), ("disabled" if disabled), ("selectable" if selectable), color, (width_word && "#{width_word} wide") ].compact opts = {} opts[:class] = classes.join(" ") if classes.any? opts[:colspan] = colspan if colspan opts[:rowspan] = rowspan if rowspan if heading tag.th(**opts) { @content } else tag.td(**opts) { @content } end end |