multitab

package
v0.0.0-...-a71523b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2025 License: MIT Imports: 4 Imported by: 0

README

Multi-Tab Bubble

A modular approach to build a tabbed interface using the Bubble Tea framework.

Demo

Features

  • Simple, independent and modular tab switching
  • Independent tab state management
  • Allows users to style tabs how they wish (active and inactive)

Key Concepts

There are 2 basic components you need to be familiar with to use this effectivley:

  1. TabModel interface{}

    • This interface is the abstraction of the actual tab.

    • It requires you to implement all methods a bubbletea model needs plus 2 others:

      • Title() & SetActive()
    • Basically, each implementation is its own tab - how you define Update() & View() will determine how the tab looks & reacts when it becomes active (more on the controller in concept #2)

          type TabModel interface {
          // Init initializes the tab and returns an initial command.
          Init() tea.Cmd
      
          // Update handles incoming messages and updates the tab's state.
          // It returns the updated model and an optional command.
          Update(tea.Msg) (tea.Model, tea.Cmd)
      
          // View renders the tab's view as a string.
          View() string
      
          // Additional: Title returns the title of the tab.
          Title() string
      
          // Additional: SetActive handles the activation state of the tab.
          SetActive(bool)
      }
      
  2. TabsModel{}

    • This Bubbletea model is the primary controller that contains all the tabs defined above.
      • It tells the TabModel{}s (implemented above) to initialize & update themselves as defined by the user.
    • This code should generally not be edited - it's your link between the main program and the user's implementation. Because of this, your main program is dead simple and all the logic is maintained in the user-implemented TabModel{}

Simple Usage in Go

See a complete working implementation in the example directory

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TabModel

type TabModel interface {
	// Init initializes the tab and returns an initial command.
	Init() tea.Cmd

	// Update handles incoming messages and updates the tab's state.
	// It returns the updated model and an optional command.
	Update(tea.Msg) (tea.Model, tea.Cmd)

	// View renders the tab's view as a string.
	View() string

	// Title returns the title of the tab.
	Title() string

	// SetActive handles the activation state of the tab.
	SetActive(bool)
}

TabModel represents the interface for a tab component in the UI. It defines the necessary methods that a tab should implement to initialize, update, render its view, and provide its title.

type TabsModel

type TabsModel struct {
	// contains filtered or unexported fields
}

TabsModel represents the model for managing a collection of tabs in a UI component. It includes the list of tabs, the index of the currently active tab, and a flag to indicate whether tab navigation should wrap around when reaching the end of the list.

Fields: - tabs: A slice of TabModel implementations representing the individual tabs. - active: An integer representing the index of the currently active tab. - wraparound: A boolean indicating whether tab navigation should wrap around.

Styles: - tabStyle: The style applied to inactive tabs. - activeTabStyle: The style applied to the active tab.

func NewTabsModel

func NewTabsModel(tabs []TabModel, wraparound bool) *TabsModel

returns a new instance of TabsModel with the provided tabs and wraparound flag.

func (*TabsModel) Init

func (m *TabsModel) Init() tea.Cmd

func (*TabsModel) Update

func (m *TabsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*TabsModel) View

func (m *TabsModel) View() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL