Class: Plushie::Widget::Table
- Inherits:
-
Object
- Object
- Plushie::Widget::Table
- Defined in:
- lib/plushie/widget/table.rb
Overview
Table -- data table with column definitions and optional sorting.
A container widget: child nodes represent row content. Use #push to add children immutably.
Props:
- columns (array of hashes) -- column definitions (key, label, width).
- rows (array) -- row data.
- header (boolean) -- show header row.
- separator (boolean) -- show row separators.
- width (length) -- table width.
- padding (number|hash) -- cell padding.
- sort_by (string) -- column key to sort by.
- sort_order (symbol) -- :asc or :desc.
- header_text_size (number) -- header font size.
- row_text_size (number) -- row font size.
- cell_spacing (number) -- horizontal spacing between cells.
- row_spacing (number) -- vertical spacing between rows.
- separator_thickness (number) -- separator line thickness.
- separator_color (string) -- separator colour.
- a11y (hash) -- accessibility overrides.
Constant Summary collapse
- PROPS =
Supported property keys for the table widget.
%i[columns rows header separator width padding sort_by sort_order header_text_size row_text_size cell_spacing row_spacing separator_thickness separator_color a11y].freeze
Instance Attribute Summary collapse
-
#a11y ⇒ Object
readonly
Returns the value of attribute a11y.
-
#cell_spacing ⇒ Object
readonly
Returns the value of attribute cell_spacing.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#header_text_size ⇒ Object
readonly
Returns the value of attribute header_text_size.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#row_spacing ⇒ Object
readonly
Returns the value of attribute row_spacing.
-
#row_text_size ⇒ Object
readonly
Returns the value of attribute row_text_size.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#separator_color ⇒ Object
readonly
Returns the value of attribute separator_color.
-
#separator_thickness ⇒ Object
readonly
Returns the value of attribute separator_thickness.
-
#sort_by ⇒ Object
readonly
Returns the value of attribute sort_by.
-
#sort_order ⇒ Object
readonly
Returns the value of attribute sort_order.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #build ⇒ Plushie::Node
-
#initialize(id, **opts) ⇒ Table
constructor
A new instance of Table.
-
#push(child) ⇒ Table
Append a child node.
Constructor Details
Instance Attribute Details
#a11y ⇒ Object (readonly)
Returns the value of attribute a11y.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def a11y @a11y end |
#cell_spacing ⇒ Object (readonly)
Returns the value of attribute cell_spacing.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def cell_spacing @cell_spacing end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def children @children end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def columns @columns end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def header @header end |
#header_text_size ⇒ Object (readonly)
Returns the value of attribute header_text_size.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def header_text_size @header_text_size end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def id @id end |
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def padding @padding end |
#row_spacing ⇒ Object (readonly)
Returns the value of attribute row_spacing.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def row_spacing @row_spacing end |
#row_text_size ⇒ Object (readonly)
Returns the value of attribute row_text_size.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def row_text_size @row_text_size end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def rows @rows end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def separator @separator end |
#separator_color ⇒ Object (readonly)
Returns the value of attribute separator_color.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def separator_color @separator_color end |
#separator_thickness ⇒ Object (readonly)
Returns the value of attribute separator_thickness.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def separator_thickness @separator_thickness end |
#sort_by ⇒ Object (readonly)
Returns the value of attribute sort_by.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def sort_by @sort_by end |
#sort_order ⇒ Object (readonly)
Returns the value of attribute sort_order.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def sort_order @sort_order end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
1 2 3 |
# File 'lib/plushie/widget/table.rb', line 1 def width @width end |
Instance Method Details
#build ⇒ Plushie::Node
65 66 67 68 69 70 71 72 73 |
# File 'lib/plushie/widget/table.rb', line 65 def build props = {} PROPS.each do |key| val = instance_variable_get(:"@#{key}") Build.put_if(props, key, val) end Node.new(id: @id, type: "table", props: props, children: Build.children_to_nodes(@children)) end |
#push(child) ⇒ Table
Append a child node. Returns a new Table (immutable).
60 61 62 |
# File 'lib/plushie/widget/table.rb', line 60 def push(child) dup.tap { _1.instance_variable_set(:@children, @children + [child]) } end |