2024-12-20 11:37:26 -05:00
|
|
|
<%# locals: (category:, categories:) %>
|
|
|
|
|
2025-02-24 21:08:05 +05:00
|
|
|
<div data-controller="category" data-category-preset-colors-value="<%= Category::COLORS %>">
|
2025-01-30 14:35:30 -03:00
|
|
|
<%= styled_form_with model: category, class: "space-y-4" do |f| %>
|
2024-08-27 17:06:41 -04:00
|
|
|
<section class="space-y-4">
|
|
|
|
<div class="w-fit m-auto">
|
2025-02-24 21:08:05 +05:00
|
|
|
<%= render partial: "color_avatar", locals: { category: category } %>
|
2024-08-27 17:06:41 -04:00
|
|
|
</div>
|
2025-02-24 21:08:05 +05:00
|
|
|
<details data-category-target="details">
|
|
|
|
<summary class="cursor-pointer absolute top-23 left-58.5 flex justify-center items-center bg-gray-50 border-2 w-7 h-7 border-white rounded-full text-gray-500">
|
|
|
|
<%= icon("pen", size: "sm") %>
|
|
|
|
</summary>
|
2024-12-20 11:37:26 -05:00
|
|
|
|
2025-04-11 09:28:00 -05:00
|
|
|
<div class=" absolute z-50 bg-container p-4 border border-alpha-black-25 rounded-2xl shadow-xs h-fit left-66 top-24">
|
2025-02-24 21:08:05 +05:00
|
|
|
<div class="flex gap-2 flex-col mb-4" data-category-target="selection" style="<%= "display:none;" if @category.subcategory? %>">
|
|
|
|
<div data-category-target="pickerSection"></div>
|
|
|
|
<h4 class="text-gray-500 text-sm">Color</h4>
|
|
|
|
<div class="flex gap-2 items-center" data-category-target="colorsSection">
|
|
|
|
<% Category::COLORS.each do |color| %>
|
|
|
|
<label class="relative">
|
|
|
|
<%= f.radio_button :color, color, class: "sr-only peer", data: { action: "change->category#handleColorChange" } %>
|
|
|
|
<div class="w-6 h-6 rounded-full cursor-pointer peer-checked:ring-2 peer-checked:ring-offset-2 peer-checked:ring-blue-500" style="background-color: <%= color %>"></div>
|
|
|
|
</label>
|
|
|
|
<% end %>
|
|
|
|
<label class="relative">
|
|
|
|
<%= f.radio_button :color, "custom-color", class: "sr-only peer", data: { category_target: "colorPickerRadioBtn"} %>
|
2025-02-25 17:28:40 -05:00
|
|
|
<div class="w-6 h-6 rounded-full cursor-pointer peer-checked:ring-2 peer-checked:ring-offset-2 peer-checked:ring-blue-500" data-category-target="pickerBtn" style="background: conic-gradient(red,orange,yellow,lime,green,teal,cyan,blue,indigo,purple,magenta,pink,red)"></div>
|
2025-02-24 21:08:05 +05:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="flex gap-2 items-center hidden flex-col" data-category-target="paletteSection">
|
|
|
|
<div class="flex gap-2 items-center w-full">
|
|
|
|
<div class="w-6 h-6 p-4 rounded-full cursor-pointer" style="background-color: <%= category.color %>" data-category-target="colorPreview"></div>
|
2025-04-23 10:42:30 -03:00
|
|
|
<%= f.text_field :color , data: { category_target: "colorInput"}, inline: true %>
|
2025-02-24 21:08:05 +05:00
|
|
|
<%= lucide_icon "palette", class: "w-8 h-8 cursor-pointer hover:bg-gray-100 p-1", data: { action: "click->category#toggleSections" } %>
|
|
|
|
</div>
|
|
|
|
<div data-category-target="validationMessage" class="hidden self-start flex gap-1 items-center text-xs text-destructive ">
|
|
|
|
<span>Poor contrast, choose darker color or</span>
|
|
|
|
<button type="button" class="underline cursor-pointer" data-action="category#autoAdjust">auto-adjust.</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex flex-wrap gap-2 justify-center flex-col w-87">
|
|
|
|
<h4 class="text-gray-500 text-sm">Icon</h4>
|
|
|
|
<div class="flex flex-wrap gap-0.5">
|
|
|
|
<% Category.icon_codes.each do |icon| %>
|
|
|
|
<label class="relative">
|
|
|
|
<%= f.radio_button :lucide_icon, icon, class: "sr-only peer", data: { action: "change->category#handleIconChange change->category#handleIconColorChange", category_target:"icon" } %>
|
2025-02-25 17:28:40 -05:00
|
|
|
<div class="w-7 h-7 flex m-0.5 items-center justify-center rounded-full cursor-pointer hover:bg-gray-100 peer-checked:bg-gray-100 border-1 border-transparent">
|
2025-02-24 21:08:05 +05:00
|
|
|
<%= lucide_icon icon, class: "w-6 h-6 p-1" %>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</details>
|
2024-12-20 11:37:26 -05:00
|
|
|
|
|
|
|
<% if category.errors.any? %>
|
|
|
|
<%= render "shared/form_errors", model: category %>
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
<div class="space-y-2">
|
2025-01-16 14:36:37 -05:00
|
|
|
<%= f.select :classification, [["Income", "income"], ["Expense", "expense"]], { label: "Classification" }, required: true %>
|
2024-12-20 11:37:26 -05:00
|
|
|
<%= f.text_field :name, placeholder: t(".placeholder"), required: true, autofocus: true, label: "Name", data: { color_avatar_target: "name" } %>
|
2025-01-30 14:35:30 -03:00
|
|
|
<% unless category.parent? %>
|
2025-02-24 21:08:05 +05:00
|
|
|
<%= f.select :parent_id, categories.pluck(:name, :id), { include_blank: "(unassigned)", label: "Parent category (optional)" }, disabled: category.parent?, data: { action: "change->category#handleParentChange" } %>
|
2025-01-30 14:35:30 -03:00
|
|
|
<% end %>
|
2024-08-27 17:06:41 -04:00
|
|
|
</div>
|
|
|
|
</section>
|
2024-05-02 07:24:31 -06:00
|
|
|
|
|
|
|
<section>
|
|
|
|
<%= hidden_field_tag :transaction_id, params[:transaction_id] %>
|
2024-08-27 17:06:41 -04:00
|
|
|
<%= f.submit %>
|
2024-05-02 07:24:31 -06:00
|
|
|
</section>
|
2024-08-27 17:06:41 -04:00
|
|
|
<% end %>
|
|
|
|
</div>
|