components

package module
v0.1.8 Latest Latest
Warning

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

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

README

LiveTemplate Components Library

Components Independence

A comprehensive collection of reusable UI components for the LiveTemplate framework.

Features

  • Zero Boilerplate - Use components directly via library API with functional options
  • Tailwind CSS - Styled variants with Tailwind classes, plus unstyled semantic HTML options
  • Server-Side State - All component state managed on the server via LiveTemplate
  • lvt- Attributes* - Uses existing generic attributes, no client library changes needed
  • Full Customization - Override templates or eject for complete control

Installation

go get github.com/livetemplate/lvt/components

Quick Start

1. Register Templates (once in main.go)
import "github.com/livetemplate/lvt/components"

tmpl := livetemplate.NewTemplates(
    livetemplate.WithComponentTemplates(components.All()),
    livetemplate.ParseGlob("internal/app/**/*.tmpl"),
)
2. Use Components in Your Page
import "github.com/livetemplate/lvt/components/dropdown"

type State struct {
    CountrySelect *dropdown.Searchable
}

// In init
CountrySelect: dropdown.NewSearchable("country", countries,
    dropdown.WithPlaceholder("Select country"),
    dropdown.WithSelected(user.CountryCode),
)
3. Render in Templates
<div class="form-group">
    <label>Country</label>
    {{template "lvt:dropdown:searchable:v1" .CountrySelect}}
</div>

Available Components

Form Controls
Component Package Templates Description
Dropdown dropdown default, searchable, multi Single and multi-select dropdowns
Autocomplete autocomplete default Search with suggestions
Date Picker datepicker single, range, inline Date selection
Time Picker timepicker default Time selection
Tags Input tagsinput default Tag/chip input
Toggle toggle default, checkbox Toggle switches
Rating rating default Star ratings
Layout
Component Package Templates Description
Tabs tabs horizontal, vertical, pills Tab navigation
Accordion accordion default, single Collapsible sections
Modal modal default, confirm, sheet Modal dialogs
Drawer drawer default Slide-out panels
Feedback
Component Package Templates Description
Toast toast default, container Toast notifications
Tooltip tooltip default Tooltips
Popover popover default Rich content popovers
Progress progress default, circular, spinner Progress indicators
Skeleton skeleton default, avatar, card Loading placeholders
Data Display
Component Package Templates Description
Data Table datatable default Tables with sorting/pagination
Timeline timeline default Event timelines
Breadcrumbs breadcrumbs default Navigation breadcrumbs
Navigation
Component Package Templates Description
Menu menu default, nested Navigation menus

Template Naming Convention

All templates follow the pattern: lvt:<component>:<variant>:v<version>

{{template "lvt:dropdown:default:v1" .MyDropdown}}
{{template "lvt:dropdown:searchable:v1" .SearchDropdown}}
{{template "lvt:tabs:horizontal:v1" .MyTabs}}
{{template "lvt:modal:confirm:v1" .ConfirmModal}}

Styling Options

Styled (Default)

Components come with Tailwind CSS classes baked in:

dropdown.New("id", options)
Unstyled

For custom CSS or other frameworks, use unstyled mode:

dropdown.New("id", options, dropdown.WithStyled(false))

This renders semantic HTML without any classes.

Customization

Option 1: Functional Options

Most customization can be achieved through functional options:

dropdown.NewSearchable("country", countries,
    dropdown.WithPlaceholder("Select country"),
    dropdown.WithSelected("US"),
    dropdown.WithMinChars(2),
    dropdown.WithDebounce(300),
)
Option 2: Override Template

Define the same template name in your project - it takes precedence:

{{/* internal/app/templates/dropdown-override.tmpl */}}
{{define "lvt:dropdown:searchable:v1"}}
<div class="my-custom-dropdown">
    {{/* Your custom markup */}}
</div>
{{end}}
Option 3: Eject Template Only

Extract just the HTML template while keeping the Go logic:

lvt component eject-template dropdown searchable
Option 4: Full Eject

Get complete source code for total control:

lvt component eject dropdown

CLI Commands

List Available Components
lvt component list
Eject Full Component
lvt component eject <component>
lvt component eject dropdown --dest internal/ui/dropdown
Eject Template Only
lvt component eject-template <component> <template>
lvt component eject-template dropdown searchable
Scaffold New Component
lvt new component <name>
lvt new component my-widget

Component Development

Creating a New Component
lvt new component rating

This creates:

components/rating/
  rating.go           # Component struct and constructor
  options.go          # Functional options
  templates.go        # Template embedding
  rating_test.go      # Tests
  templates/
    default.tmpl      # HTML template
Component Structure
// rating.go
package rating

import "github.com/livetemplate/lvt/components/base"

type Rating struct {
    base.Base
    Value    int
    MaxStars int
}

func New(id string, opts ...Option) *Rating {
    r := &Rating{
        Base:     base.NewBase(id, "rating"),
        MaxStars: 5,
    }
    for _, opt := range opts {
        opt(r)
    }
    return r
}
Template Structure
{{define "lvt:rating:default:v1"}}
{{if .IsStyled}}
<div class="flex gap-1" data-component="rating" data-id="{{.ID}}">
  {{/* Tailwind styled version */}}
</div>
{{else}}
<div data-component="rating" data-id="{{.ID}}">
  {{/* Unstyled semantic HTML */}}
</div>
{{end}}
{{end}}

Independence Guarantee

The components module is fully independent from the parent lvt CLI tool. This means external projects can import and use components without pulling in the entire lvt dependency tree.

What CI checks:

  • No imports of github.com/livetemplate/lvt (parent module)
  • No imports of github.com/livetemplate/lvt/internal or github.com/livetemplate/lvt/commands (fully-qualified import paths)
  • components/go.mod does not require the parent module
  • go build ./... and go test ./... pass with GOWORK=off
  • An external test module can import and build against components

Using components in your project:

import "github.com/livetemplate/lvt/components/modal"

m := modal.New("my-modal", modal.WithTitle("Confirm"))

No lvt CLI installation required — components are a standalone Go library.

Contributing

See CONTRIBUTING.md for guidelines on:

  • Component naming conventions
  • Template requirements
  • Test requirements
  • PR process

License

MIT License - see LICENSE file for details.

Documentation

Overview

Package components provides pre-built UI components for the LiveTemplate framework.

This library provides reusable, styled components that can be registered with LiveTemplate applications using the WithComponentTemplates() option.

Quick Start

Register all component templates in your main.go:

import "github.com/livetemplate/lvt/components"

func main() {
    tmpl := livetemplate.NewTemplates(
        livetemplate.WithComponentTemplates(components.All()),
        livetemplate.ParseGlob("internal/app/**/*.tmpl"),
    )
}

Then use components in your templates:

{{template "lvt:dropdown:searchable:v1" .MyDropdown}}

Available Components

See the component-specific packages for detailed documentation:

  • dropdown: Dropdown menus (default, searchable, multi-select)
  • tabs: Tab navigation and content panels
  • modal: Modal dialogs and sheets
  • toast: Toast notifications
  • accordion: Collapsible sections
  • datepicker: Date/time selection
  • rating: Star rating
  • And more...

Customization

Components use Tailwind CSS by default. Override by defining the same template name in your project - project templates take precedence over library templates.

Contributing

See the repository README for contribution guidelines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All() []*base.TemplateSet

All returns all component template sets for registration with LiveTemplate.

Usage:

tmpl := livetemplate.NewTemplates(
    livetemplate.WithComponentTemplates(components.All()),
)

This registers all component templates, allowing you to use any component in your templates immediately.

func Version

func Version() string

Version returns the library version.

Types

This section is empty.

Directories

Path Synopsis
Package accordion provides collapsible content sections for organizing information.
Package accordion provides collapsible content sections for organizing information.
Package autocomplete provides typeahead/autocomplete input components.
Package autocomplete provides typeahead/autocomplete input components.
Package base provides common types and utilities for LiveTemplate components.
Package base provides common types and utilities for LiveTemplate components.
Package breadcrumbs provides breadcrumb navigation components for the LiveTemplate framework.
Package breadcrumbs provides breadcrumb navigation components for the LiveTemplate framework.
Package datatable provides data table components with sorting, filtering, and pagination.
Package datatable provides data table components with sorting, filtering, and pagination.
Package datepicker provides date selection components with calendar UI.
Package datepicker provides date selection components with calendar UI.
Package drawer provides slide-out panel/sidebar components.
Package drawer provides slide-out panel/sidebar components.
Package dropdown provides dropdown/select components with single and multi-select support.
Package dropdown provides dropdown/select components with single and multi-select support.
Package menu provides navigation and context menu components.
Package menu provides navigation and context menu components.
Package modal provides modal/dialog components.
Package modal provides modal/dialog components.
Package popover provides rich content popover components.
Package popover provides rich content popover components.
Package progress provides progress bar and spinner components.
Package progress provides progress bar and spinner components.
Package rating provides star rating components.
Package rating provides star rating components.
Package skeleton provides loading placeholder components.
Package skeleton provides loading placeholder components.
Package styles provides the style adapter system for swappable CSS frameworks.
Package styles provides the style adapter system for swappable CSS frameworks.
tailwind
Package tailwind provides a Tailwind CSS style adapter.
Package tailwind provides a Tailwind CSS style adapter.
Package tabs provides tab navigation components for organizing content.
Package tabs provides tab navigation components for organizing content.
Package tagsinput provides a tag/chip input component for entering multiple values.
Package tagsinput provides a tag/chip input component for entering multiple values.
Package timeline provides timeline components for the LiveTemplate framework.
Package timeline provides timeline components for the LiveTemplate framework.
Package timepicker provides time selection components.
Package timepicker provides time selection components.
Package toast provides notification/toast components for displaying messages.
Package toast provides notification/toast components for displaying messages.
Package toggle provides toggle/switch components.
Package toggle provides toggle/switch components.
Package tooltip provides tooltip/hint components.
Package tooltip provides tooltip/hint components.

Jump to

Keyboard shortcuts

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