// templui component dropdown - version: v0.84.0 installed by templui v0.84.0 package dropdown import ( "context" "fmt" "git.jmbit.de/jmb/scanfile/server/web/templui/components/popover" "git.jmbit.de/jmb/scanfile/server/web/templui/utils" ) type contextKey string var ( contentIDKey contextKey = "contentID" subContentIDKey contextKey = "subContentID" ) type Props struct { ID string Class string Attributes templ.Attributes } type TriggerProps struct { ID string Class string Attributes templ.Attributes } type ContentProps struct { ID string Class string Attributes templ.Attributes Width string MaxHeight string Align string Side string } type GroupProps struct { ID string Class string Attributes templ.Attributes } type LabelProps struct { ID string Class string Attributes templ.Attributes } type ItemProps struct { ID string Class string Attributes templ.Attributes Disabled bool Href string Target string PreventClose bool } type SeparatorProps struct { ID string Class string Attributes templ.Attributes } type ShortcutProps struct { ID string Class string Attributes templ.Attributes } type SubProps struct { ID string Class string Attributes templ.Attributes } type SubTriggerProps struct { ID string Class string Attributes templ.Attributes } type SubContentProps struct { ID string Class string Attributes templ.Attributes } type PortalProps struct { ID string Class string Attributes templ.Attributes } templ Dropdown(props ...Props) { {{ var p Props if len(props) > 0 { p = props[0] } contentID := p.ID if contentID == "" { contentID = utils.RandomID() } ctx = context.WithValue(ctx, contentIDKey, contentID) }} { children... } } templ Trigger(props ...TriggerProps) { {{ var p TriggerProps if len(props) > 0 { p = props[0] } contentID, ok := ctx.Value(contentIDKey).(string) if !ok { contentID = "fallback-content-id" } }} @popover.Trigger(popover.TriggerProps{ ID: p.ID, For: contentID, TriggerType: popover.TriggerTypeClick, }) { { children... } } } templ Content(props ...ContentProps) { {{ var p ContentProps }} if len(props) > 0 { {{ p = props[0] }} } {{ contentID, ok := ctx.Value(contentIDKey).(string) }} if !ok { {{ contentID = "fallback-content-id" }} // Must match fallback in Trigger } {{ var maxHeight string = "300px" if p.MaxHeight != "" { maxHeight = p.MaxHeight } maxHeightClass := fmt.Sprintf("max-h-[%s]", maxHeight) }} @popover.Content(popover.ContentProps{ ID: contentID, Placement: popover.PlacementBottomStart, Offset: 4, Class: utils.TwMerge( "z-50 rounded-md bg-popover p-1 shadow-md focus:outline-none overflow-auto", "border border-border", "min-w-[8rem]", maxHeightClass, p.Width, p.Class, ), Attributes: p.Attributes, }) { { children... } } } templ Group(props ...GroupProps) { {{ var p GroupProps }} if len(props) > 0 { {{ p = props[0] }} }