Class: Plutonium::UI::Form::Components::Currency
- Inherits:
-
Phlexi::Form::Components::Input
- Object
- Phlexi::Form::Components::Input
- Plutonium::UI::Form::Components::Currency
- Defined in:
- lib/plutonium/ui/form/components/currency.rb
Overview
A numeric (money) input with an OPTIONAL currency-unit prefix. The unit
is resolved by the SAME rules as the currency display
(Display::Components::Currency.resolve_unit), so the input and the
show/index/summary render the same symbol: an explicit unit: (a
literal "£", a Symbol read off the record, or false for none) → the
record's has_cents unit → default_currency_unit / the i18n default.
When nothing resolves (or unit: false) the prefix is omitted and it's
a plain number input.
input :price, as: :currency # → configured/i18n default unit
input :price, as: :currency, unit: "£"
input :price, as: :currency, unit: false # no prefix
Instance Method Summary collapse
Instance Method Details
#view_template ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/plutonium/ui/form/components/currency.rb', line 20 def view_template return super if @unit_prefix.blank? # Overlay the unit at the input's left edge; the currency-input # Stimulus controller measures this prefix and sets the input's # left padding to match, so digits always clear it whatever the # symbol's width ("$" vs "GH₵"). div(class: "relative", data: {controller: "currency-input"}) do span( class: "pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3 text-sm text-[var(--pu-text-muted)]", aria_hidden: "true", data: {currency_input_target: "prefix"} ) { plain @unit_prefix } super end end |