Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kutty-bootstrap: Table #13

Open
Tracked by #10
nikochiko opened this issue Jan 3, 2023 · 6 comments
Open
Tracked by #10

kutty-bootstrap: Table #13

nikochiko opened this issue Jan 3, 2023 · 6 comments

Comments

@nikochiko
Copy link
Contributor

nikochiko commented Jan 3, 2023

We will need to use this Bootstrap component: https://getbootstrap.com/docs/4.6/content/tables/

For Tables, we should follow the style in https://github.com/pipalacademy/kutty/blob/1e20a839a502f0cd9a970afb5bc3052c00615e39/kutty/components/table.py

The tables can be themed, but the default style works well too. I think keyword arguments would be a good way to pass the style in this case, because StripedTable or DarkTable are not that different to be separated out, and a table could be both dark and striped.

@anandology
Copy link
Member

Could you please enumerate all the possible variations and show code examples with the proposed API?

@nikochiko
Copy link
Contributor Author

Yes. I imagined it to be the same as the previous Table element, with some extra keyword arguments. Like:

from kuty import Table

table1 = Table(columns=["a", "b", "c", "d"], striped=True, color_style="dark")
table1.add_row(["e", "f", "g", "h"])
table1.add_row(["i", "j", "k", "l"])

I'm not sure if color_style is the right name for it. It could be something other than dark or light also, something like primary, secondary, info, danger, etc. is also acceptable. I'm not sure if we should support it like that (that would couple it with bootstrap too tightly) but also losing out on that would mean less power to us.

@anandology
Copy link
Member

anandology commented Jan 4, 2023 via email

@anandology
Copy link
Member

anandology commented Jan 4, 2023 via email

@nikochiko
Copy link
Contributor Author

Yes. I agree.
I had thought of kind for alerts, but then kind implies to have all attributes. striped in this case being outside kind doesn't make sense with that naming.

@nikochiko
Copy link
Contributor Author

I'm thinking of this API for Tables:

from kutty import html
from kutty.bootstrap import Table, TableHead, TableBody, TableRow

# recommended usage style:
table = Table(columns=["#", "First Name", "Last Name", "Nickname"])
table.add_row(["1", "Foo", "Bar", "Baz"])
table.add_row(["2", "Spam", "Ham", "Eggs"])

# advanced usage style:
table = Table(
    TableHead(
        TableRow(
            html.th("#", scope="col"),
            html.th("First Name", scope="col"),
            html.th("Last Name", scope="col"),
            html.th("Nickname", scope="col"),
        )
    ),
    TableBody(
        TableRow(html.td("1"), html.td("Foo"), html.td("Bar"), html.td("Baz")),
        TableRow(html.td("2"), html.td("Spam"), html.td("Ham"), html.td("Eggs")),
    )
)

# TableRow can also be initialised like this:
row = TableRow(items=["1", "Foo", "Bar", "Baz"])

The advanced usage style doesn't look very nice in this case, but the other usage style looks very usable.
Additionally, table.head and table.body should be present. And both table.head and table.body should have an add_row method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants