diff --git a/README.md b/README.md index 46d4156..9a9c96d 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 @@ -172,6 +177,7 @@ A host partial with the same path overrides the theme's. Copy the partial from t - `_page_content`: the grid that holds the sidebar and the page, and the tab that collapses the sidebar. - `_sidebar`. - `_flash_messages`: the flash bands under the title band. +- `_page_banner`: empty. Override it to show a band under the flashes on every logged-in page, such as the environment name. The login pages leave it out. - `kaminari/*`: the page links under an index table, with "First", "Next ›" and "Last »". The index footer is one line under the table: per page, page links, the count, and the download links. Its English wording ("Displaying Orders 1 - 30 of 60 in total") comes from the theme's `config/locales/active_admin_theme.en.yml`; your own locale file overrides it, and other languages keep ActiveAdmin's text. @@ -323,6 +329,8 @@ text_node pre_wrap(response.body, max_height: "20rem") row(:payload) { |order| pre_wrap(order.payload, max_height: 240) } ``` +Any `pre` in an `attributes_table` cell, with or without `pre_wrap`, is capped at 24rem and scrolls the rest. To change the cap, set `--aat-attributes-pre-max-height` in your CSS. A `max_height:` of its own wins. + ### `secret_reveal` A masked value with an eye icon before it. A click fetches and shows the value, and the icon turns to an eye-off icon that hides it again. The URL must return `{"value": "..."}`. Needs the `active_admin_theme/secret_reveal` script. @@ -420,6 +428,17 @@ action_item :export, only: :index do end ``` +### Buttons + +Action items and form buttons get the theme button look on their own. Anywhere else, such as a panel or a hand-written form, give a link or a button the `aat-button` class, or ActiveAdmin's own `action-item-button`. The button uses the `--aat-button*` colors. Add `aat-button-secondary` for the plain variant, which uses the surface and input border colors. + +```ruby +panel "Export" do + a "Download CSV", href: export_path(format: :csv), class: "aat-button" + a "Back", href: collection_path, class: "aat-button aat-button-secondary" +end +``` + ### String helpers For decorators and view helpers outside an Arbre context, each component has a helper that returns an `html_safe` String: `status_tag`, `secret_reveal_tag`, `notice_tag`, `confirm_dialog_tag`, `dropdown_menu_tag` and `pre_wrap`. `status_tag` builds its tag with Rails tag helpers, which is faster than Arbre in long tables, and gives the same markup as the component; inside Arbre the component wins. `arbre { ... }` builds any Arbre block the same way and trims Arbre's trailing newline. All of them are available in ActiveAdmin views. A plain object includes `ActiveAdminTheme::Helpers::Tags`. It must also answer the view methods a component calls, such as `link_to` for `dropdown_menu_tag`; a Draper decorator can delegate them to `h`. diff --git a/app/javascript/active_admin_theme/layout.js b/app/javascript/active_admin_theme/layout.js index 4c7708e..125eaf8 100644 --- a/app/javascript/active_admin_theme/layout.js +++ b/app/javascript/active_admin_theme/layout.js @@ -33,12 +33,12 @@ const init = () => apply(read()) if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init) else init() -// A top-menu flyout that would run past the viewport edge opens on the other -// side of its item instead. +// A top-menu dropdown or flyout that would run past the viewport edge opens on +// the other side of its item instead. const placeFlyout = (event) => { - const item = event.target.closest("[data-aat-submenu]") + const item = event.target.closest("[data-aat-submenu], [data-aat-top-item]") if (!item || item.contains(event.relatedTarget)) return - const flyout = item.querySelector(":scope > .aat-flyout") + const flyout = item.querySelector(":scope > .aat-flyout, :scope > .aat-top-dropdown") if (!flyout) return item.removeAttribute("data-aat-flip") const rect = flyout.getBoundingClientRect() @@ -47,3 +47,11 @@ const placeFlyout = (event) => { } document.addEventListener("mouseover", placeFlyout) document.addEventListener("focusin", placeFlyout) + +// The width the page header and footer keep while a wide index table scrolls +// the page sideways: the viewport without its scrollbar. +const setViewportWidth = () => { + document.documentElement.style.setProperty("--aat-viewport-width", `${document.documentElement.clientWidth}px`) +} +setViewportWidth() +window.addEventListener("resize", setViewportWidth) diff --git a/app/tailwind/active_admin_theme.css b/app/tailwind/active_admin_theme.css index 2e5880a..504c39c 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -141,7 +141,8 @@ .data-table :where(thead > tr > th > a) { gap: 0.375rem; } -/* Sort marks: both arrows on a sortable column, one on the sorted column. */ +/* Sort marks: both arrows on a sortable column, one on the sorted column. They + * are muted, so they read apart from the column title. */ .data-table-sorted-icon { display: none; } @@ -150,8 +151,8 @@ flex: none; width: 9px; height: 12px; - background-color: currentColor; - opacity: 0.6; + background-color: var(--aat-text-muted); + opacity: 0.5; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 12'%3E%3Cpath d='M4.5 0 9 5H0z'/%3E%3Cpath d='M4.5 12 0 7h9z'/%3E%3C/svg%3E") center / contain no-repeat; } .data-table :where(th[data-sort-direction="asc"] > a)::after { @@ -175,8 +176,34 @@ .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 wide index table widens the page, and the window scrolls sideways, as in + * v3. The main column takes the table's width, and the bars around the + * content stay at the viewport width. layout.js sets --aat-viewport-width, + * which leaves out a classic scrollbar. Below 768px the table scrolls in its + * wrapper. */ +@media (width >= 48rem) { + :has(> [data-aat-page] .index-as-table) { + min-width: fit-content; + } + :has(> [data-aat-page] .index-as-table) > :not([data-aat-page], #main-menu, script) { + position: sticky; + inset-inline-start: 0; + width: var(--aat-viewport-width, 100vw); + } + [data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(.index-as-table) { + grid-template-columns: 270px minmax(min-content, 1fr); + } + [data-aat-page]:is(:not([data-aat-has-sidebar]), [data-aat-sidebar-collapsed]):has(.index-as-table) { + grid-template-columns: minmax(min-content, 1fr); + } + [data-aat-page] :is(.index-as-table, .paginated-collection-contents:has(> .index-as-table)) { + overflow-x: visible; + } +} + +/* 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. */ @@ -289,12 +316,16 @@ table.with-sticky-rows thead th:first-child { color: var(--aat-filter-label); } -/* Action items are always buttons, the trigger of a confirm_dialog included. */ +/* Action items are always buttons, the trigger of a confirm_dialog included. + * Elsewhere, ActiveAdmin's action-item-button class or aat-button gives a link + * or a button the same look; aat-button-secondary is the plain variant. */ #action-items > a, #action-items > button, #action-items > input[type="submit"], #action-items > form > :where(button, input[type="submit"]), -#action-items .aat-confirm-trigger { +#action-items .aat-confirm-trigger, +.action-item-button, +.aat-button { @apply inline-flex items-center rounded no-underline cursor-pointer; padding: 0.375rem 0.625rem; font-size: var(--aat-font-size); @@ -308,8 +339,24 @@ table.with-sticky-rows thead th:first-child { #action-items > button:hover, #action-items > input[type="submit"]:hover, #action-items > form > :where(button, input[type="submit"]):hover, -#action-items .aat-confirm-trigger:hover { +#action-items .aat-confirm-trigger:hover, +.action-item-button:hover, +.aat-button:hover { background-color: var(--aat-button-hover); + color: var(--aat-button-text); +} +.aat-button.aat-button-secondary { + color: var(--aat-text); + background-color: var(--aat-surface-2); + box-shadow: inset 0 0 0 1px var(--aat-input-border); +} +.aat-button.aat-button-secondary:hover { + color: var(--aat-text); + background-color: var(--aat-surface-hover); +} +:is(.action-item-button, .aat-button):focus-visible { + outline: 2px solid var(--aat-accent); + outline-offset: 2px; } #action-items > form { display: inline-flex; @@ -421,8 +468,9 @@ table.data-table td[data-selected-cell] { overflow-x: auto; } -/* Login pages: the Devise card follows the theme surface and border. */ -[data-aat-login] > div:not(:has(> div)) { +/* Login pages: the Devise card, the box that holds the title, follows the + * theme surface and border. A host's empty wrapper gets no box. */ +[data-aat-login] > div:has(> h2) { background-color: var(--aat-surface); border: 1px solid var(--aat-border); border-radius: 0.25rem; @@ -507,7 +555,12 @@ table.data-table td[data-selected-cell] { } } -/* Index toolbar: scopes, batch actions. */ +/* Index toolbar: scopes, batch actions. ActiveAdmin renders it whenever batch + * actions exist, even when display_if hides them all; empty, its margin pushes + * the table below the sidebar top. */ +.index-data-table-toolbar:not(:has(*)) { + display: none; +} .index-button, .batch-actions-dropdown-toggle { height: 1.875rem; @@ -573,8 +626,22 @@ body { } } -/* A top-menu item keeps its highlight while its dropdown is open, as in v3. */ -[data-aat-main-menu] li:has(> div:not(.hidden)) > a { +/* A top-menu dropdown opens and closes with the pointer or keyboard focus, with no + * delay, as in v3. Its item keeps the highlight while it is open. */ +.aat-top-dropdown { + display: none; + position: absolute; + top: 100%; + inset-inline-start: 0; +} +[data-aat-top-item]:is(:hover, :has(:focus-visible)) > .aat-top-dropdown { + display: block; +} +[data-aat-top-item][data-aat-flip] > .aat-top-dropdown { + inset-inline-start: auto; + inset-inline-end: 0; +} +[data-aat-top-item]:is(:hover, :has(:focus-visible)) > a { background-color: var(--aat-menu-pill); color: var(--aat-menu-hover-text); } @@ -583,9 +650,10 @@ body { z-index: 30; gap: 0.75rem; padding: 0 0.625rem; + /* A real border, inside the fixed height, so a hovered menu link stops above it. */ border: 0; - /* An inset shadow, so the fixed header keeps its --aa-header-height. */ - box-shadow: inset 0 -1px 0 var(--aat-header-border); + border-bottom: 1px solid var(--aat-header-border); + box-shadow: none; backdrop-filter: none; background-color: var(--aat-header-bg); color: var(--aat-header-text); @@ -696,7 +764,19 @@ body { display: none; } -/* v3 drew EMPTY in #bbb in both modes; ActiveAdmin's dark gray-600/50 is barely readable. */ +/* A long preformatted value in an attributes table scrolls inside its cell. A + * pre_wrap with its own max_height keeps it. */ +.attributes-table :where(tbody > tr > td) > pre:not(.aat-pre-wrap-capped) { + max-height: var(--aat-attributes-pre-max-height, 24rem); + overflow: auto; +} + +/* 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/app/tailwind/components/sidebar_tab.css b/app/tailwind/components/sidebar_tab.css index 4728dc2..23351e1 100644 --- a/app/tailwind/components/sidebar_tab.css +++ b/app/tailwind/components/sidebar_tab.css @@ -28,3 +28,14 @@ border-inline-end: 0; border-inline-start: 5px solid #ffffff; } + +/* With the sidebar open, the tab sits against the sidebar and keeps a v3-sized + gap from the page. Collapsed, the page keeps its own spacing. */ +@media (width >= 48rem) { + [data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]) { + column-gap: 1.625rem; + } + [data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]) .aat-sidebar-tab { + inset-inline-start: -1.625rem; + } +} diff --git a/app/views/active_admin/_flash_messages.html.erb b/app/views/active_admin/_flash_messages.html.erb index 2472c01..de87a31 100644 --- a/app/views/active_admin/_flash_messages.html.erb +++ b/app/views/active_admin/_flash_messages.html.erb @@ -5,3 +5,4 @@ <% end %> <% end %> +<%= render "active_admin/page_banner" unless local_assigns[:page_banner] == false %> diff --git a/app/views/active_admin/_header_navigation.html.erb b/app/views/active_admin/_header_navigation.html.erb index 67165c3..1564977 100644 --- a/app/views/active_admin/_header_navigation.html.erb +++ b/app/views/active_admin/_header_navigation.html.erb @@ -5,14 +5,14 @@ <% url = item.url(self) %> <% current = current_menu_item?(item) %> <% classes = "flex items-center h-full px-2.5 no-underline text-(--aat-header-text) hover:bg-(--aat-menu-pill) hover:text-(--aat-menu-hover-text) #{'bg-(--aat-menu-pill) text-(--aat-menu-hover-text) selected' if current}" %> -