Idea to add more functioanlity to a tabbed view - introduce new components? #693
nick-popovic
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Charmbracelet Team,
Disclosure: so sorry for the essay XD ...
Thought I'd share some work I've done on the side while playing around with your Bubbletea framework.
Current State
Currently, there is no ability to use prebuilt components to handle multiple tabs that scales your code horizontally. As of now all there is is the following example of a single model that incorporates logic for tab switching: https://github.com/charmbracelet/bubbletea/tree/main/examples/tabs
Very well done btw :) and shows the basics on how to use Bubbletea but if you wanted to add more (tabs, interactions, nested models/bubbles ..etc) you're kind of stuck with figuring out how to manage different tabs and as the number of tabs increases, so does your internal code logic and there's no best practices (that I could find anyways) where this can be handled better so I build my own custom model.
Proposed Solution
In my approach, I created main 2 artifacts
TabModel
that makes the user implementInit()
/Update()
/View()
at the tab-content-level. To make the codebase readable, each tab implements this model and is in a separate file (see my own custom model).TabsModel
- a custom-implemented Bubbletea model that generally shouldn't be modified and that represents the entire tabbed view (tabs + active tab view). If this was ever accepted into future versions of the bubbles repo, only the file that contains both of these artifacts inside mytabsmodel.go
file would need to be imported.Benefits
TabModel
interface, you can easily parse out more complex tabs from each otherHere is how you main definitions look like:
Here is how your main Update() and View() looks like:
Potential Hiccups / Feedback
p.s. The whole reason I know about this project was because I was trying to lean Go and I stumbled upon some tutorials that @bashbunni hosted on YouTube. I know C very well and wanted to update my knowledge with something a tad bit more modern and Youtube recommended me some of her videos. Very cool project and kudos to the entire team for an amazing product !! :) ... Thanks Youtube algorithm? xD
Beta Was this translation helpful? Give feedback.
All reactions