tabs

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tabs provides tab navigation components for organizing content.

Available variants:

  • New() creates horizontal tabs (template: "lvt:tabs:horizontal:v1")
  • NewVertical() creates vertical tabs (template: "lvt:tabs:vertical:v1")
  • NewPills() creates pill-style tabs (template: "lvt:tabs:pills:v1")

Required lvt-* attributes: name

Example usage:

// In your controller/state
SettingsTabs: tabs.New("settings", []tabs.Tab{
    {ID: "general", Label: "General"},
    {ID: "security", Label: "Security"},
    {ID: "notifications", Label: "Notifications"},
},
    tabs.WithActive("general"),
)

// In your template
{{template "lvt:tabs:horizontal:v1" .SettingsTabs}}
{{if eq .SettingsTabs.ActiveID "general"}}
  <!-- General settings content -->
{{end}}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Templates

func Templates() *base.TemplateSet

Templates returns the tabs component's template set for registration with the LiveTemplate framework.

Example usage in main.go:

import "github.com/livetemplate/lvt/components/tabs"

tmpl, err := livetemplate.New("app",
    livetemplate.WithComponentTemplates(tabs.Templates()),
)

Available templates:

  • "lvt:tabs:horizontal:v1" - Horizontal tabs (default)
  • "lvt:tabs:vertical:v1" - Vertical tabs (sidebar style)
  • "lvt:tabs:pills:v1" - Pill-style tabs

Types

type Option

type Option func(*Tabs)

Option is a functional option for configuring tabs.

func WithActive

func WithActive(tabID string) Option

WithActive sets the initially active tab by ID.

func WithStyled

func WithStyled(styled bool) Option

WithStyled enables Tailwind CSS styling for the component. When false, renders semantic HTML without styling classes.

type Tab

type Tab struct {
	ID       string // Unique identifier for this tab
	Label    string // Display text shown in the tab
	Icon     string // Optional icon (HTML or class name)
	Disabled bool   // Whether this tab is disabled
	Badge    string // Optional badge text (e.g., count)
}

Tab represents a single tab item.

type Tabs

type Tabs struct {
	base.Base

	// Items is the list of tabs
	Items []Tab

	// ActiveID is the ID of the currently active tab
	ActiveID string
}

Tabs is the base component for tab navigation. Use template "lvt:tabs:horizontal:v1" to render.

func New

func New(id string, items []Tab, opts ...Option) *Tabs

New creates horizontal tabs.

Example:

tabs := tabs.New("settings", []tabs.Tab{
    {ID: "general", Label: "General"},
    {ID: "security", Label: "Security"},
    {ID: "notifications", Label: "Notifications"},
},
    tabs.WithActive("general"),
)

func NewPills

func NewPills(id string, items []Tab, opts ...Option) *Tabs

NewPills creates pill-style tabs.

Example:

tabs := tabs.NewPills("filter", filterItems,
    tabs.WithActive("all"),
)

func NewVertical

func NewVertical(id string, items []Tab, opts ...Option) *Tabs

NewVertical creates vertical tabs (sidebar style).

Example:

tabs := tabs.NewVertical("nav", navItems,
    tabs.WithActive("dashboard"),
)

func (*Tabs) ActiveTab

func (t *Tabs) ActiveTab() *Tab

ActiveTab returns the currently active tab, or nil if none.

func (*Tabs) AddTab

func (t *Tabs) AddTab(tab Tab)

AddTab adds a new tab to the list.

func (*Tabs) EnabledTabCount

func (t *Tabs) EnabledTabCount() int

EnabledTabCount returns the number of non-disabled tabs.

func (*Tabs) IsActive

func (t *Tabs) IsActive(tabID string) bool

IsActive checks if a tab is currently active.

func (*Tabs) Next

func (t *Tabs) Next()

Next activates the next non-disabled tab (wraps around).

func (*Tabs) Previous

func (t *Tabs) Previous()

Previous activates the previous non-disabled tab (wraps around).

func (*Tabs) RemoveTab

func (t *Tabs) RemoveTab(tabID string)

RemoveTab removes a tab by ID.

func (*Tabs) SetActive

func (t *Tabs) SetActive(tabID string)

SetActive sets the active tab by ID.

func (*Tabs) Styles

func (t *Tabs) Styles() styles.TabsStyles

Styles returns the resolved CSS class set for this component. It lazily resolves from the registered style adapter and caches the result.

func (*Tabs) TabCount

func (t *Tabs) TabCount() int

TabCount returns the number of tabs.

Jump to

Keyboard shortcuts

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