Evertras / bubble-table

A customizable, interactive table component for the Bubble Tea framework
MIT License
435 stars 25 forks source link

How can I alternate row styles? #173

Closed flippedcracker closed 6 days ago

flippedcracker commented 3 months ago

I've been using the lipgloss table module, but I like some of the options this one provides. But I don't see how to easily style every other row. Before, I was using the StyleFunc. Can you give any guidance?

Evertras commented 3 months ago

Hey there, this feels like a bit of an obvious oversight... let me take a look at this over the weekend when I get some time, apologies for the late response!

Evertras commented 3 months ago

I've added a way to provide a row styling function which is demonstrated in the updates example, which includes both alternating row styles as well as some dynamic styling for the row data. This has been released as v0.16.0, let me know if this does what you wanted or if this needs to be resolved in some other way.

Evertras commented 3 months ago

Hi @flippedcracker just checking if you were able to take a look at this to see if there was anything missing? If I don't hear back in a few days I'll close this issue for now, but obviously please feel free to reopen if there's still something missing.

flippedcracker commented 3 months ago

Sorry for the late response. And thank you for the quick fix. The fix works great for a static table. Can I still highlight selected rows with this?

flippedcracker commented 3 months ago

I figured out to use the WithRows().HighlightStyle()

Thanks!

Edit: looks like that doesn't change the background, just the foreground.

flippedcracker commented 3 months ago

Just to be more complete; If you use the HighlightStyle with the WithRowsStyleFunc, it appears that only the foreground color of the currently highlighted row will change the to the Highlight Style specified. The background color stays the same as what is defined in the WithRowStyleFunc.

Evertras commented 2 months ago

Apologies for the late response on this as life has been busy lately, I'll take another look at this when I get some time hopefully in the near future!

Evertras commented 2 months ago

Released a fix that should hopefully solve this in v0.16.1. The idea is that the highlighted row style is actually a poor fit for a custom style func anyway, because a single highlighted style may not apply properly. So the better way to approach this is to give the user control over what a highlighted row looks like with their custom style function, just passing it in as input.

Let me know if this solves things more fully. Apologies again for the wait!

rflandau commented 1 month ago

Not OP, but this solution works. It is not quite as granular as the coordinates provided by lipgloss's table, but the struct should well facilitate that if it becomes necessary in the future. Ignore me; I hadn't noticed the existence of StyledCell.