table

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package table implements tables.

templ: version: v0.2.793

Index

Examples

Constants

View Source
const (
	StyleStripedRows       style.Style = 1 << 8
	StyleNoBorder          style.Style = 1 << 9
	StyleAddHighlightHover style.Style = 1 << 10
)

Variables

This section is empty.

Functions

func C

func C(def D) templ.Component
Example
package main

import (
	"context"
	"os"

	"github.com/a-h/templ"
	"github.com/jfbus/templui/components/button"
	"github.com/jfbus/templui/components/style"
	"github.com/jfbus/templui/components/table"
	"github.com/jfbus/templui/components/table/cell"
	"github.com/jfbus/templui/components/table/row"
)

func main() {
	c := table.C(table.D{
		Style: table.StyleStripedRows,
		Header: &row.D{
			Cells: []string{"Email", "Name", "Status", ""},
		},
		Rows: []row.D{{
			Cells: []any{
				"John Doe",
				"john.doe@example.com",
				"active",
				cell.D{
					Content: button.C(button.D{
						Label: "disable",
						Attributes: templ.Attributes{
							"hx-delete": "/users/1",
						},
					}),
				},
			},
		}},
		CustomStyle: style.Custom{
			"table/cell": style.D{
				style.Set("text-center"),
			},
		},
	})
	_ = c.Render(context.TODO(), os.Stdout)
}
Output:

Types

type D

type D struct {
	// Style defines the table style.
	Style style.Style
	// Header defines an optional header row (thead).
	//playground:import:github.com/jfbus/templui/components/table/row
	//playground:default:&row.D{Cells: []string{"Name", "Description", ""}}
	Header *row.D
	// Rows defines the body rows (tbody).
	//playground:default:[]row.D{{Cells: []string{"Lorem", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.", ""}},{Cells: []string{"Ipsum", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.", ""}},{Cells: []string{"Dolor", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.", ""}}}
	Rows []row.D
	// Footer defines an optional footer fow (tfoot).
	Footer *row.D
	// CustomStyle defines a custom style.
	// 	style.Custom{
	// 		"table":             style.D{style.Add("...")},
	// 		"table/header":       style.D{style.Add("...")},
	// 		"table/row": style.D{style.Add("...")},
	// 		"table/cell":     style.D{style.Add("...")},
	// 		"table/footer":       style.D{style.Add("...")},
	//	}
	CustomStyle style.Custom
}

D is the table definition.

Directories

Path Synopsis
templ: version: v0.2.793
templ: version: v0.2.793
templ: version: v0.2.793
templ: version: v0.2.793

Jump to

Keyboard shortcuts

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