-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget.templ
52 lines (46 loc) · 994 Bytes
/
target.templ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gong
templ Target(opts ...TargetOption) {
{{
config := targetConfig{
trigger: TriggerNone,
}
for _, opt := range opts {
config = opt(config)
}
}}
<div
id={ buildComponentID(ctx, config.id) }
hx-get={ getContext(ctx).route.path }
hx-swap={ SwapInnerHTML }
hx-trigger={ config.trigger }
hx-target="this"
hx-headers={ buildHeaders(ctx, GongRequestTypeAction) }
class={ config.cssClass }
>
{ children... }
</div>
}
type targetConfig struct {
id string
trigger string
cssClass templ.CSSClass
}
type TargetOption func(c targetConfig) targetConfig
func TargetWithID(id string) TargetOption {
return func(c targetConfig) targetConfig {
c.id = id
return c
}
}
func TargetWithTrigger(trigger string) TargetOption {
return func(c targetConfig) targetConfig {
c.trigger = trigger
return c
}
}
func TargetWithCSSClass(cssClass templ.CSSClass) TargetOption {
return func(c targetConfig) targetConfig {
c.cssClass = cssClass
return c
}
}