Documentation
¶
Overview ¶
templ: version: v0.3.977
Index ¶
- Constants
- func DecimalHandler() http.HandlerFunc
- func DecimalInput(props DecimalProps) templ.Component
- func DecimalRoute() func(chi.Router)
- func FormatAmount(val float64) string
- func MoneyHandler(allowedCurrencies ...string) http.HandlerFunc
- func MoneyInput(props MoneyProps) templ.Component
- func MoneyRoute(allowedCurrencies ...string) func(chi.Router)
- type DecimalProps
- type MoneyProps
- type ParsedAmount
- type ParsedMoney
Constants ¶
const DecimalPath = "/parse/decimal"
DecimalPath is the standard handler path for decimal parsing.
const MoneyPath = "/parse/money"
MoneyPath is the standard handler path for money parsing.
Variables ¶
This section is empty.
Functions ¶
func DecimalHandler ¶
func DecimalHandler() http.HandlerFunc
DecimalHandler returns an http.HandlerFunc that parses a numeric value (supporting shorthand like 5k, 1.5M) and patches the signals with the formatted result.
Mount at a dedicated path:
r.Get(moneyinput.DecimalPath, moneyinput.DecimalHandler())
func DecimalInput ¶
func DecimalInput(props DecimalProps) templ.Component
DecimalInput renders a text input that parses numeric shorthand (5k, 1.5M, 1,234.56) via server-side Datastar SSE. The parsed and formatted result is displayed inline.
func DecimalRoute ¶ added in v0.0.31
DecimalRoute returns a RouteOption that registers the decimal parser handler.
func FormatAmount ¶
FormatAmount formats a float64 with 2 decimal places and thousands separators.
func MoneyHandler ¶
func MoneyHandler(allowedCurrencies ...string) http.HandlerFunc
MoneyHandler returns an http.HandlerFunc that parses a money value (e.g., "USD 5k", "100 EUR") and patches the signals with the formatted amount and detected currency.
If allowedCurrencies is provided, only those currencies are accepted.
Mount at a dedicated path:
r.Get(moneyinput.MoneyPath, moneyinput.MoneyHandler("USD", "EUR"))
func MoneyInput ¶
func MoneyInput(props MoneyProps) templ.Component
MoneyInput renders a text input that parses monetary values with optional currency codes (e.g., "USD 5k", "100 EUR") via server-side Datastar SSE. The parsed amount and detected currency are displayed inline.
func MoneyRoute ¶ added in v0.0.31
MoneyRoute returns a RouteOption that registers the money parser handler. If allowedCurrencies is provided, only those currencies are accepted.
Types ¶
type DecimalProps ¶
type DecimalProps struct {
// ID uniquely identifies this component instance. Required.
ID string
// Class adds additional CSS classes to the input element.
Class string
// Attributes adds arbitrary HTML attributes to the input element.
Attributes templ.Attributes
// Name is the form field name attribute.
Name string
// Placeholder is the input placeholder text.
Placeholder string
// Value is the initial input value.
Value string
// ParseURL is the endpoint path for server-side parsing.
// The component appends "?id=<ID>" automatically.
ParseURL string
// DebounceMs is the debounce delay in milliseconds. Defaults to 500.
DebounceMs int
}
DecimalProps configures a decimal input field.
type MoneyProps ¶
type MoneyProps struct {
// ID uniquely identifies this component instance. Required.
ID string
// Class adds additional CSS classes to the input element.
Class string
// Attributes adds arbitrary HTML attributes to the input element.
Attributes templ.Attributes
// Name is the form field name attribute.
Name string
// Placeholder is the input placeholder text.
Placeholder string
// Value is the initial input value.
Value string
// ParseURL is the endpoint path for server-side parsing.
// The component appends "?id=<ID>" automatically.
ParseURL string
// DebounceMs is the debounce delay in milliseconds. Defaults to 500.
DebounceMs int
}
MoneyProps configures a money input field with currency support.
type ParsedAmount ¶
ParsedAmount holds the result of parsing a numeric string.
func ParseAmount ¶
func ParseAmount(raw string) ParsedAmount
ParseAmount parses a string into a float64 amount. Handles plain numbers, thousands separators, and shorthand suffixes (k, M, B). Returns Valid=true with zero Value for empty input.
type ParsedMoney ¶
ParsedMoney holds the result of parsing a money string.
func ParseMoney ¶
func ParseMoney(raw string, allowedCurrencies []string) ParsedMoney
ParseMoney parses a string that may contain a currency code and amount. Accepts "USD 100", "100 EUR", or plain "100". If allowedCurrencies is non-empty, the detected currency must be in the list.