location

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Location

type Location struct {
	// The path to navigate to
	Path string `json:"path"`

	// The event that triggered the request
	Event string `json:"event,omitempty"`

	// The type of request
	Handler string `json:"handler,omitempty"`

	// The headers to submit with the request
	Headers map[string]string `json:"headers,omitempty"`

	// The CSS selector to target the content to swap
	Select string `json:"select,omitempty"`

	// The source element of the request
	Source string `json:"source,omitempty"`

	// The type of swap to perform
	Swap string `json:"swap,omitempty"`

	// The target element to swap content into
	Target string `json:"target,omitempty"`

	// The values to submit with the request
	Values map[string]string `json:"values,omitempty"`
	// contains filtered or unexported fields
}

Location is a struct that represents a location to navigate to within HTMX. See the https://htmx.org/headers/hx-location/ documentation for more information.

func NewLocation

func NewLocation(path string, opt ...Option) *Location

NewLocation creates a new Location struct with the given path and options

Example
package main

import (
	"fmt"

	"github.com/patrickward/hop/render/htmx/location"
	"github.com/patrickward/hop/render/htmx/swap"
)

func main() {
	// For simple location strings, use NewLocation with a single path parameter
	loc1 := location.NewLocation("/testpath")

	// For more complex location strings with context, use NewLocation with the options pattern
	loc2 := location.NewLocation(
		"/testpath",
		location.Event("click"),
		location.Handler("handleClick"),
		location.Headers(map[string]string{"header": "value"}),
		location.Select("#foobar"),
		location.Source("source"),
		location.Swap(swap.InnerHTML(swap.Transition(true), swap.IgnoreTitle())),
		location.Target("target"),
		location.Values(map[string]string{"foo": "bar"}),
	)

	fmt.Println(loc1.String())
	fmt.Println(loc2.String())

}
Output:

/testpath
{"path":"/testpath","event":"click","handler":"handleClick","headers":{"header":"value"},"select":"#foobar","source":"source","swap":"innerHTML transition:true ignoreTitle:true","target":"target","values":{"foo":"bar"}}

func (*Location) String

func (hxl *Location) String() string

String encodes the Location struct into a json string

type Option

type Option func(*Location)

func Event

func Event(event string) Option

Event returns an Option that sets the event field of the Location struct

func Handler

func Handler(handler string) Option

Handler returns an Option that sets the handler field of the Location struct

func Headers

func Headers(headers map[string]string) Option

Headers returns an Option that sets the headers field of the Location struct

func Select

func Select(selectValue string) Option

Select returns an Option that sets the select field of the Location struct

func Source

func Source(source string) Option

Source returns an Option that sets the source field of the Location struct

func Swap

func Swap(swap *swap.Style) Option

Swap returns an Option that sets the swap field of the Location struct

func Target

func Target(target string) Option

Target returns an Option that sets the target field of the Location struct

func Values

func Values(values map[string]string) Option

Values returns an Option that sets the values field of the Location struct

Jump to

Keyboard shortcuts

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