// 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] }} }
{ children... }
} templ Label(props ...LabelProps) { {{ var p LabelProps }} if len(props) > 0 { {{ p = props[0] }} }
{ children... }
} templ Item(props ...ItemProps) { {{ var p ItemProps }} if len(props) > 0 { {{ p = props[0] }} } if p.ID == "" { {{ p.ID = utils.RandomID() }} } if p.Href != "" { { children... } } else { } } templ Separator(props ...SeparatorProps) { {{ var p SeparatorProps }} if len(props) > 0 { {{ p = props[0] }} } } templ Shortcut(props ...ShortcutProps) { {{ var p ShortcutProps }} if len(props) > 0 { {{ p = props[0] }} } { children... } } templ Sub(props ...SubProps) { {{ var p SubProps if len(props) > 0 { p = props[0] } subContentID := p.ID if subContentID == "" { subContentID = utils.RandomID() } ctx = context.WithValue(ctx, subContentIDKey, subContentID) }}
{ children... }
} templ SubTrigger(props ...SubTriggerProps) { {{ var p SubTriggerProps if len(props) > 0 { p = props[0] } subContentID, ok := ctx.Value(subContentIDKey).(string) if !ok { subContentID = "fallback-subcontent-id" } }} @popover.Trigger(popover.TriggerProps{ ID: p.ID, For: subContentID, TriggerType: popover.TriggerTypeHover, }) { } } templ SubContent(props ...SubContentProps) { {{ var p SubContentProps if len(props) > 0 { p = props[0] } subContentID, ok := ctx.Value(subContentIDKey).(string) if !ok { subContentID = "fallback-subcontent-id" } }} @popover.Content(popover.ContentProps{ ID: subContentID, Placement: popover.PlacementRightStart, Offset: -4, // Adjust as needed HoverDelay: 100, // ms HoverOutDelay: 200, // ms Class: utils.TwMerge( "z-[9999] min-w-[8rem] rounded-md border bg-popover p-1 shadow-lg", p.Class, ), Attributes: p.Attributes, }) { { children... } } } templ Script() { }