tabs

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tabs provides tab components following shadcn/ui patterns. Tabs use Alpine.js for state management and support keyboard navigation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tab

func Tab(id string, label g.Node, opts ...TabOption) g.Node

Tab creates an individual tab button or link Tabs default to natural width (sized to content). Use WithGrow() for equal width distribution.

Example:

tabs.Tab("overview", g.Text("Overview"))

With custom options:

tabs.Tab("overview", g.Text("Overview"),
    tabs.WithHref("/overview"),
    tabs.WithTabClass("custom-class"),
    tabs.WithGrow(),  // Equal width distribution
    tabs.WithActive(true),
    tabs.WithAttr(g.Attr("data-testid", "overview-tab")),
)

func TabList

func TabList(children ...g.Node) g.Node

TabList creates a wrapper for tab buttons

Example:

tabs.TabList(
    tabs.Tab("tab1", g.Text("Tab 1")),
    tabs.Tab("tab2", g.Text("Tab 2")),
)

With scrollable option for many tabs:

tabs.TabList(
    tabs.Tab("tab1", g.Text("Tab 1")),
    tabs.Tab("tab2", g.Text("Tab 2")),
    tabs.WithScrollable(),
)

With equal width distribution:

tabs.TabList(
    tabs.Tab("tab1", g.Text("Tab 1"), tabs.WithGrow()),
    tabs.Tab("tab2", g.Text("Tab 2"), tabs.WithGrow()),
)

func TabListWithOptions added in v0.0.8

func TabListWithOptions(opts []TabListOption, children ...g.Node) g.Node

TabListWithOptions creates a tab list with custom options

func TabPanel

func TabPanel(id string, content ...g.Node) g.Node

TabPanel creates a content panel for a tab

Example:

tabs.TabPanel("overview", g.Text("Overview content here"))

func Tabs

func Tabs(children ...g.Node) g.Node

Tabs creates a tabs container with Alpine.js state management

IMPORTANT: Use WithDefaultTab to set the initially active tab

Example:

tabs.TabsWithOptions(
    []tabs.Option{tabs.WithDefaultTab("overview")},
    tabs.TabList(
        tabs.Tab("overview", g.Text("Overview")),
        tabs.Tab("details", g.Text("Details")),
    ),
    tabs.TabPanel("overview", g.Text("Overview content")),
    tabs.TabPanel("details", g.Text("Details content")),
)

func TabsWithOptions

func TabsWithOptions(opts []Option, children ...g.Node) g.Node

TabsWithOptions creates tabs with custom options

Types

type Option

type Option func(*TabsProps)

Option is a functional option for configuring tabs

func WithAttrs

func WithAttrs(attrs ...g.Node) Option

WithAttrs adds custom attributes

func WithClass

func WithClass(class string) Option

WithClass adds custom classes

func WithDefaultTab

func WithDefaultTab(id string) Option

WithDefaultTab sets the initially active tab

func WithOrientation

func WithOrientation(o Orientation) Option

WithOrientation sets the tab orientation

type Orientation

type Orientation string

Orientation defines tab layout direction

const (
	OrientationHorizontal Orientation = "horizontal"
	OrientationVertical   Orientation = "vertical"
)

type TabListOption added in v0.0.8

type TabListOption func(*TabListProps)

TabListOption is a functional option for configuring tab list

func WithScrollable added in v0.0.8

func WithScrollable() TabListOption

WithScrollable enables horizontal scrolling for overflow tabs

func WithTabListAttrs added in v0.0.8

func WithTabListAttrs(attrs ...g.Node) TabListOption

WithTabListAttrs adds custom attributes to the tab list

func WithTabListClass added in v0.0.8

func WithTabListClass(class string) TabListOption

WithTabListClass adds custom classes to the tab list

func WithTabListVariant added in v0.0.8

func WithTabListVariant(variant TabListVariant) TabListOption

WithTabListVariant sets the visual style of the tab list

type TabListProps added in v0.0.8

type TabListProps struct {
	Variant    TabListVariant
	Scrollable bool
	Class      string
	Attrs      []g.Node
}

TabListProps defines tab list configuration

type TabListVariant added in v0.0.8

type TabListVariant string

TabListVariant defines the visual style of the tab list

const (
	TabListVariantDefault   TabListVariant = "default"   // Boxed style with background
	TabListVariantUnderline TabListVariant = "underline" // Minimal with bottom border
	TabListVariantPills     TabListVariant = "pills"     // Rounded pill style
)

type TabOption added in v0.0.8

type TabOption func(*TabProps)

TabOption is a functional option for configuring individual tabs

func WithActive added in v0.0.8

func WithActive(active bool) TabOption

WithActive marks the tab as initially active

func WithAttr added in v0.0.8

func WithAttr(attr g.Node) TabOption

WithAttr adds a single custom attribute to the tab

func WithGrow added in v0.0.8

func WithGrow() TabOption

WithGrow adds flex-1 class for equal width distribution By default, tabs size naturally to their content.

func WithHref added in v0.0.8

func WithHref(href string) TabOption

WithHref makes the tab render as a link

func WithShrink added in v0.0.8

func WithShrink() TabOption

WithShrink removes flex-1 class for natural width sizing Deprecated: No longer needed. Tabs now default to natural width. Use WithGrow() if you want equal width distribution.

func WithTabAttrs added in v0.0.8

func WithTabAttrs(attrs ...g.Node) TabOption

WithTabAttrs adds custom attributes to the tab

func WithTabClass added in v0.0.8

func WithTabClass(class string) TabOption

WithTabClass adds custom classes to the tab

func WithTabVariant added in v0.0.8

func WithTabVariant(variant TabVariant) TabOption

WithTabVariant sets the visual style of the tab

type TabProps added in v0.0.8

type TabProps struct {
	Variant TabVariant
	Href    string
	Class   string
	Attrs   []g.Node
	Shrink  bool // Deprecated: No longer needed, tabs default to natural width
	Grow    bool // Add flex-1 for equal width distribution
	Active  bool
}

TabProps defines individual tab configuration

type TabVariant added in v0.0.8

type TabVariant string

TabVariant defines the visual style of individual tabs

const (
	TabVariantDefault   TabVariant = "default"   // Boxed style matching default list
	TabVariantUnderline TabVariant = "underline" // Minimal with bottom border
	TabVariantPills     TabVariant = "pills"     // Rounded pill style
)

type TabsProps

type TabsProps struct {
	DefaultTab  string
	Orientation Orientation
	Class       string
	Attrs       []g.Node
}

TabsProps defines tabs configuration

Jump to

Keyboard shortcuts

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