display

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 11 Imported by: 4

Documentation

Overview

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

Package display provides button components.

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

Package display provides UI components for data visualization and interactive elements including cards, tables, tabs, dropdowns, modals, tooltips, avatars, badges, and more.

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

Package display provides modal dialog components and related functionality.

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accordion

func Accordion(props AccordionProps) templ.Component

Accordion renders a collapsible accordion with accessible markup

@display.Accordion(display.AccordionProps{
   Items: []display.AccordionItem{
     {ID: "faq1", Title: "What is this?", Open: true},
     {ID: "faq2", Title: "How does it work?"},
   },
})

func Avatar

func Avatar(props AvatarProps) templ.Component

Avatar renders a user avatar with image, initials, or fallback

@display.Avatar(display.AvatarProps{Src: "/avatar.jpg", Alt: "Alice"})

func Badge

func Badge(props BadgeProps) templ.Component

Badge renders a compact status label

@display.Badge(display.BadgeProps{Text: "Active", Type: display.BadgeSuccess, Dot: true})
Example
package main

import (
	"bytes"
	"context"
	"fmt"

	"github.com/larsartmann/templ-components/display"
)

func main() {
	props := display.DefaultBadgeProps()
	props.Text = "Beta"
	props.Type = display.BadgeInfo

	var buf bytes.Buffer
	_ = display.Badge(props).Render(context.Background(), &buf)
	fmt.Println(buf.String())
	// Output will contain the badge text and Tailwind classes
}

func Button

func Button(props ButtonProps) templ.Component

Button renders a button or link styled as a button. When Href is set, renders as an anchor tag; otherwise renders as a button element.

@display.Button(display.DefaultButtonProps())
@display.Button(display.ButtonProps{Text: "Save", Type: display.ButtonHTMLSubmit})
@display.Button(display.ButtonProps{Text: "Docs", Href: "/docs", Variant: display.ButtonSecondary})

func Card

func Card(props CardProps) templ.Component

Card renders a bordered card with optional header and footer

@display.Card(display.CardProps{Title: "Users", Subtitle: "Manage your users"}) {
   <p>Card content goes here</p>
 }
Example
package main

import (
	"bytes"
	"context"
	"fmt"

	"github.com/larsartmann/templ-components/display"
)

func main() {
	props := display.DefaultCardProps()
	props.Title = "Hello World"

	var buf bytes.Buffer
	_ = display.Card(props).Render(context.Background(), &buf)
	fmt.Println(buf.String())
}

func DefinitionList added in v0.6.0

func DefinitionList(props DefinitionListProps) templ.Component

DefinitionList renders a two-column <dl> with term labels on the left and detail values on the right. Ideal for metadata tables, settings summaries, and key-value display.

@display.DefinitionList(display.DefinitionListProps{
   Items: []display.DefinitionItem{
     {Term: "Email", Detail: "alice@example.com"},
     {Term: "Status", DetailComponent: display.Badge(display.BadgeProps{Text: "Active", Type: display.BadgeSuccess})},
   },
})

func Drawer added in v0.3.0

func Drawer(props DrawerProps) templ.Component

Drawer renders an accessible side panel that slides in from the left or right

@display.Drawer(display.DrawerProps{Title: "Settings", ID: "settings-drawer", Side: display.DrawerRight, Open: true, Nonce: nonce}) {
   <p>Drawer content</p>
}

The panel body is intentionally not shared with Modal: the transition (translate-x) and positioning classes differ, with conditional templ.KV classes inline. overlayShell already owns the shared a11y shell + JS.

func Dropdown(props DropdownProps) templ.Component

Dropdown renders a button-triggered action menu

@display.Dropdown(display.DropdownProps{
   Label: "Actions",
   Items: []display.DropdownItem{
     {Text: "Edit", Href: "/edit"},
     {Text: "Delete", Href: "/delete"},
   },
})

func EmptyState

func EmptyState(props EmptyStateProps) templ.Component

EmptyState renders a centered empty state with icon, title, description, and optional action

@display.EmptyState(display.EmptyStateProps{
   Title: "No repositories",
   Description: "Connect your first repository to get started.",
   Icon: "folder",
   ActionText: "Connect Repository",
   ActionHref: "/repos/connect",
})

func ListNote added in v0.6.0

func ListNote(props ListNoteProps) templ.Component

ListNote renders a "Showing N of M" hint when a list is truncated (Total > Shown). Renders nothing when all rows fit.

@display.ListNote(display.ListNoteProps{Shown: 50, Total: 127})
func Modal(props ModalProps) templ.Component

Modal renders an accessible modal dialog with backdrop

@display.Modal(display.ModalProps{Title: "Confirm", ID: "confirm-modal", Nonce: nonce}) {
   <p>Are you sure?</p>
}

The panel body is intentionally not shared with Drawer: the transition (scale/opacity) and sizing classes differ, with conditional templ.KV classes inline. overlayShell already owns the shared a11y shell + JS.

func PageHeader(props PageHeaderProps) templ.Component

PageHeader renders a page-level header with title, optional subtitle, optional breadcrumb above, and an optional action slot on the right.

@display.PageHeader(display.PageHeaderProps{
   Title: "Users",
   Subtitle: "Manage user accounts",
   Action: display.Button(display.ButtonProps{Text: "New user", Href: "/users/new"}),
})

func SimpleCard

func SimpleCard(props SimpleCardProps) templ.Component

SimpleCard renders a card without header/footer for quick use. Internally composes through Card for consistent shell styling.

@display.SimpleCard(display.SimpleCardProps{}) {
   <p>Content</p>
 }

func SimpleEmptyState

func SimpleEmptyState(message string) templ.Component

SimpleEmptyState is a minimal empty state for inline use

@display.SimpleEmptyState("No items found")

func StatCard

func StatCard(props StatCardProps) templ.Component

StatCard renders a dashboard stat card with value, label, optional change indicator, and an optional leading icon tile.

@display.StatCard(display.StatCardProps{Label: "Users", Value: "1,204", Icon: icons.Users})
Example
package main

import (
	"bytes"
	"context"
	"fmt"

	"github.com/larsartmann/templ-components/display"
)

func main() {
	props := display.DefaultStatCardProps()
	props.Value = "$12,345"
	props.Label = "Total Revenue"
	props.Trend = display.TrendUp
	props.Change = "+12.5%"

	var buf bytes.Buffer
	_ = display.StatCard(props).Render(context.Background(), &buf)
	fmt.Println(buf.String())
}

func StatusBadge

func StatusBadge(status string) templ.Component

StatusBadge is a convenience wrapper for common status values Maps status strings to badge types automatically

@display.StatusBadge("active")

func Table

func Table(props TableProps) templ.Component

Table renders a responsive data table

@display.Table(display.TableProps{
   Headers: []string{"Name", "Email", "Role"},
   Rows: []display.TableRow{
     display.SimpleTableRow("Alice", "alice@example.com", "Admin"),
     display.SimpleTableRow("Bob", "bob@example.com", "User"),
   },
})

func Tabs

func Tabs(props TabsProps) templ.Component

Tabs renders a tabbed interface with accessible markup

@display.Tabs(display.TabsProps{
   ActiveTabID: "users",
   Tabs: []display.Tab{
     {ID: "users", Label: "Users"},
     {ID: "settings", Label: "Settings"},
   },
})

func Tooltip

func Tooltip(props TooltipProps) templ.Component

Tooltip wraps content in a hover-activated tooltip

@display.Tooltip(display.TooltipProps{Text: "More info"}) {
   <button>Hover me</button>
 }

Types

type AccordionItem

type AccordionItem struct {
	ID      string
	Title   string
	Content templ.Component
	Open    bool
}

AccordionItem represents a single collapsible panel

type AccordionProps

type AccordionProps struct {
	utils.BaseProps
	Items []AccordionItem
}

AccordionProps configures an accordion component

func DefaultAccordionProps

func DefaultAccordionProps() AccordionProps

DefaultAccordionProps returns sensible defaults

type AvatarProps

type AvatarProps struct {
	utils.BaseProps
	Src      string
	Alt      string
	Initials string
	Size     AvatarSize
	Shape    AvatarShape
	Status   AvatarStatus
}

AvatarProps configures an avatar component

func DefaultAvatarProps

func DefaultAvatarProps() AvatarProps

DefaultAvatarProps returns sensible defaults

type AvatarShape

type AvatarShape string

AvatarShape defines the shape of an avatar

const (
	AvatarShapeCircle AvatarShape = "circle"
	AvatarShapeSquare AvatarShape = "square"
)

type AvatarSize

type AvatarSize string

AvatarSize defines the size of an avatar

const (
	AvatarSizeXS AvatarSize = "xs"
	AvatarSizeSM AvatarSize = "sm"
	AvatarSizeMD AvatarSize = "md"
	AvatarSizeLG AvatarSize = "lg"
	AvatarSizeXL AvatarSize = "xl"
)

type AvatarStatus

type AvatarStatus string

AvatarStatus represents the online status indicator for an avatar

const (
	AvatarStatusNone    AvatarStatus = ""
	AvatarStatusOnline  AvatarStatus = "online"
	AvatarStatusOffline AvatarStatus = "offline"
)

type BadgeProps

type BadgeProps struct {
	utils.BaseProps
	Text string
	Type BadgeType
	Size BadgeSize
	Pill bool
	Dot  bool
	Href string
}

BadgeProps configures a status badge

func DefaultBadgeProps

func DefaultBadgeProps() BadgeProps

DefaultBadgeProps returns sensible defaults

type BadgeSize

type BadgeSize string

BadgeSize defines the size of a badge

const (
	BadgeSizeSM BadgeSize = "sm"
	BadgeSizeMD BadgeSize = "md"
	BadgeSizeLG BadgeSize = "lg"
)

type BadgeType

type BadgeType string

BadgeType defines the visual style of a badge

const (
	BadgePrimary BadgeType = "primary"
	BadgeSuccess BadgeType = "success"
	BadgeWarning BadgeType = "warning"
	BadgeError   BadgeType = "error"
	BadgeInfo    BadgeType = "info"
	BadgeNeutral BadgeType = "neutral"
)

type ButtonHTMLType added in v0.5.0

type ButtonHTMLType string

ButtonHTMLType is the HTML type attribute for a <button> element.

const (
	ButtonHTMLButton ButtonHTMLType = "button"
	ButtonHTMLSubmit ButtonHTMLType = "submit"
	ButtonHTMLReset  ButtonHTMLType = "reset"
)

Button HTML type constants

type ButtonProps

type ButtonProps struct {
	utils.BaseProps
	Text     string
	Type     ButtonHTMLType // button, submit, reset (default: button; ignored when Href is set)
	Href     string         // if set, renders as <a> instead of <button>
	Variant  ButtonType     // default: Primary
	Size     ButtonSize     // default: MD
	Disabled bool
	Icon     templ.Component
	External bool // adds target="_blank" and rel="noopener noreferrer" for links
}

ButtonProps configures a button or link styled as a button

func DefaultButtonProps

func DefaultButtonProps() ButtonProps

DefaultButtonProps returns sensible defaults

type ButtonSize

type ButtonSize string

ButtonSize defines the size of a button

const (
	ButtonSizeSM ButtonSize = "sm"
	ButtonSizeMD ButtonSize = "md"
	ButtonSizeLG ButtonSize = "lg"
)

Button size constants

type ButtonType

type ButtonType string

ButtonType defines the visual style of a button

const (
	ButtonPrimary   ButtonType = "primary"
	ButtonSecondary ButtonType = "secondary"
	ButtonDanger    ButtonType = "danger"
	ButtonGhost     ButtonType = "ghost"
	ButtonLink      ButtonType = "link"
)

Button variant constants

type CardPadding

type CardPadding string

CardPadding defines the internal padding of a card

const (
	CardPaddingNone CardPadding = "none"
	CardPaddingSM   CardPadding = "sm"
	CardPaddingMD   CardPadding = "md"
	CardPaddingLG   CardPadding = "lg"
)

type CardProps

type CardProps struct {
	utils.BaseProps
	Title        string
	Subtitle     string
	Footer       templ.Component
	HeaderAction templ.Component
	Padding      CardPadding
}

CardProps configures a card container

func DefaultCardProps

func DefaultCardProps() CardProps

DefaultCardProps returns sensible defaults

type DefinitionItem added in v0.6.0

type DefinitionItem struct {
	Term   string
	Detail string
	// DetailComponent overrides Detail when set — use for badges, links, or
	// any rich content instead of plain text.
	DetailComponent templ.Component
}

DefinitionItem is one term-detail pair in a DefinitionList.

type DefinitionListProps added in v0.6.0

type DefinitionListProps struct {
	utils.BaseProps
	Items []DefinitionItem
}

DefinitionListProps configures a two-column term/detail list.

func DefaultDefinitionListProps added in v0.6.0

func DefaultDefinitionListProps() DefinitionListProps

DefaultDefinitionListProps returns sensible defaults

type DrawerProps added in v0.3.0

type DrawerProps struct {
	utils.BaseProps
	Title string
	Open  bool
	Side  DrawerSide
	Size  DrawerSize
}

DrawerProps configures a drawer (side panel) component

func DefaultDrawerProps added in v0.3.0

func DefaultDrawerProps() DrawerProps

DefaultDrawerProps returns sensible defaults

type DrawerSide added in v0.3.0

type DrawerSide string

DrawerSide defines which side the drawer slides in from

const (
	DrawerLeft  DrawerSide = "left"
	DrawerRight DrawerSide = "right"
)

type DrawerSize added in v0.3.0

type DrawerSize string

DrawerSize defines the width of the drawer panel

const (
	DrawerSizeSM  DrawerSize = "sm"
	DrawerSizeMD  DrawerSize = "md"
	DrawerSizeLG  DrawerSize = "lg"
	DrawerSizeXL  DrawerSize = "xl"
	DrawerSize2XL DrawerSize = "full" // largest available width (max-w-2xl)
	DrawerFull    DrawerSize = "full" // Deprecated: use DrawerSize2XL; "full" is a misnomer (capped at max-w-2xl)
)

Drawer size constants. DrawerSize2XL is the largest size (max-w-2xl); DrawerFull is a deprecated alias kept for backward compatibility.

type DropdownItem struct {
	Text     string
	Href     string
	Icon     icons.Name
	Kind     DropdownItemKind
	External bool
	Disabled bool
	Attrs    templ.Attributes
}

DropdownItem represents a single action in a dropdown menu

func (item DropdownItem) IsLink() bool

IsLink returns true if the item should render as a link. When Kind is unset, falls back to Href-based discrimination for backward compat.

type DropdownItemKind string

DropdownItemKind determines how a dropdown item is rendered

const (
	// DropdownItemLink renders the item as an anchor (<a>) element
	DropdownItemLink DropdownItemKind = "link"
	// DropdownItemButton renders the item as a <button> element
	DropdownItemButton DropdownItemKind = "button"
)
type DropdownPosition string

DropdownPosition defines where the dropdown menu appears

const (
	DropdownPositionLeft  DropdownPosition = "left"
	DropdownPositionRight DropdownPosition = "right"
)
type DropdownProps struct {
	utils.BaseProps
	Label    string
	Items    []DropdownItem
	Position DropdownPosition
}

DropdownProps configures a dropdown action menu

func DefaultDropdownProps

func DefaultDropdownProps() DropdownProps

DefaultDropdownProps returns sensible defaults

type EmptyStateProps

type EmptyStateProps struct {
	utils.BaseProps
	Title       string
	Description string
	Icon        icons.Name
	ActionText  string
	ActionHref  string
	ActionAttrs templ.Attributes
}

EmptyStateProps configures an empty state illustration

func DefaultEmptyStateProps

func DefaultEmptyStateProps() EmptyStateProps

DefaultEmptyStateProps returns sensible defaults

type ListNoteProps added in v0.6.0

type ListNoteProps struct {
	utils.BaseProps
	// Shown is the number of items currently rendered.
	Shown int
	// Total is the unfiltered/cap-exceeding match count.
	Total int
}

ListNoteProps configures a "Showing N of M" truncation notice.

type ModalProps

type ModalProps struct {
	utils.BaseProps
	Title string
	Open  bool
	Size  ModalSize
}

ModalProps configures a modal dialog

func DefaultModalProps

func DefaultModalProps() ModalProps

DefaultModalProps returns sensible defaults

type ModalSize

type ModalSize string

ModalSize defines the width of a modal dialog

const (
	ModalSizeSM   ModalSize = "sm"
	ModalSizeMD   ModalSize = "md"
	ModalSizeLG   ModalSize = "lg"
	ModalSizeXL   ModalSize = "xl"
	ModalSize2XL  ModalSize = "full" // largest available width (max-w-4xl)
	ModalSizeFull ModalSize = "full" // Deprecated: use ModalSize2XL; "full" is a misnomer (capped at max-w-4xl)
)

Modal size constants. ModalSize2XL is the largest size (max-w-4xl); ModalSizeFull is a deprecated alias kept for backward compatibility.

type PageHeaderProps added in v0.6.0

type PageHeaderProps struct {
	utils.BaseProps
	Title string
	// Subtitle renders below the title in muted text.
	Subtitle string
	// Breadcrumb renders above the title (optional). Pass a navigation.Breadcrumbs
	// component or any custom breadcrumb markup.
	Breadcrumb templ.Component
	// Action renders on the right side of the title row (optional). Use for
	// primary buttons, back links, or status badges.
	Action templ.Component
}

PageHeaderProps configures a page-level header with title, optional subtitle, and optional breadcrumb/action slots.

func DefaultPageHeaderProps added in v0.6.0

func DefaultPageHeaderProps() PageHeaderProps

DefaultPageHeaderProps returns sensible defaults

type SimpleCardProps

type SimpleCardProps struct {
	utils.BaseProps
	Padding CardPadding
}

SimpleCardProps configures a simple card without header/footer

func DefaultSimpleCardProps

func DefaultSimpleCardProps() SimpleCardProps

DefaultSimpleCardProps returns sensible defaults

type StatCardProps

type StatCardProps struct {
	utils.BaseProps
	Value  string
	Label  string
	Change string
	Trend  TrendDirection
	// Icon optionally renders a leading icon tile (e.g. icons.Users).
	Icon icons.Name
}

StatCardProps configures a dashboard stat card

func DefaultStatCardProps

func DefaultStatCardProps() StatCardProps

DefaultStatCardProps returns sensible defaults

type Tab

type Tab struct {
	ID      string
	Label   string
	Content templ.Component
}

Tab represents a single tab panel

type TableCell

type TableCell struct {
	Text    string
	Content templ.Component
}

TableCell represents a single cell in a table row. When Content is set, it takes priority over Text for rendering.

type TableProps

type TableProps struct {
	utils.BaseProps
	Caption  string
	Headers  []string
	Rows     []TableRow
	Striped  bool
	Hover    bool
	Bordered bool
}

TableProps configures a data table

func DefaultTableProps

func DefaultTableProps() TableProps

DefaultTableProps returns sensible defaults

type TableRow

type TableRow struct {
	Cells []TableCell
}

TableRow represents a single row in a table

func SimpleTableRow

func SimpleTableRow(values ...string) TableRow

SimpleTableRow creates a row from string values for convenience

type TabsProps

type TabsProps struct {
	utils.BaseProps
	Tabs        []Tab
	ActiveTabID string
	Variant     TabsVariant
	ClientSide  bool
}

TabsProps configures a tab component

func DefaultTabsProps

func DefaultTabsProps() TabsProps

DefaultTabsProps returns sensible defaults

type TabsVariant

type TabsVariant string

TabsVariant defines the visual style of tabs

const (
	TabsDefault TabsVariant = "default"
	TabsPills   TabsVariant = "pills"
)

type TooltipPosition

type TooltipPosition string

TooltipPosition defines where the tooltip appears relative to the trigger

const (
	TooltipPositionTop    TooltipPosition = "top"
	TooltipPositionBottom TooltipPosition = "bottom"
	TooltipPositionLeft   TooltipPosition = "left"
	TooltipPositionRight  TooltipPosition = "right"
)

type TooltipProps

type TooltipProps struct {
	utils.BaseProps
	Text     string
	Position TooltipPosition
}

TooltipProps configures a tooltip component

func DefaultTooltipProps

func DefaultTooltipProps() TooltipProps

DefaultTooltipProps returns sensible defaults

type TrendDirection

type TrendDirection string

TrendDirection represents the direction of a stat change

const (
	TrendUp   TrendDirection = "up"
	TrendDown TrendDirection = "down"
	TrendNone TrendDirection = "none"
)

Jump to

Keyboard shortcuts

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