swap

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction string

Direction represents the possible scroll direction values for the show and scroll modifiers

const (
	DirectionTop    Direction = "top"
	DirectionBottom Direction = "bottom"
)

type Option

type Option func(*Style)

func FocusScroll

func FocusScroll(val bool) Option

func IgnoreTitle

func IgnoreTitle() Option

func Scroll

func Scroll(direction Direction) Option

func ScrollTo

func ScrollTo(selector string, direction Direction) Option

func SettleAfter

func SettleAfter(d time.Duration) Option

func Show

func Show(direction Direction) Option

func ShowNone

func ShowNone() Option

func ShowTo

func ShowTo(selector string, direction Direction) Option

func SwapAfter

func SwapAfter(d time.Duration) Option

func Transition

func Transition(val bool) Option

type Style

type Style struct {
	// contains filtered or unexported fields
}

Style represents an HTMX swap style that can be used to instruct HTMX how to swap content.

For more information, see: https://htmx.org/attributes/hx-swap

func AfterBegin

func AfterBegin(opt ...Option) *Style

AfterBegin Inserts the response before the first child of the target element

func AfterEnd

func AfterEnd(opt ...Option) *Style

AfterEnd Inserts the response after the target element

func BeforeBegin

func BeforeBegin(opt ...Option) *Style

BeforeBegin Inserts the response before the target element

func BeforeEnd

func BeforeEnd(opt ...Option) *Style

BeforeEnd Inserts the response after the last child of the target element

func Delete

func Delete(opt ...Option) *Style

Delete Deletes the target element regardless of the response

func InnerHTML

func InnerHTML(opt ...Option) *Style

InnerHTML replaces the inner HTML of the target element

Example
package main

import (
	"fmt"
	"time"

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

func main() {
	// For simple swaps, use any of the style functions alone
	s1 := swap.InnerHTML()

	// For more complex swaps, use any of the style functions with the options pattern
	s2 := swap.AfterBegin(
		swap.Transition(true),
		swap.IgnoreTitle(),
		swap.SwapAfter(time.Second*2),
	)

	fmt.Println(s1.String())
	fmt.Println(s2.String())

}
Output:

innerHTML
afterbegin transition:true swap:2s ignoreTitle:true

func None

func None(opt ...Option) *Style

None Instructs HTMX not to append content from the response. However, out of band swaps will still be processed.

func OuterHTML

func OuterHTML(opt ...Option) *Style

OuterHTML replaces the entire target element with the response

func (*Style) String

func (s *Style) String() string

String returns the string representation of the Style by combining the style and space separated modifiers

Jump to

Keyboard shortcuts

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