mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 21:15:19 +02:00
Finalize transaction drawer, simplify money form helpers (#1191)
* Finalize transaction drawer, simplify money form helpers * Fix money form errors * Reusable disclosure helper, fix styles * Final style tweaks
This commit is contained in:
parent
730e58d763
commit
5942ce7e3c
16 changed files with 275 additions and 214 deletions
12
app/views/shared/_disclosure.html.erb
Normal file
12
app/views/shared/_disclosure.html.erb
Normal file
|
@ -0,0 +1,12 @@
|
|||
<%# locals: (title:, content:, open: true) %>
|
||||
|
||||
<details class="group space-y-2" <%= "open" if open %>>
|
||||
<summary class="flex list-none items-center justify-between rounded-xl px-3 py-2 text-xs font-medium
|
||||
uppercase text-gray-500 bg-gray-25 focus-visible:outline-none">
|
||||
<h3><%= title %></h3>
|
||||
<%= lucide_icon "chevron-down",
|
||||
class: "group-open:transform group-open:rotate-180 text-gray-500 w-5 h-5" %>
|
||||
</summary>
|
||||
|
||||
<%= content %>
|
||||
</details>
|
|
@ -1,26 +1,53 @@
|
|||
<%# locals: (form:, money_method:, default_currency:, disable_currency: false, hide_currency: false, label: nil, required: false) %>
|
||||
<%# locals: (form:, amount_method:, currency_method:, **options) %>
|
||||
|
||||
<% fallback_label = t(".money-label") %>
|
||||
<% currency = form.object ? (form.object.send(money_method)&.currency || Money::Currency.new(default_currency)) : Money::Currency.new(default_currency) %>
|
||||
<% currency_value = if form.object && form.object.respond_to?(currency_method)
|
||||
form.object.public_send(currency_method)
|
||||
end
|
||||
currency = Money::Currency.new(currency_value || options[:default_currency] || "USD") %>
|
||||
|
||||
<div class="form-field pr-0" data-controller="money-field">
|
||||
<%= form.label label || fallback_label, { class: "form-field__label" } %>
|
||||
<div class="form-field pr-0 <%= options[:container_class] %>" data-controller="money-field">
|
||||
<%= form.label options[:label] || t(".label"), class: "form-field__label" %>
|
||||
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="flex items-center grow gap-1">
|
||||
<span class="text-gray-500 text-sm" data-money-field-target="symbol"><%= currency.symbol %></span>
|
||||
<%= money_field form, money_method, { inline: true, "data-money-field-target" => "amount", default_currency: currency, required: required } %>
|
||||
<span class="text-gray-500 text-sm" data-money-field-target="symbol">
|
||||
<%= currency.symbol %>
|
||||
</span>
|
||||
|
||||
<%= form.number_field amount_method,
|
||||
class: "form-field__input",
|
||||
inline: true,
|
||||
placeholder: "100",
|
||||
value: if options[:value]
|
||||
sprintf("%.#{currency.default_precision}f", options[:value])
|
||||
elsif form.object && form.object.respond_to?(amount_method)
|
||||
form.object.public_send(amount_method)
|
||||
end,
|
||||
min: options[:min] || -99999999999999,
|
||||
max: options[:max] || 99999999999999,
|
||||
step: currency.step,
|
||||
data: {
|
||||
"money-field-target": "amount",
|
||||
action: "change->money-field#handleAmountChange",
|
||||
"auto-submit-form-target": ("auto" if options[:auto_submit])
|
||||
}.compact,
|
||||
required: options[:required] %>
|
||||
</div>
|
||||
<% unless hide_currency %>
|
||||
|
||||
<% unless options[:hide_currency] %>
|
||||
<div>
|
||||
<%= currency_select form, :currency, { inline: true, selected: currency.iso_code }, {
|
||||
class: "form-field__input text-right pr-8 disabled:text-gray-500",
|
||||
disabled: disable_currency,
|
||||
data: {
|
||||
"money-field-target" => "currency",
|
||||
action: "money-field#handleCurrencyChange"
|
||||
}
|
||||
} %>
|
||||
<%= form.select currency_method,
|
||||
currencies_for_select.map(&:iso_code),
|
||||
{ inline: true },
|
||||
{
|
||||
class: "w-fit pr-5 disabled:text-gray-400 form-field__input",
|
||||
disabled: options[:disable_currency],
|
||||
data: {
|
||||
"money-field-target": "currency",
|
||||
action: "change->money-field#handleCurrencyChange",
|
||||
"auto-submit-form-target": ("auto" if options[:auto_submit])
|
||||
}.compact
|
||||
} %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue