buttongroup

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: 5 Imported by: 2

Documentation

Overview

Package buttongroup implements button groups.

templ: version: v0.2.793

Index

Examples

Constants

This section is empty.

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/buttongroup"
	"github.com/jfbus/templui/components/icon"
	"github.com/jfbus/templui/components/size"
	"github.com/jfbus/templui/components/style"
)

func main() {
	c := buttongroup.C(buttongroup.D{
		Size: size.S,
		Buttons: []button.D{
			{
				Icon:  icon.ArrowDownNarrowWide,
				Label: "Sort",
				Style: button.StyleHideLabelAlways,
				CustomStyle: style.Custom{
					"button": style.D{
						style.ReplaceVariants("bg", "bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600"),
					},
				},
				Attributes: templ.Attributes{
					"@click": "$dispatch('input', '')",
				},
			},
			{
				Icon:  icon.Heart,
				Label: "Rating",
				Style: button.StyleHideLabelAlways,
				Attributes: templ.Attributes{
					"@click": "$dispatch('input', 'rating')",
				},
			},
			{
				Icon:  icon.Banknote,
				Label: "Price",
				Style: button.StyleHideLabelAlways,
				Attributes: templ.Attributes{
					"@click": "$dispatch('input', 'price')",
				},
			},
		},
		Attributes: templ.Attributes{
			"x-model": "sort",
		},
	})
	_ = c.Render(context.TODO(), os.Stdout)
}

Types

type D

type D struct {
	// Buttons is the list of buttons to display.
	//playground:import:github.com/jfbus/templui/components/button
	//playground:default:[]button.D{{Label:"A"},{Label:"B"},{Label:"C"},{Label:"D"}}
	Buttons []button.D
	// Size defines the buttons size (shortcut for Buttons.Size).
	Size size.Size
	// CustomStyle defines a custom style.
	// 	style.Custom{
	// 		"buttongroup":        style.D{style.Add("...")},
	//		"buttongroup/button": style.D{style.Add("...")},
	//	}
	CustomStyle style.Custom
	// Attributes stores additional attributes (e.g. HTMX attributes).
	Attributes templ.Attributes
}

Jump to

Keyboard shortcuts

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