Replace non-GET links with buttons

This commit is contained in:
cryptogopher 2023-05-14 15:11:17 +02:00
parent 459836ca38
commit fbb74bd1f8
5 changed files with 79 additions and 59 deletions

View File

@ -74,42 +74,42 @@ input:read-only:hover {
height: 2.2rem; height: 2.2rem;
margin: 0.4rem 0; margin: 0.4rem 0;
} }
.app-menu .image-button { .app-menu > * {
float: right; float: right;
margin-left: 0.8rem; margin-left: 0.8rem;
} }
.nav-menu { .nav-menu {
height: 2.7rem; height: 2.4rem;
margin: 0.4rem 0; margin: 0.4rem 0;
} }
.nav-menu a svg { .nav-menu .right > * {
height: 1.5rem;
padding-right: 0.4rem;
width: 1.5rem;
}
.nav-menu .image-button {
font-size: 0.9rem;
padding: 0.5rem 0.8rem;
}
.nav-menu .right .image-button {
float: right; float: right;
} }
.nav-menu .left .image-button { .nav-menu .left > * {
float: left; float: left;
} }
.nav-menu .tab-button { .nav-menu .tab {
border: none; border: none;
border-radius: 0; border-radius: 0;
font-size: 0.9rem;
margin: 0 0.8rem; margin: 0 0.8rem;
padding: 0.5rem 0.8rem;
} }
.nav-menu .tab-button.active { .nav-menu .tab.active {
border-bottom: solid 0.2rem; border-bottom: solid 0.2rem;
color: #009ade; color: #009ade;
fill: #009ade; fill: #009ade;
} }
.nav-menu a.button svg,
.nav-menu button svg {
height: 1.5rem;
padding-right: 0.4rem;
width: 1.5rem;
}
.image-button, a.button,
button,
input[type=submit] { input[type=submit] {
align-items: center; align-items: center;
background-color: white; background-color: white;
@ -126,35 +126,39 @@ input[type=submit] {
text-decoration: none; text-decoration: none;
width: fit-content; width: fit-content;
} }
.image-button svg { a.button svg,
button svg {
height: 1.3rem; height: 1.3rem;
padding-right: 0.4rem; padding-right: 0.4rem;
width: 1.3rem; width: 1.3rem;
} }
.image-button:hover, a.button:hover,
.image-button.active:hover, a.button.active:hover,
button:hover,
input[type=submit]:hover { input[type=submit]:hover {
background-color: #009ade; background-color: #009ade;
border-color: #009ade; border-color: #009ade;
color: white; color: white;
fill: white; fill: white;
} }
.image-button.dangerous:hover { a.button:focus-visible,
background-color: #ff1f5b; a.button.active:focus-visible,
border-color: #ff1f5b; button:focus-visible,
}
.image-button:focus-visible,
.image-button.active:focus-visible,
input[type=submit]:focus-visible { input[type=submit]:focus-visible {
background-color: #f3f3f3; background-color: #f3f3f3;
} }
.image-button:hover:focus-visible, a.button:hover:focus-visible,
.image-button.active:hover:focus-visible, a.button.active:hover:focus-visible,
button:hover:focus-visible,
input[type=submit]:hover:focus-visible { input[type=submit]:hover:focus-visible {
background-color: #006c9b; background-color: #006c9b;
border-color: #006c9b; border-color: #006c9b;
} }
.image-button.dangerous:hover:focus-visible { button.dangerous:hover {
background-color: #ff1f5b;
border-color: #ff1f5b;
}
button.dangerous:hover:focus-visible {
background-color: #b21237; background-color: #b21237;
border-color: #b21237; border-color: #b21237;
} }
@ -265,37 +269,45 @@ table.items td:not(:first-child):not(.actions) {
} }
table.items td { table.items td {
border-top: 1px solid #dddddd; border-top: 1px solid #dddddd;
line-height: 2.5rem;
padding: 0; padding: 0;
} }
table.items td a { table.items a {
color: black; color: black;
cursor: pointer; cursor: pointer;
display: block; display: block;
font-weight: normal; font-weight: normal;
line-height: 2.5rem;
padding: 0 0.8rem; padding: 0 0.8rem;
text-decoration: none; text-decoration: none;
} }
table.items td a:hover { table.items a:hover,
table.items a:focus-visible,
table.items a:hover:focus-visible {
text-decoration: underline; text-decoration: underline;
text-decoration-thickness: 0.05rem; text-decoration-thickness: 0.05rem;
text-underline-offset: 0.2rem; text-underline-offset: 0.2rem;
} }
table.items td a.image-button { table.items a:focus-visible {
border-color: #dddddd; text-decoration-style: dashed;
color: #909090;
margin-right: 0.25rem;
padding: 0.25rem;
} }
table.items td:not(:first-child) { table.items td:not(:first-child) {
color: #909090; color: #909090;
fill: #909090; fill: #909090;
} }
table.items td.actions {
text-align: right;
}
table.items svg { table.items svg {
height: 1.2rem; height: 1.2rem;
vertical-align: middle; vertical-align: middle;
width: 1.2rem; width: 1.2rem;
} }
table.items td.actions {
padding-left: 0.8rem;
text-align: right;
}
table.items button {
margin-right: 0.25rem;
padding: 0.25rem;
}
table.items button:not(:hover) {
border-color: #dddddd;
color: #909090;
}

View File

@ -54,15 +54,12 @@ module ApplicationHelper
form_for(record, **options, &-> (f) { f.table_form_for(&block) }) form_for(record, **options, &-> (f) { f.table_form_for(&block) })
end end
def image_button_to(name, image = nil, options = nil, html_options = {})
image_element_to(:button, name, image, options, html_options)
end
def image_link_to(name, image = nil, options = nil, html_options = {}) def image_link_to(name, image = nil, options = nil, html_options = {})
current = html_options.delete(:current) image_element_to(:link, name, image, options, html_options)
return "" if (current == :hide) && (url_for(options) == request.path)
name = svg_tag("pictograms/#{image}") + name if image
classes = class_names(html_options[:class], "image-button", active: current == :active)
html_options.merge!(class: classes) { |k, v1, v2| "#{v1} #{v2}" }
link_to name, options, html_options
end end
def svg_tag(source, options = {}) def svg_tag(source, options = {})
@ -76,9 +73,21 @@ module ApplicationHelper
content_tag :div, class: "right" do content_tag :div, class: "right" do
if current_user.at_least(:admin) if current_user.at_least(:admin)
image_link_to t('.users'), "account-multiple-outline", users_path, class: "tab-button", image_link_to t('.users'), "account-multiple-outline", users_path, class: "tab",
current: :active current: :active
end end
end end
end end
private
def image_element_to(type, name, image = nil, options = nil, html_options = {})
current = html_options.delete(:current)
return "" if (current == :hide) && (url_for(options) == request.path)
name = svg_tag("pictograms/#{image}") + name if image
html_options[:class] = class_names(html_options[:class], "button", active: current == :active)
send "#{type}_to", name, options, html_options
end
end end

View File

@ -14,17 +14,15 @@
<div class="app-menu"> <div class="app-menu">
<% if user_signed_in? %> <% if user_signed_in? %>
<% if current_user_disguised? %> <% if current_user_disguised? %>
<%= image_link_to t(:revert), "incognito-off", revert_users_path, <%= image_button_to t(:revert), "incognito-off", revert_users_path %>
data: {turbo: true, turbo_method: :post} %>
<% else %> <% else %>
<%= image_link_to t(:sign_out), "logout", destroy_user_session_path, <%= image_button_to t(:sign_out), "logout", destroy_user_session_path, method: :delete %>
data: {turbo: true, turbo_method: :delete} %>
<% end %> <% end %>
<%= image_link_to current_user.email, "account-wrench-outline", <%= image_link_to current_user.email, "account-wrench-outline",
edit_user_registration_path, current: :hide %> edit_user_registration_path, current: :hide %>
<% else %> <% else %>
<%= image_link_to t(:register), "account-plus-outline", new_user_registration_path, <%= image_link_to t(:register), "account-plus-outline", new_user_registration_path,
current: :hide %> current: :hide %>
<%= image_link_to t(:sign_in), "login", new_user_session_path, current: :hide %> <%= image_link_to t(:sign_in), "login", new_user_session_path, current: :hide %>
<% end %> <% end %>
</div> </div>

View File

@ -18,8 +18,9 @@
</td> </td>
<td><%= user.created_at.to_fs(:db_without_sec) %></td> <td><%= user.created_at.to_fs(:db_without_sec) %></td>
<td class="actions"> <td class="actions">
<%= image_link_to t(".disguise"), "incognito", disguise_user_path(user), <% if allow_disguise?(user) %>
data: {turbo: true, turbo_method: :post} if allow_disguise?(user) %> <%= image_button_to t(".disguise"), "incognito", disguise_user_path(user) %>
<% end %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@ -4,9 +4,9 @@
request.referer.present? ? :back : root_url %> request.referer.present? ? :back : root_url %>
</div> </div>
<div class="right"> <div class="right">
<%= image_link_to t(".delete"), "account-remove-outline", user_registration_path, <%# TODO: make confirm dialog work %>
class: "dangerous", <%= image_button_to t(".delete"), "account-remove-outline", user_registration_path,
data: { turbo: true, turbo_method: :delete, turbo_confirm: t(".confirm_delete") } %> class: "dangerous", method: :delete, data: {confirm: t(".confirm_delete")} %>
</div> </div>
<% end %> <% end %>