Documentation
¶
Overview ¶
Package drawer provides slide-out panel/sidebar components.
Available variants:
- New() creates a drawer (template: "lvt:drawer:default:v1")
Open/close is handled client-side via CSS classes. The consuming page triggers the drawer by adding/removing the "open" class on the element with data-drawer attribute.
Example usage:
// In your controller/state
Sidebar: drawer.New("sidebar",
drawer.WithPosition("left"),
drawer.WithTitle("Navigation"),
)
// In your template
{{template "lvt:drawer:default:v1" .Sidebar}}
Index ¶
- func Templates() *base.TemplateSet
- type Drawer
- func (d *Drawer) HasTitle() bool
- func (d *Drawer) IsBottom() bool
- func (d *Drawer) IsHorizontal() bool
- func (d *Drawer) IsLeft() bool
- func (d *Drawer) IsRight() bool
- func (d *Drawer) IsTop() bool
- func (d *Drawer) IsVertical() bool
- func (d *Drawer) PositionClass() string
- func (d *Drawer) SizeClass() string
- func (d *Drawer) Styles() styles.DrawerStyles
- func (d *Drawer) TransformClass() string
- type Option
- func WithCloseOnEscape(close bool) Option
- func WithCloseOnOverlay(close bool) Option
- func WithOpen(_ bool) Option
- func WithPersistent(persistent bool) Option
- func WithPosition(position Position) Option
- func WithShowClose(show bool) Option
- func WithShowOverlay(show bool) Option
- func WithSize(size Size) Option
- func WithStyled(styled bool) Option
- func WithTitle(title string) Option
- type Position
- type Size
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Templates ¶
func Templates() *base.TemplateSet
Templates returns the drawer component's template set for registration with the LiveTemplate framework.
Example usage in main.go:
import "github.com/livetemplate/lvt/components/drawer"
tmpl, err := livetemplate.New("app",
livetemplate.WithComponentTemplates(drawer.Templates()),
)
Available templates:
- "lvt:drawer:default:v1" - Slide-out drawer/sidebar
Types ¶
type Drawer ¶
type Drawer struct {
base.Base
// Position is where the drawer slides from
Position Position
// Size is the drawer size
Size Size
// Title is the drawer header title
Title string
// ShowClose shows a close button
ShowClose bool
// ShowOverlay shows a backdrop overlay
ShowOverlay bool
// CloseOnOverlay closes drawer when clicking overlay
CloseOnOverlay bool
// CloseOnEscape closes drawer on Escape key
CloseOnEscape bool
// Persistent prevents closing (no overlay click, no escape)
Persistent bool
}
Drawer is a slide-out panel component. Use template "lvt:drawer:default:v1" to render.
func New ¶
New creates a drawer.
Example:
d := drawer.New("sidebar",
drawer.WithPosition(drawer.PositionLeft),
drawer.WithSize(drawer.SizeMd),
)
func (*Drawer) IsHorizontal ¶
IsHorizontal returns true if position is left or right.
func (*Drawer) IsVertical ¶
IsVertical returns true if position is top or bottom.
func (*Drawer) PositionClass ¶
PositionClass returns CSS classes for position.
func (*Drawer) Styles ¶
func (d *Drawer) Styles() styles.DrawerStyles
Styles returns the resolved DrawerStyles for this component.
func (*Drawer) TransformClass ¶
TransformClass returns the CSS transform value for the closed state. This is used as a CSS custom property; the open state uses translate(0,0).
type Option ¶
type Option func(*Drawer)
Option is a functional option for configuring drawers.
func WithCloseOnEscape ¶
WithCloseOnEscape enables closing on Escape key.
func WithCloseOnOverlay ¶
WithCloseOnOverlay enables closing when clicking overlay.
func WithOpen ¶
WithOpen is a no-op. Open/close is now handled client-side via CSS classes. Deprecated: This option has no effect.
func WithPersistent ¶
WithPersistent makes the drawer persistent (can't be closed by user).
func WithPosition ¶
WithPosition sets the drawer position.
func WithShowClose ¶
WithShowClose shows or hides the close button.
func WithShowOverlay ¶
WithShowOverlay shows or hides the backdrop overlay.