mordant
mordant copied to clipboard
Mordant 2.0 Tables DSL suggestion
Hello @ajalt!
I see that in Mordant 2.0 you want to add support for rendering tables, and you have also a nice DSL for it. Well, I have some suggestions to it. I think that when table styling and properties are lying around with child components of a table it is not very easy to read. I think it is better to implement styling in function arguments, like in Jetpack Compose. So it will look like this:
table(
align = BorderLocation.TopBottom,
outerBorder = false
) {
header(
style = TableStyle(color = DefaultColors.Magenta, bold = true)
) {
row("", "Projected Cost", "Actual Cost", "Difference")
}
body(
borders = BorderLocation.TopBottom
) {
row("Food", "$400", "$200", "$200")
row("Data", "$100", "$150", "-$50")
row("Rent", "$800", "$800", "$0")
row("Candles", "$0", "$3,600", "-$3,600")
row("Utility", "$145", "$150", "-$5")
}
footer(
style = TableStyle(bold = true)
) {
row {
cell(text = "Subtotal")
cell(columnSpan = 3, text = "$-3,455")
}
}
captionBottom("Budget courtesy @dril", TextStyle(dim = true))
}
I think it looks a lot better :D
What do you think about this?
Thanks for the feedback!
Although I don't feel strongly about it either way, you proposal looks like a step backwards from the current implementation to me. It seems cluttered up with extra braces/parentheses compared to using builder properties. The current implementation also has the advantage of sharing all the properties using a common interface, whereas the proposal would require some copy-pasted code.