Class: Shadcn::Chart::Table::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/chart/table/component.rb

Overview

The chart's numbers, as a table only a screen reader sees.

Ours. chart.tsx has nothing like it — upstream's answer is recharts' accessibilityLayer, which makes the chart arrow-navigable and announces a category at a time.

A table is what this port reaches for instead, because a table is already a table: a screen reader enters it in table mode, moves by row and by column, and rereads the column header on demand. What it replaces is one long sentence — "January: Desktop 186, Mobile 80; February: …" — which cannot be navigated, cannot be reread in pieces, and by the time a year of months is in it is not a sentence anyone listens to.

It is rendered by the shape rather than by the container, so that a shape rendered on its own is still complete, and so that the graphic and its table can never disagree about who carries the data — the same object emits both.

Not Shadcn::Table, despite the name it shadows inside this module: that family's classes are all visual — borders, padding, hover — and every one of them would be dead CSS on an element no one sees.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#css_classes, default_tag, #element_attributes, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(caption: nil, columns: [], rows: [], **attributes) ⇒ Component

rows is one array per row: the row's own header, then a cell per column.



40
41
42
43
44
45
# File 'app/components/shadcn/chart/table/component.rb', line 40

def initialize(caption: nil, columns: [], rows: [], **attributes)
  @caption = caption
  @columns = columns
  @rows = rows
  super(**attributes)
end

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



36
37
38
# File 'app/components/shadcn/chart/table/component.rb', line 36

def caption
  @caption
end

#columnsObject (readonly)

Returns the value of attribute columns.



36
37
38
# File 'app/components/shadcn/chart/table/component.rb', line 36

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



36
37
38
# File 'app/components/shadcn/chart/table/component.rb', line 36

def rows
  @rows
end

Instance Method Details

#callObject



47
48
49
# File 'app/components/shadcn/chart/table/component.rb', line 47

def call
  render_element(body: safe_join([ heading, head, body ].compact))
end