feat: Add Table component with borders, separators, and styling support#598
feat: Add Table component with borders, separators, and styling support#598votsuk wants to merge 2 commits intoanomalyco:mainfrom
Conversation
|
Hey @kommander , just want to start off by saying this is my first PR into opensource. Hope you take a look at this PR and consider the work I've put in. I will disclaim that I did use AI to help me put this together. The motive - I am building OpenDocker which is a TUI built on top of OpenTUI + Solid. I find myself displaying some data about docker containers, images, and volumes and I have to use hacky solutions like left pad to have data aligned well. With a solution like introducing the table primitive I am able to have a much cleaner and stable approach to displaying data in the TUI. |
|
Thanks for the PR. An observation is the rendering architecture. Every component in the table hierarchy returns [] from _getVisibleChildren(), which hides the entire subtree from the normal render/layout pipeline. This means children added via .add() don't participate in hit testing, selection, focus, or mouse events. Existing components that do manual drawing in renderSelf (Slider, ScrollBarArrow, LineNumberGutter, etc.) are all leaf nodes. With the current implementation text isn't selectable, for instance. There are other things in the PR to address, but I think it makes sense to first consider the architecture before iterating on the details. |
|
Thanks @simonklee for the comment. I see what you're saying and the concern. I'll take a look at it and rethink the architecture. I think I have a few ideas as well e.g extending the box renderable for the table to inherit the functionality of a box. A few other technical decisions I have in mind are also things like do we want to support completely dynamic cells allowing things having other renderables children besides just text? Would love to hear your thoughts on those 2 examples, and also any other architectural concerns you have as again... this is something new for me so I'm still trying to wrap my mind around this domain and don't want to just keep spitting out crap after crap lol and rather contribute something meaningful |
Summary
table,thead,tbody,tr,th,td) to core, React, and Solid packages with complete TypeScript typesDetails
Core Package (
@opentui/core)TableRenderablewith configurable border styles, colors, separators, and cell paddingTableHeadRenderable,TableBodyRenderable) with background color supportTableRowRenderable,TableHeaderCellRenderable,TableDataCellRenderable) with text alignment and per-cell stylingconstructs.tsas JSX-like helper functions (Table,THead,TBody,TR,TH,TD)React Package (
@opentui/react)Solid Package (
@opentui/solid)Examples & Tests
table-demofor core, React, and Solid showcasing all featuresA few screenshots
An example inside of OpenDocker using the table renderable
A solidjs demo for using the table renderable