Skip to content

Table #45

@roblafeve

Description

@roblafeve

Proposal

Tables can be a pain. Let's make it as quick and easy to spit out a simple table that handles sorting and selection.

AC

  1. Any data can be mapped to a row
  2. Can sorting by column
  3. Can select by row
  4. Does not support complicated tables

Interface Options

A - Render Children and Props

Pros:

  1. Kind of looks like a table...

Cons:

  1. We'll still have to pass configuration for header/footer to distinct props which will give this a weird shape
  2. Need to pull in custom, or native table elements—you essentially still need to build a table
  3. Kind of looks like a table—seems like a shallow module (bad)—doesn't hide much
<Table
  data={data}
  renderHeader={() => (...)}
  >
  {({ a, b, c, d }) => (
    <Tr>
      <Td>{a}</Td>
      <Td>{b}</Td>
      <Td>{c}</Td>
      <Td>{d}</Td>
    </Tr>
  )}
</Table>

B - Render Props

Pros:

  1. Kind of looks like a table
  2. All render props are passed as props—as opposed to using children

Cons:

  1. Same as Option A
<Table
  data={data}
  renderHeader={() => (...)}
  renderRow={({ a, b, c, d }) => (
    <Tr>
      <Td>{a}</Td>
      <Td>{b}</Td>
      <Td>{c}</Td>
      <Td>{d}</Td>
    </Tr>
  )}
/>

C - Config-Based

Pros:

  1. No knowledge of table structure is needed (deep module)
  2. Column headers and table data values are define once—instead of potentially defining them separately—and potentially mismatching them.

Cons:

  1. Lose FULL control—but that's the point. This is the starting point for a useful abstraction that the user could augment to fit their needs.
<Table
  data={data}
  columns={[
    { label: null }, // maybe we need a gap 🤷‍♂️
    { label: "A", getValue: (user) => user.a, sortable: true },
    { label: "B", getValue: (user) => user.b },
    { label: "C", getValue: (user) => user.c.toString() },
    { label: "D", getValue: (user) => user.d.e },
  ]}
/>

I might convert columns to a single function that has "datum" passed to it

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

🏗 In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions