drawer

package
v0.1.6 Latest Latest
Warning

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

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

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

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

func New(id string, opts ...Option) *Drawer

New creates a drawer.

Example:

d := drawer.New("sidebar",
    drawer.WithPosition(drawer.PositionLeft),
    drawer.WithSize(drawer.SizeMd),
)

func (*Drawer) HasTitle

func (d *Drawer) HasTitle() bool

HasTitle returns true if drawer has a title.

func (*Drawer) IsBottom

func (d *Drawer) IsBottom() bool

IsBottom returns true if position is bottom.

func (*Drawer) IsHorizontal

func (d *Drawer) IsHorizontal() bool

IsHorizontal returns true if position is left or right.

func (*Drawer) IsLeft

func (d *Drawer) IsLeft() bool

IsLeft returns true if position is left.

func (*Drawer) IsRight

func (d *Drawer) IsRight() bool

IsRight returns true if position is right.

func (*Drawer) IsTop

func (d *Drawer) IsTop() bool

IsTop returns true if position is top.

func (*Drawer) IsVertical

func (d *Drawer) IsVertical() bool

IsVertical returns true if position is top or bottom.

func (*Drawer) PositionClass

func (d *Drawer) PositionClass() string

PositionClass returns CSS classes for position.

func (*Drawer) SizeClass

func (d *Drawer) SizeClass() string

SizeClass returns CSS classes for the size.

func (*Drawer) Styles

func (d *Drawer) Styles() styles.DrawerStyles

Styles returns the resolved DrawerStyles for this component.

func (*Drawer) TransformClass

func (d *Drawer) TransformClass() string

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

func WithCloseOnEscape(close bool) Option

WithCloseOnEscape enables closing on Escape key.

func WithCloseOnOverlay

func WithCloseOnOverlay(close bool) Option

WithCloseOnOverlay enables closing when clicking overlay.

func WithOpen

func WithOpen(_ bool) Option

WithOpen is a no-op. Open/close is now handled client-side via CSS classes. Deprecated: This option has no effect.

func WithPersistent

func WithPersistent(persistent bool) Option

WithPersistent makes the drawer persistent (can't be closed by user).

func WithPosition

func WithPosition(position Position) Option

WithPosition sets the drawer position.

func WithShowClose

func WithShowClose(show bool) Option

WithShowClose shows or hides the close button.

func WithShowOverlay

func WithShowOverlay(show bool) Option

WithShowOverlay shows or hides the backdrop overlay.

func WithSize

func WithSize(size Size) Option

WithSize sets the drawer size.

func WithStyled

func WithStyled(styled bool) Option

WithStyled enables Tailwind CSS styling.

func WithTitle

func WithTitle(title string) Option

WithTitle sets the drawer title.

type Position

type Position string

Position defines where the drawer slides from.

const (
	PositionLeft   Position = "left"
	PositionRight  Position = "right"
	PositionTop    Position = "top"
	PositionBottom Position = "bottom"
)

type Size

type Size string

Size defines the drawer size.

const (
	SizeSm   Size = "sm"
	SizeMd   Size = "md"
	SizeLg   Size = "lg"
	SizeXl   Size = "xl"
	SizeFull Size = "full"
)

Jump to

Keyboard shortcuts

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