diff --git a/README.md b/README.md index 46d4156..a989715 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,12 @@ ActiveAdmin 4 keeps its menu in a left sidebar and gives breadcrumbs and titles - Index tables scroll sideways when they are wider than the screen, and cells stay on one line. - Theme 3 colors, density, and typography on top of ActiveAdmin 4's own dark mode. -Theme 4 needs ActiveAdmin 4 (`>= 4.0.0.beta23`) and Ruby 3.3 or newer. For ActiveAdmin 3, use theme 3.x (branch `3.x`). See [docs/migrating-from-v3.md](docs/migrating-from-v3.md). +Theme 4 needs ActiveAdmin 4 (`>= 4.0.0.beta23`) and Ruby 3.3 or newer. To upgrade from theme 3, see [docs/migrating-from-v3.md](docs/migrating-from-v3.md). + +| ActiveAdmin | Theme | Install | Docs | +| --- | --- | --- | --- | +| 4 | 4.0.0.beta1 | `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta1"` | this README | +| 3 | 3.3.0, maintained on the [`3.x`](https://github.com/activeadmin-plugins/active_admin_theme/tree/3.x) branch | `gem "active_admin_theme", "~> 3.3"` (RubyGems) | [v3.3.0 README](https://github.com/activeadmin-plugins/active_admin_theme/blob/v3.3.0/README.md) | ## Screenshots diff --git a/app/tailwind/active_admin_theme.css b/app/tailwind/active_admin_theme.css index 2e5880a..b170e87 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -175,8 +175,9 @@ .data-table :where(tbody > tr.selected) > td { background-color: var(--aat-selected-row); } -/* A table_for in a panel scrolls sideways instead of widening the page. */ -.panel-body:has(> .data-table) { +/* A table_for in a panel or a tab scrolls sideways instead of widening the page. */ +.panel-body:has(> .data-table), +.aat-tab-panel:has(> .data-table) { overflow-x: auto; } /* Opt-in sticky first column. Body cells keep the stripe, hover and selected fills above. */ @@ -696,7 +697,12 @@ body { display: none; } -/* v3 drew EMPTY in #bbb in both modes; ActiveAdmin's dark gray-600/50 is barely readable. */ +/* ActiveAdmin's gray-400/50 and dark gray-600/50 are barely readable. These + * grays keep about 3:1 on white and 4.6:1 on the dark panel, well under values, + * so EMPTY stays readable and reads as a blank. */ +.attributes-table-empty-value { + color: #8f969e; +} .dark .attributes-table-empty-value { - color: #bbbbbb; + color: #8a929c; } diff --git a/docs/migrating-from-v3.md b/docs/migrating-from-v3.md index ffe28af..168cf89 100644 --- a/docs/migrating-from-v3.md +++ b/docs/migrating-from-v3.md @@ -2,7 +2,7 @@ Theme 4 is a rework for ActiveAdmin 4. ActiveAdmin 4 replaced SCSS and Sprockets with Tailwind CSS 4, ERB partials, and import maps, so theme 3 cannot run on it. On screen the result looks almost the same. In your app, a few things change. -Upgrade ActiveAdmin first, and follow ActiveAdmin's own [upgrade guide](https://github.com/activeadmin/activeadmin/blob/master/UPGRADING.md). Then switch the theme. Theme 3.x stays on the `3.x` branch and keeps getting bug fixes. +Upgrade ActiveAdmin first, and follow ActiveAdmin's own [upgrade guide](https://github.com/activeadmin/activeadmin/blob/master/UPGRADING.md). Then switch the theme. Theme 3 stays on RubyGems as 3.3.0, with its docs in the [v3.3.0 README](https://github.com/activeadmin-plugins/active_admin_theme/blob/v3.3.0/README.md). Theme 3 fixes go to the [`3.x`](https://github.com/activeadmin-plugins/active_admin_theme/tree/3.x) branch. ## Checklist diff --git a/test/components_test.rb b/test/components_test.rb index 7aca5cc..8633cce 100644 --- a/test/components_test.rb +++ b/test/components_test.rb @@ -53,6 +53,15 @@ def test_table_in_a_panel_scrolls_with_a_sticky_first_column assert_equal style(second, "backgroundColor"), style(first, "backgroundColor") end + def test_table_in_a_tab_scrolls_inside_the_tab + tab = "#tab-table .aat-tab-panel:not(.hidden)" + assert_equal "auto", style(tab, "overflowX") + right = ->(sel) { page.evaluate_script("document.querySelector(#{sel.to_json}).getBoundingClientRect().right") } + assert page.evaluate_script("(() => { const e = document.querySelector(#{tab.to_json}); return e.scrollWidth > e.clientWidth })()") + assert_operator right.(tab), :<=, right.("#tab-table") + assert_operator page.evaluate_script("document.documentElement.scrollWidth"), :<=, 1280 + end + def test_body_uses_the_v3_font_without_antialiasing assert_match(/\A"Helvetica Neue", Arial/, style("body", "fontFamily")) assert_equal "auto", style("body", "webkitFontSmoothing") diff --git a/test/dummy/app/admin/components_demo.rb b/test/dummy/app/admin/components_demo.rb index d5a79e2..5de9e01 100644 --- a/test/dummy/app/admin/components_demo.rb +++ b/test/dummy/app/admin/components_demo.rb @@ -55,6 +55,17 @@ end end + panel "Table in tabs", id: "tab-table" do + tabs do + tab "Wide table" do + table_for (1..2).to_a do + (1..20).each { |c| column("Column #{c}") { |r| "row #{r} / value #{c}" } } + end + end + tab("Other") { para "Another tab" } + end + end + panel "Secret reveal" do div(id: "secret") { secret_reveal url: "/admin/components/secret" } end diff --git a/test/form_look_test.rb b/test/form_look_test.rb index b639fb6..34102b9 100644 --- a/test/form_look_test.rb +++ b/test/form_look_test.rb @@ -42,10 +42,38 @@ def test_tabs_in_a_form_keep_their_look_in_dark_mode assert_equal "rgba(0, 0, 0, 0)", style("#form-panels .aat-panel-toggle", "backgroundColor") end - def test_empty_values_are_as_bright_as_v3_in_dark_mode + # Contrast ratio (WCAG 2) of the text of +selector+ against the first + # opaque background behind it. + def contrast(selector) + page.evaluate_script(<<~JS) + (() => { + const rgb = (value) => value.match(/[\\d.]+/g).map(Number) + const lum = ([r, g, b]) => [r, g, b].map((c) => { c /= 255; return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4 }) + .reduce((sum, c, i) => sum + c * [0.2126, 0.7152, 0.0722][i], 0) + let el = document.querySelector(#{selector.to_json}) + const fg = lum(rgb(getComputedStyle(el).color)) + while (el && (rgb(getComputedStyle(el).backgroundColor)[3] === 0)) el = el.parentElement + const bg = lum(rgb(getComputedStyle(el || document.body).backgroundColor)) + return (Math.max(fg, bg) + 0.05) / (Math.min(fg, bg) + 0.05) + })() + JS + end + + def test_empty_values_are_dimmer_than_values_but_readable_in_dark_mode visit "/admin/components" page.execute_script("document.documentElement.classList.add('dark')") - assert_equal "rgb(187, 187, 187)", style("#pre-wrap-blank .attributes-table-empty-value", "color") + empty = "#pre-wrap-blank .attributes-table-empty-value" + assert_equal "rgb(138, 146, 156)", style(empty, "color") + assert_operator contrast(empty), :>=, 4.5 + assert_operator contrast(empty), :<, contrast("#pre-wrap") / 2 + end + + def test_empty_values_are_dimmer_than_values_but_readable_in_light_mode + visit "/admin/components" + empty = "#pre-wrap-blank .attributes-table-empty-value" + assert_equal "rgb(143, 150, 158)", style(empty, "color") + assert_operator contrast(empty), :>=, 2.95 + assert_operator contrast(empty), :<, contrast("#pre-wrap") / 2 end def test_a_panel_after_the_form_actions_has_a_gap