Plushie.Widget.Table (Plushie v0.7.0)

Copy Markdown View Source

Data table with children-based rows for efficient diffing.

Tables support two ways to populate rows:

Rich composition using table_row and cell children for custom cell content (buttons, icons, any widget):

table "users", columns: cols do
  for user <- users do
    table_row user.id do
      cell "name", text(user.name)
      cell "actions", button("del", "Delete")
    end
  end
end

Data shorthand using the rows: prop for text-only tables:

table "users", columns: cols, rows: data

These two approaches are mutually exclusive: setting rows: and providing do-block children in the same table raises an error.

Props

NameTypeDefaultDescription
columns[map()]nilColumn definitions. Each map requires a :key (string or atom, consistent across all columns). Optional: :label, :width, :sortable, :align.
rows[map()]nilData shorthand for text-only tables. List of maps with keys matching column :key values. Each map should include an :id key for stable row identity.
headerboolean()nilShow header row. Default: true.
width:fill | :shrink | {:fill_portion, pos_integer()} | number()nilTable width. Default: fill.
height:fill | :shrink | {:fill_portion, pos_integer()} | number()nilTable height. Wraps in a scrollable when set.
paddingnumber() | {number(), number()} | %Plushie.Type.Padding{}nilCell internal padding.
sort_byString.t() | atom()nilKey of the currently sorted column.
sort_order:asc | :descnilCurrent sort direction: :asc or :desc.
separatornumber()nilDivider line thickness in pixels. Set to 0.0 to hide.
separator_colorString.t()nilDivider line color.
header_text_sizenumber()nilText size for auto-generated header labels.
row_text_sizenumber()nilText size for data shorthand auto-generated cells.
event_rateinteger()nilMax events per second for coalescable events.
a11y%Plushie.Type.A11y{} | map() | keyword()%{role: :table}Accessibility annotations.

Events

EventTypeDescription
:sortvalue: String.t() | atom()Column key when a sortable header is clicked. App handles reordering.

Summary

Functions

Accessibility annotations.

Converts this widget struct to a ui_node() map.

Column definitions. Each map requires a :key (string or atom, consistent across all columns). Optional: :label, :width, :sortable, :align.

Max events per second for coalescable events.

Appends multiple children to the widget.

Show header row. Default: true.

Text size for auto-generated header labels.

Table height. Wraps in a scrollable when set.

Creates a new widget struct with the given ID and keyword options.

Cell internal padding.

Appends a child to the widget.

Text size for data shorthand auto-generated cells.

Data shorthand for text-only tables. List of maps with keys matching column :key values. Each map should include an :id key for stable row identity.

Divider line thickness in pixels. Set to 0.0 to hide.

Key of the currently sorted column.

Current sort direction: :asc or :desc.

Creates a :table widget.

Table width. Default: fill.

Applies keyword options to an existing widget struct.

Types

option()

@type option() ::
  (((((((((((({:columns, [map()]} | {:rows, [map()]}) | {:header, boolean()})
            | {:width,
               :fill | :shrink | {:fill_portion, pos_integer()} | number()})
           | {:height,
              :fill | :shrink | {:fill_portion, pos_integer()} | number()})
          | {:padding,
             number()
             | {number(), number()}
             | %Plushie.Type.Padding{
                 bottom: term(),
                 left: term(),
                 right: term(),
                 top: term()
               }})
         | {:sort_by, String.t() | atom()})
        | {:sort_order, :asc | :desc})
       | {:separator, number()})
      | {:separator_color, atom() | String.t() | map()})
     | {:header_text_size, number()})
    | {:row_text_size, number()})
   | {:event_rate, integer()})
  | {:a11y,
     %Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword()}

t()

@type t() :: %Plushie.Widget.Table{
  a11y:
    (%Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  children: [Plushie.Widget.ui_node()],
  columns:
    [map()]
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  event_rate:
    integer()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  header:
    boolean()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  header_text_size:
    number()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  height:
    (:fill | :shrink | {:fill_portion, pos_integer()} | number())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  id: String.t(),
  padding:
    (number()
     | {number(), number()}
     | %Plushie.Type.Padding{
         bottom: term(),
         left: term(),
         right: term(),
         top: term()
       })
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  row_text_size:
    number()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  rows:
    [map()]
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  separator:
    number()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  separator_color:
    String.t()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  sort_by:
    (String.t() | atom())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  sort_order:
    (:asc | :desc)
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  width:
    (:fill | :shrink | {:fill_portion, pos_integer()} | number())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil
}

Functions

a11y(widget, descriptor)

@spec a11y(
  widget :: t(),
  value ::
    (%Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword())
    | nil
) :: t()

Accessibility annotations.

Accepts %Plushie.Type.A11y{} | map() | keyword().

build(widget)

@spec build(widget :: t()) :: Plushie.Widget.ui_node()

Converts this widget struct to a ui_node() map.

columns(widget, descriptor)

@spec columns(widget :: t(), value :: [map()] | nil) :: t()

Column definitions. Each map requires a :key (string or atom, consistent across all columns). Optional: :label, :width, :sortable, :align.

Accepts [map()].

event_rate(widget, descriptor)

@spec event_rate(widget :: t(), value :: integer() | nil) :: t()

Max events per second for coalescable events.

Accepts integer().

extend(widget, children)

@spec extend(widget :: t(), children :: [Plushie.Widget.child()]) :: t()

Appends multiple children to the widget.

header(widget, descriptor)

@spec header(widget :: t(), value :: boolean() | nil) :: t()

Show header row. Default: true.

Accepts boolean().

header_text_size(widget, descriptor)

@spec header_text_size(widget :: t(), value :: number() | nil) :: t()

Text size for auto-generated header labels.

Accepts number().

height(widget, descriptor)

@spec height(
  widget :: t(),
  value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
) :: t()

Table height. Wraps in a scrollable when set.

Accepts :fill | :shrink | {:fill_portion, pos_integer()} | number().

new(id, opts \\ [])

@spec new(id :: String.t(), opts :: [option()]) :: t()

Creates a new widget struct with the given ID and keyword options.

padding(widget, descriptor)

@spec padding(
  widget :: t(),
  value ::
    (number()
     | {number(), number()}
     | %Plushie.Type.Padding{
         bottom: term(),
         left: term(),
         right: term(),
         top: term()
       })
    | nil
) :: t()

Cell internal padding.

Accepts number() | {number(), number()} | %Plushie.Type.Padding{}.

push(widget, child)

@spec push(widget :: t(), child :: Plushie.Widget.child()) :: t()

Appends a child to the widget.

row_text_size(widget, descriptor)

@spec row_text_size(widget :: t(), value :: number() | nil) :: t()

Text size for data shorthand auto-generated cells.

Accepts number().

rows(widget, descriptor)

@spec rows(widget :: t(), value :: [map()] | nil) :: t()

Data shorthand for text-only tables. List of maps with keys matching column :key values. Each map should include an :id key for stable row identity.

Accepts [map()].

separator(widget, descriptor)

@spec separator(widget :: t(), value :: number() | nil) :: t()

Divider line thickness in pixels. Set to 0.0 to hide.

Accepts number().

separator_color(widget, descriptor)

@spec separator_color(widget :: t(), value :: (atom() | String.t() | map()) | nil) ::
  t()

Divider line color.

Accepts String.t().

sort_by(widget, descriptor)

@spec sort_by(widget :: t(), value :: (String.t() | atom()) | nil) :: t()

Key of the currently sorted column.

Accepts String.t() | atom().

sort_order(widget, descriptor)

@spec sort_order(widget :: t(), value :: (:asc | :desc) | nil) :: t()

Current sort direction: :asc or :desc.

Accepts :asc | :desc.

table(id, opts \\ [])

(macro)

Creates a :table widget.

Shorthand for new/2. Import this macro to use the widget name directly in view functions:

import Plushie.Widget.Table, only: [table: 2]

table("my-id", prop: value)

width(widget, descriptor)

@spec width(
  widget :: t(),
  value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
) ::
  t()

Table width. Default: fill.

Accepts :fill | :shrink | {:fill_portion, pos_integer()} | number().

with_options(widget, opts)

@spec with_options(widget :: t(), opts :: [option()]) :: t()

Applies keyword options to an existing widget struct.