Documentation
¶
Overview ¶
Package accordion provides collapsible content sections for organizing information.
Available variants:
- New() creates a basic accordion (template: "lvt:accordion:default:v1")
- NewSingle() creates single-open accordion (template: "lvt:accordion:single:v1")
Required lvt-* attributes: name
Example usage:
// In your controller/state
FAQ: accordion.New("faq", []accordion.Item{
{ID: "q1", Title: "What is LiveTemplate?", Content: "..."},
{ID: "q2", Title: "How do I get started?", Content: "..."},
})
// In your template
{{template "lvt:accordion:default:v1" .FAQ}}
Index ¶
- func Templates() *base.TemplateSet
- type Accordion
- func (a *Accordion) AddItem(item Item)
- func (a *Accordion) Close(itemID string)
- func (a *Accordion) CloseAll()
- func (a *Accordion) GetItem(itemID string) *Item
- func (a *Accordion) IsOpen(itemID string) bool
- func (a *Accordion) ItemCount() int
- func (a *Accordion) Open(itemID string)
- func (a *Accordion) OpenAll()
- func (a *Accordion) OpenCount() int
- func (a *Accordion) RemoveItem(itemID string)
- func (a *Accordion) Styles() styles.AccordionStyles
- func (a *Accordion) Toggle(itemID string)
- type Item
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Templates ¶
func Templates() *base.TemplateSet
Templates returns the accordion component's template set for registration with the LiveTemplate framework.
Example usage in main.go:
import "github.com/livetemplate/lvt/components/accordion"
tmpl, err := livetemplate.New("app",
livetemplate.WithComponentTemplates(accordion.Templates()),
)
Available templates:
- "lvt:accordion:default:v1" - Multi-open accordion
- "lvt:accordion:single:v1" - Single-open accordion
Types ¶
type Accordion ¶
type Accordion struct {
base.Base
// Items is the list of accordion sections
Items []Item
// OpenIDs contains the IDs of currently open items
OpenIDs map[string]bool
// AllowMultiple allows multiple items to be open at once
// When false, opening one item closes others (single-open mode)
AllowMultiple bool
}
Accordion is the base component for collapsible sections. Use template "lvt:accordion:default:v1" to render.
func New ¶
New creates an accordion that allows multiple items open.
Example:
faq := accordion.New("faq", []accordion.Item{
{ID: "q1", Title: "Question 1", Content: "Answer 1"},
{ID: "q2", Title: "Question 2", Content: "Answer 2"},
},
accordion.WithOpen("q1"),
)
func NewSingle ¶
NewSingle creates an accordion where only one item can be open at a time.
Example:
nav := accordion.NewSingle("nav", sections,
accordion.WithOpen("section1"),
)
func (*Accordion) RemoveItem ¶
RemoveItem removes an item by ID.
func (*Accordion) Styles ¶
func (a *Accordion) Styles() styles.AccordionStyles
Styles returns the resolved CSS class set for this component. It lazily resolves from the registered style adapter and caches the result.
type Item ¶
type Item struct {
ID string // Unique identifier for this item
Title string // Header text shown (always visible)
Content string // Body content (shown when expanded)
Disabled bool // Whether this item can be toggled
Icon string // Optional icon (HTML or class name)
}
Item represents a single accordion section.
type Option ¶
type Option func(*Accordion)
Option is a functional option for configuring accordions.
func WithStyled ¶
WithStyled enables Tailwind CSS styling for the component. When false, renders semantic HTML without styling classes.