Files
LazyPM/pkg/web/components/base/select.templ
2026-02-03 13:13:27 +01:00

68 lines
1.2 KiB
Plaintext

package base
type SelectProps struct {
ID string
Label string
Name string
Description string
Class string
Size string
Required bool
Options []SelectOption
Attrs templ.Attributes
}
type SelectOption struct {
Label string
Value string
Selected bool
Disabled bool
}
templ Select(props SelectProps) {
<fieldset class="fieldset">
if props.Label != "" {
<legend class="fieldset-legend">{ props.Label }</legend>
}
<select
class={
"select w-full",
props.Class,
templ.KV("select-xs", props.Size == "xs"),
templ.KV("select-sm", props.Size == "sm"),
templ.KV("select-lg", props.Size == "lg"),
templ.KV("select-xl", props.Size == "xl"),
}
if props.ID != "" {
id={ props.ID }
}
name={ props.Name }
if props.Required {
required
}
{ props.Attrs... }
>
@SelectOptions(props.Options)
</select>
if props.Description != "" {
<span class="label">{ props.Description }</span>
}
</fieldset>
}
templ SelectOptions(options []SelectOption) {
for i := range options {
<option
if options[i].Selected {
selected
}
if options[i].Disabled {
disabled
}
value={ options[i].Value }
>
{ options[i].Label }
</option>
}
}