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: TabView component #26

Open
nikochiko opened this issue Feb 1, 2023 · 12 comments
Open

kutty-bootstrap: TabView component #26

nikochiko opened this issue Feb 1, 2023 · 12 comments

Comments

@nikochiko
Copy link
Contributor

Should have this behaviour: https://getbootstrap.com/docs/4.6/components/navs/#javascript-behavior

image

The TabView component should allow creating component with a tablist and different content associated with each tab in the tablist. The content of the "tab panel" should change based on which tab is selected.

Sample usage:

from kutty.bootstrap import TabView

tabs = {
    "Alice": "Alice likes Foo",
    "Bob": "Bob likes Bar",
    "Charlie": "Charlie likes Baz",
}
tab_view = TabView()
for title, content in tabs.items():
  tab_view.add_tab(title, content)

If user wants more control, they can use tab_view.tab_list and tab_view.tab_panel.

@anandology
Copy link
Member

How will you support icons or badges in the title?

Something like:
https://getbootstrap.com/docs/4.6/components/badge/#pill-badges

@nikochiko
Copy link
Contributor Author

How about if the title need not be text?

We could something like this:

tab_view = TabView()

for title, content in tabs.items():
    tab_view.add(Pill(title), content))

Same goes for content too.

@anandology
Copy link
Member

Wouldn't it be better to have a separate TabPane class that contains both the title and the body?

That way, you can do:

tabs = TabView()
tabs.add_tab("Home", home())

which is same as:

tabs = TabView()
tabs.add(TabPane("Home", home()))

The TabPane can support extra options like pills, icons etc.

@nikochiko
Copy link
Contributor Author

nikochiko commented Feb 1, 2023 via email

@anandology
Copy link
Member

The tab title and body both need to go into separate divs. Also, I think my solution was not correct. There are separate classes for each nav style.

What you have mentioned is just an interface. The implementation can decide to render the title and body in separate divs.

@nikochiko
Copy link
Contributor Author

What you have mentioned is just an interface. The implementation can decide to render the title and body in separate divs.

For the components so far, we create special methods for adding elements like this conveniently, but each component itself renders only one output and that is directly added to the parent. It would be powerful if we could figure out a way to render a child differently based on its parent.

@anandology
Copy link
Member

anandology commented Feb 1, 2023 via email

@nikochiko
Copy link
Contributor Author

But the render method would be on the child itself and it can only render to HTML text.
If we modify the parent's render method to take out the tab and content as attributes from the child, then that should be a new kind of component because sometimes it will be rendered with its render and sometimes with its parent's render.

@anandology
Copy link
Member

anandology commented Feb 1, 2023

Why not something like this?

class TabView:
    def __init__(self):
        self.panes = []

    def render(self):
        a = self.render_tabs()
        b = self.render_content()
        return html.div(a, b).render()

    def render_tabs(self):
        tabs = [pane.render_tab() for pane in self.panes]
        return html.ul(*tabs, class_="nav nav-tabs", role="tablist")
    
    def render_content(self):
        contents = [pane.render_content() for pane in self.panes]
        return html.div(*contents, class_="nav-content")

class TabPane:
    def __init__(self, title, content):
        self.title = title
        self.content = content

    ...

@nikochiko
Copy link
Contributor Author

nikochiko commented Feb 1, 2023 via email

@anandology
Copy link
Member

Why should Optional look at children. It should probably call an is_empty method with a default implementation using children . Subclasses should be able to provide custom implementation for that.

@nikochiko
Copy link
Contributor Author

nikochiko commented Feb 1, 2023 via email

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