1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00

Improve theme selection (#2152)

* Improve theme selectin

* Use HTML form labels and the existing auto-submit controller
This commit is contained in:
Alex Hatzenbuhler 2025-04-25 09:15:48 -05:00 committed by GitHub
parent 210b89cd17
commit ce83418f0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -42,30 +42,29 @@
<% end %> <% end %>
<%= settings_section title: t(".theme_title"), subtitle: t(".theme_subtitle") do %> <%= settings_section title: t(".theme_title"), subtitle: t(".theme_subtitle") do %>
<div> <div data-controller="theme" data-theme-user-preference-value="<%= @user.theme %>">
<%= styled_form_with model: @user, class: "flex flex-col md:flex-row justify-between items-center gap-4", data: { controller: "auto-submit-form" } do |form| %> <%= form_with model: @user, class: "flex flex-col md:flex-row justify-between items-center gap-4", id: "theme_form",
data: { controller: "auto-submit-form", auto_submit_form_trigger_event_value: "change" } do |form| %>
<%= form.hidden_field :redirect_to, value: "preferences" %> <%= form.hidden_field :redirect_to, value: "preferences" %>
<div class="text-center">
<%= image_tag("light-mode-preview.png", alt: "Light Theme Preview", class: "h-44 mb-4") %> <% theme_option_class = "text-center transition-all duration-200 p-3 rounded-lg hover:bg-surface-hover cursor-pointer [&:has(input:checked)]:bg-surface-hover [&:has(input:checked)]:border [&:has(input:checked)]:border-primary [&:has(input:checked)]:shadow-xs" %>
<div class="flex justify-center items-center gap-2">
<%= form.radio_button :theme, "light", checked: @user.theme == "light", data: { auto_submit_form_target: "auto", action: "theme#updateTheme" } %> <% [
<%= form.label :theme_light, t(".theme_light"), value: "light" %> { value: "light", image: "light-mode-preview.png" },
</div> { value: "dark", image: "dark-mode-preview.png" },
</div> { value: "system", image: "system-mode-preview.png" }
<div class="text-center"> ].each do |theme| %>
<%= image_tag("dark-mode-preview.png", alt: "Dark Theme Preview", class: "h-44 mb-4") %> <%= form.label :"theme_#{theme[:value]}", class: "group" do %>
<div class="flex justify-center items-center gap-2"> <div class="<%= theme_option_class %>">
<%= form.radio_button :theme, "dark", checked: @user.theme == "dark", data: { auto_submit_form_target: "auto", action: "theme#updateTheme" } %> <%= image_tag(theme[:image], alt: "#{theme[:value].titleize} Theme Preview", class: "h-44 mb-2") %>
<%= form.label :theme_dark, t(".theme_dark"), value: "dark" %> <div class="<%= theme[:value] == 'system' ? 'flex items-center gap-2 justify-center' : 'text-sm font-medium text-primary' %>">
</div> <%= form.radio_button :theme, theme[:value], checked: @user.theme == theme[:value], class: "sr-only",
</div> data: { auto_submit_form_target: "auto", autosubmit_trigger_event: "change", action: "theme#updateTheme" } %>
<div class="text-center"> <%= t(".theme_#{theme[:value]}") %>
<%= image_tag("system-mode-preview.png", alt: "System Theme Preview", class: "h-44 mb-4") %> </div>
<div class="flex items-center gap-2 justify-center"> </div>
<%= form.radio_button :theme, "system", checked: @user.theme == "system", data: { auto_submit_form_target: "auto", action: "theme#updateTheme" } %> <% end %>
<%= form.label :theme_system, t(".theme_system"), value: "system" %> <% end %>
</div>
</div>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>