Something went wrong. Try again.
Tea journaling on ATProto (alpha)
Something went wrong. Try again.
3.4 kB · 167 lines
at feat-explore
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168package components
import "strconv"
// TextInputProps defines properties for text inputstype TextInputProps struct { Name string Value string Placeholder string Required bool Class string Type string // "text", "email", "url", etc. Defaults to "text"}
// TextInput renders a text input fieldtempl TextInput(props TextInputProps) { <input type={ getInputType(props.Type) } name={ props.Name } value={ props.Value } placeholder={ props.Placeholder } class={ "form-input " + props.Class } if props.Required { required } />}
// Helper function to get input type, defaults to "text"func getInputType(t string) string { if t == "" { return "text" } return t}
// NumberInputProps defines properties for number inputstype NumberInputProps struct { Name string Value string Placeholder string Required bool Step string Min string Max string Class string}
// NumberInput renders a number input fieldtempl NumberInput(props NumberInputProps) { <input type="number" name={ props.Name } value={ props.Value } placeholder={ props.Placeholder } class={ "form-input " + props.Class } if props.Required { required } if props.Step != "" { step={ props.Step } } if props.Min != "" { min={ props.Min } } if props.Max != "" { max={ props.Max } } />}
// TextAreaProps defines properties for textarea inputstype TextAreaProps struct { Name string Value string Placeholder string Required bool Rows int Class string}
// TextArea renders a textarea input fieldtempl TextArea(props TextAreaProps) { <textarea name={ props.Name } placeholder={ props.Placeholder } class={ "form-textarea " + props.Class } rows={ getRowsAttr(props.Rows) } if props.Required { required } >{ props.Value }</textarea>}
// Helper function to get rows attributefunc getRowsAttr(rows int) string { if rows <= 0 { return "3" } return strconv.Itoa(rows)}
// SelectOption represents an option in a select dropdowntype SelectOption struct { Value string Label string Selected bool}
// SelectProps defines properties for select dropdownstype SelectProps struct { Name string Options []SelectOption Placeholder string Required bool Class string}
// Select renders a select dropdowntempl Select(props SelectProps) { <select name={ props.Name } class={ "form-select " + props.Class } if props.Required { required } > if props.Placeholder != "" { <option value="">{ props.Placeholder }</option> } for _, opt := range props.Options { <option value={ opt.Value } if opt.Selected { selected } > { opt.Label } </option> } </select>}
// FormFieldProps defines properties for a complete form field (label + input + helper)type FormFieldProps struct { Label string HelperText string Required bool}
// FormField wraps a form input with label and helper texttempl FormField(props FormFieldProps, input templ.Component) { <div> if props.Label != "" { <label class="form-label"> { props.Label } if props.Required { <span class="text-red-600">*</span> } </label> } @input if props.HelperText != "" { <p class="text-helper">{ props.HelperText }</p> } </div>}