Documentation
¶
Index ¶
- type Location
- type Option
- func Event(event string) Option
- func Handler(handler string) Option
- func Headers(headers map[string]string) Option
- func Select(selectValue string) Option
- func Source(source string) Option
- func Swap(swap *swap.Style) Option
- func Target(target string) Option
- func Values(values map[string]string) Option
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 ¶
NewLocation creates a new Location struct with the given path and options
Example ¶
package main
import (
"fmt"
"github.com/patrickward/hyperview/htmx/location"
"github.com/patrickward/hyperview/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"}}
type Option ¶
type Option func(*Location)
Click to show internal directories.
Click to hide internal directories.