Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Let DS buttons marked hidden actually hide (#4342)

Guillem Arias Fauste5fc2caf47952
diff --git a/app/components/DS/buttonish.rb b/app/components/DS/buttonish.rb
index fe47424830..1cee8a5132 100644
--- a/app/components/DS/buttonish.rb
+++ b/app/components/DS/buttonish.rb
@@ -63,19 +63,19 @@ class DS::Buttonish < DesignSystemComponent
SIZES = {
sm: {
container_classes: "px-2 py-1",
- icon_container_classes: "inline-flex items-center justify-center w-7 h-7 pointer-coarse:w-11 pointer-coarse:h-11",
+ icon_container_classes: "items-center justify-center w-7 h-7 pointer-coarse:w-11 pointer-coarse:h-11",
radius_classes: "rounded-md",
text_classes: "text-sm"
},
md: {
container_classes: "px-3 py-2",
- icon_container_classes: "inline-flex items-center justify-center w-9 h-9 pointer-coarse:w-11 pointer-coarse:h-11",
+ icon_container_classes: "items-center justify-center w-9 h-9 pointer-coarse:w-11 pointer-coarse:h-11",
radius_classes: "rounded-lg",
text_classes: "text-sm"
},
lg: {
container_classes: "px-4 py-3",
- icon_container_classes: "inline-flex items-center justify-center w-12 h-12",
+ icon_container_classes: "items-center justify-center w-12 h-12",
radius_classes: "rounded-xl",
text_classes: "text-base"
}
@@ -157,9 +157,13 @@ class DS::Buttonish < DesignSystemComponent
self.class::SIZES.dig(size)
end
- # Make sure that user can override common classes like `hidden`
+ # Make sure that user can override common classes like `hidden`. Only the
+ # display utility gives way: a responsive `hidden lg:inline-flex` still
+ # needs the alignment and gap once it shows, and nothing else may add
+ # `inline-flex` back (it wins over `hidden` in the generated CSS).
def merged_base_classes
- base_display_classes = "inline-flex items-center gap-1"
+ base_display_classes = "inline-flex"
+ base_layout_classes = "items-center gap-1"
base_radius_classes = size_data.dig(:radius_classes)
extra_classes_list = (extra_classes || "").split
@@ -173,6 +177,8 @@ class DS::Buttonish < DesignSystemComponent
base_classes << base_display_classes
end
+ base_classes << base_layout_classes
+
unless has_radius_override
base_classes << base_radius_classes
end
diff --git a/app/components/DS/dialog.rb b/app/components/DS/dialog.rb
index ca7b4f21cf..ceb81d6dcf 100644
--- a/app/components/DS/dialog.rb
+++ b/app/components/DS/dialog.rb
@@ -161,12 +161,14 @@ class DS::Dialog < DesignSystemComponent
@responsive
end
+ # Shown at every width: responsive dialogs use it as their only close
+ # control on phones too. shrink-0 keeps its square beside a long title in a
+ # custom header.
def close_button
- classes = responsive? ? "ml-auto hidden lg:flex" : "ml-auto"
render DS::Button.new(
variant: "icon",
size: :sm,
- class: classes,
+ class: "ml-auto shrink-0",
icon: "x",
title: I18n.t("ds.dialog.close"),
aria_label: I18n.t("ds.dialog.close"),
diff --git a/app/views/bills/_view_switcher.html.erb b/app/views/bills/_view_switcher.html.erb
index 55edc15d3c..148ff82df7 100644
--- a/app/views/bills/_view_switcher.html.erb
+++ b/app/views/bills/_view_switcher.html.erb
@@ -7,9 +7,7 @@
everywhere else. The other half and the AI review live in the overflow
menu, so the header carries one action instead of a toolbar of three.
Laid out the way Transactions lays out New transaction: the menu first,
- the primary action last, and a round + in its place on a phone. A display
- class makes DS::Link drop its own inline-flex row, so the button brings
- items-center gap-1 back or its + touches the label. %>
+ the primary action last, and a round + in its place on a phone. %>
<% income_first = active == "paycheck" %>
<% add_text = income_first ? t("bills.index.add_income") : t("bills.index.add_bill") %>
<% add_href = income_first ? new_recurring_transaction_path(income: true) : new_recurring_transaction_path %>
@@ -45,7 +43,7 @@
variant: "primary",
href: add_href,
frame: :modal,
- class: "hidden md:inline-flex items-center gap-1"
+ class: "hidden md:inline-flex"
) %>
<%= render DS::Link.new(
icon: "plus",
diff --git a/app/views/recurring_occurrences/show.html.erb b/app/views/recurring_occurrences/show.html.erb
index c485f14ccf..b4828521d3 100644
--- a/app/views/recurring_occurrences/show.html.erb
+++ b/app/views/recurring_occurrences/show.html.erb
@@ -10,10 +10,7 @@
is why it is its own drawer, one link away from the bill's.
frame: "drawer", responsive: true matches every other detail surface in the
- app -- a centred card on a phone, a right-hand drawer from lg up. The close
- button is ours rather than dialog.close_button, because that one carries
- `hidden lg:flex` under `responsive`, which leaves a phone with no visible
- way out. %>
+ app -- a centred card on a phone, a right-hand drawer from lg up. %>
<%= render DS::Dialog.new(frame: "drawer", responsive: true) do |dialog| %>
<% dialog.with_header(custom_header: true) do %>
@@ -26,15 +23,7 @@
<%= occurrence_due_label(@occurrence) %>
</p>
</div>
- <%= render DS::Button.new(
- variant: "icon",
- size: :sm,
- icon: "x",
- class: "ml-auto shrink-0",
- title: t("ds.dialog.close"),
- aria_label: t("ds.dialog.close"),
- data: { action: "DS--dialog#close" }
- ) %>
+ <%= dialog.close_button %>
</div>
<% end %>
diff --git a/app/views/settings/providers/_drawer_header.html.erb b/app/views/settings/providers/_drawer_header.html.erb
index 3ccb473ba5..7577c435c6 100644
--- a/app/views/settings/providers/_drawer_header.html.erb
+++ b/app/views/settings/providers/_drawer_header.html.erb
@@ -11,7 +11,7 @@
</div>
<%= render DS::Button.new(
variant: "icon",
- class: "ml-auto hidden lg:flex",
+ class: "ml-auto",
icon: "x",
title: t("defaults.common.close"),
aria_label: t("defaults.common.close"),
diff --git a/test/components/DS/dialog_test.rb b/test/components/DS/dialog_test.rb
index e6fac26642..a3715edc8a 100644
--- a/test/components/DS/dialog_test.rb
+++ b/test/components/DS/dialog_test.rb
@@ -26,6 +26,18 @@ class DS::DialogTest < ViewComponent::TestCase
assert_no_selector "dialog[data-turbo-temporary]"
end
+ # Transaction, trade and other detail drawers put this button in their
+ # custom headers and have no other way out on a phone.
+ test "a responsive dialog's close button shows at every width" do
+ dialog = DS::Dialog.new(frame: "drawer", responsive: true)
+ render_inline(dialog) do
+ dialog.with_header(custom_header: true) { dialog.close_button }
+ end
+
+ close = page.find("button[data-action='DS--dialog#close']")
+ refute_includes close[:class].split, "hidden"
+ end
+
test "a modal fetched into the modal frame is left out of Turbo's page cache" do
vc_test_request.headers["Turbo-Frame"] = "modal"
render_inline(DS::Dialog.new)
diff --git a/test/components/DS/link_test.rb b/test/components/DS/link_test.rb
new file mode 100644
index 0000000000..02e85ac76e
--- /dev/null
+++ b/test/components/DS/link_test.rb
@@ -0,0 +1,34 @@
+require "test_helper"
+
+class DS::LinkTest < ViewComponent::TestCase
+ # The dashboard's desktop Customize link is icon-only and marked
+ # `hidden lg:inline-flex`. Icon-only sizes used to add `inline-flex`
+ # themselves, which beats `hidden`, so phones showed it next to the
+ # mobile one.
+ test "an icon-only link marked hidden stays hidden below its breakpoint" do
+ render_inline(DS::Link.new(href: "/", icon: "layout-grid", variant: "outline", class: "hidden lg:inline-flex"))
+
+ classes = page.find("a")[:class].split
+ assert_includes classes, "hidden"
+ assert_includes classes, "lg:inline-flex"
+ refute_includes classes, "inline-flex"
+ end
+
+ test "a text link marked hidden keeps its alignment and gap for when it shows" do
+ render_inline(DS::Link.new(href: "/", icon: "plus", text: "New", class: "hidden md:inline-flex"))
+
+ classes = page.find("a")[:class].split
+ assert_includes classes, "items-center"
+ assert_includes classes, "gap-1"
+ refute_includes classes, "inline-flex"
+ end
+
+ test "an icon-only link without a display override is a centred inline-flex box" do
+ render_inline(DS::Link.new(href: "/", icon: "plus", variant: "icon"))
+
+ classes = page.find("a")[:class].split
+ assert_includes classes, "inline-flex"
+ assert_includes classes, "items-center"
+ assert_includes classes, "justify-center"
+ end
+end