Skip to content

[Table] Composable and simpler API #2251

@alitaheri

Description

@alitaheri

Regarding #2246. I'd say we should rewrite table, it's better not to use HTML table and instead do it all with div. This will give very flexible api and capability that would otherwise be impossible with table.

Right now there are tight couplings between Table and it's child components TableHeader, TableBody and TableFooter. There should be carefully designed props instead of wrapping the child components within divs and tables only to apply some styles and callbacks that can hurt composibility and customizability.

But I guess if we decide to do this we have to rewrite all the table components. Therefore, deprecation will be very hard.

Roadmap:

  1. Keep the Table as it is for now.
  2. Create new Table component set.
  3. Deprecate the old components with a migration guide.
  4. Remove the old Table components after some time.

New Components to be built:

  • Table (how to disambiguate with the current table?)
    • Only a wrapper.
    • Passes dimension data, column sizes, etc. down the hierarchy via context.
    • Takes Header and Footer (or arrays of them?) as props not as children.
    • The children are the rows (that can be anything, not just TableRow).
  • TableHeader (disambiguate!)
    • Can only accept TableCell
    • Flexible height?
  • TableRow (disambiguate!)
    • Can only accept TableCell
    • Handles selection.
  • TableCell
    • Can span multiple columns.

The sizes of columns will be passed down the hierarchy by the Table component. This information is something like this:

// the actual width of each column would be calculated like this:
// actualtWidthOfColumns[0] = (columns[0] / columns.sum() ) * tableWidth;
const columns = [5, 1, 1, 2, 2];
const tableWidth = 1000;

This means the first column will have the width of 500, the second 100 and so on.

With this, one can implement any feature around the table. Or even build it within the components. Features such as sorting, pagination, flexible columns, resizable columns, editable cells and so on. All these are possible right now, but with a lot of pain. Because the coupling is very tight. But with this things can become a lot easier for others to customize the table to their needs.

I'd love to hear everyone's thoughts on this. Or how it can be improved further.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: new featureExpand the scope of the product to solve a new problem.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions