// templui component selectbox - version: main installed by templui v0.71.0 package selectbox import ( "context" "fmt" "git.jmbit.de/jmb/scanfile/server/web/templui/components/button" "git.jmbit.de/jmb/scanfile/server/web/templui/components/icon" "git.jmbit.de/jmb/scanfile/server/web/templui/components/popover" "git.jmbit.de/jmb/scanfile/server/web/templui/utils" "strconv" ) type contextKey string var contentIDKey contextKey = "contentID" type Props struct { ID string Class string Attributes templ.Attributes } type TriggerProps struct { ID string Class string Attributes templ.Attributes Name string Required bool Disabled bool HasError bool } type ValueProps struct { ID string Class string Attributes templ.Attributes Placeholder string } type ContentProps struct { ID string Class string Attributes templ.Attributes } 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 Value string Selected bool Disabled bool } templ SelectBox(props ...Props) { @Script() {{ var p Props if len(props) > 0 { p = props[0] } wrapperID := p.ID if wrapperID == "" { wrapperID = utils.RandomID() } contentID := fmt.Sprintf("%s-content", wrapperID) ctx = context.WithValue(ctx, contentIDKey, contentID) }}
@popover.Popover() { { 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-select-content-id" } }} @popover.Trigger(popover.TriggerProps{ For: contentID, TriggerType: popover.TriggerTypeClick, }) { @button.Button(button.Props{ ID: p.ID, Type: "button", Variant: button.VariantOutline, Class: utils.TwMerge( "w-full select-trigger flex items-center justify-between focus:ring-2 focus:ring-offset-2", utils.If(p.HasError, "border-destructive ring-destructive"), p.Class, ), Disabled: p.Disabled, Attributes: utils.MergeAttributes( templ.Attributes{ "data-content-id": contentID, "tabindex": "0", "required": strconv.FormatBool(p.Required), }, p.Attributes, ), }) { { children... } @icon.ChevronDown(icon.Props{ Size: 16, Class: "text-muted-foreground", }) } } } templ Value(props ...ValueProps) { {{ var p ValueProps }} if len(props) > 0 { {{ p = props[0] }} } if p.Placeholder != "" { { p.Placeholder } } { 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-select-content-id" } }} @popover.Content(popover.ContentProps{ ID: contentID, Placement: popover.PlacementBottomStart, Offset: 4, MatchWidth: true, Class: utils.TwMerge( "p-1 select-content z-50 overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md", "min-w-[var(--popover-trigger-width)] w-[var(--popover-trigger-width)]", p.Class, ), Attributes: utils.MergeAttributes( templ.Attributes{ "role": "listbox", "tabindex": "-1", }, 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] }} }
{ children... } @icon.Check(icon.Props{Size: 16})
} var handle = templ.NewOnceHandle() templ Script() { @handle.Once() { } }