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 ¶
- func Templates() *base.TemplateSet
- type Option
- type Tab
- type Tabs
- func (t *Tabs) ActiveTab() *Tab
- func (t *Tabs) AddTab(tab Tab)
- func (t *Tabs) EnabledTabCount() int
- func (t *Tabs) IsActive(tabID string) bool
- func (t *Tabs) Next()
- func (t *Tabs) Previous()
- func (t *Tabs) RemoveTab(tabID string)
- func (t *Tabs) SetActive(tabID string)
- func (t *Tabs) Styles() styles.TabsStyles
- func (t *Tabs) TabCount() int
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 ¶
WithActive sets the initially active tab by ID.
func WithStyled ¶
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 ¶
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 ¶
NewPills creates pill-style tabs.
Example:
tabs := tabs.NewPills("filter", filterItems,
tabs.WithActive("all"),
)
func NewVertical ¶
NewVertical creates vertical tabs (sidebar style).
Example:
tabs := tabs.NewVertical("nav", navItems,
tabs.WithActive("dashboard"),
)
func (*Tabs) EnabledTabCount ¶
EnabledTabCount returns the number of non-disabled tabs.
func (*Tabs) Previous ¶
func (t *Tabs) Previous()
Previous activates the previous non-disabled tab (wraps around).
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.