-
Notifications
You must be signed in to change notification settings - Fork 0
/
popover.templ
39 lines (35 loc) · 1018 Bytes
/
popover.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
package appkit
type PopoverProps struct {
ID string
ButtonText string
OnClick string
OnSelect string
Options string
OptionsLabel string
}
templ Popover(props *PopoverProps) {
<div class="relative inline-block">
@Button(&ButtonProps{
Label: props.ButtonText,
OnClick: props.OnClick,
PopoverTarget: props.ID,
Small: true,
})
<div popover id={ props.ID }></div>
<div class="hidden absolute left-0 top-7 popover-menu border border-neutral-200 rounded-md px-1 py-0.5 w-full">
<ul>
<template x-for={ `option in ` + props.Options }>
<li class="px-2 py-1.5 font-medium text-base text-neutral-800 w-full rounded hover:bg-neutral-100">
<button class="w-full text-left" @click={ props.OnSelect + `(option)` } x-text={ `option.` + props.GetLabel() }></button>
</li>
</template>
</ul>
</div>
</div>
}
func (pp *PopoverProps) GetLabel() string {
if pp.OptionsLabel != "" {
return pp.OptionsLabel
}
return "label"
}