Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down
16 changes: 12 additions & 4 deletions app/javascript/active_admin_theme/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
114 changes: 97 additions & 17 deletions app/tailwind/active_admin_theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand All @@ -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. */
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Comment thread
senid231 marked this conversation as resolved.
Resolved
}
.dark .attributes-table-empty-value {
color: #bbbbbb;
color: #8a929c;
}
11 changes: 11 additions & 0 deletions app/tailwind/components/sidebar_tab.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions app/views/active_admin/_flash_messages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
<% end %>
</div>
<% end %>
<%= render "active_admin/page_banner" unless local_assigns[:page_banner] == false %>
6 changes: 3 additions & 3 deletions app/views/active_admin/_header_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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}" %>
<li class="relative" data-item-id="<%= item.id %>">
<li class="relative" data-item-id="<%= item.id %>" <%= "data-aat-top-item" if children %>>
<% if children %>
<% menu_id = "top-menu-#{item.id}" %>
<%= link_to url.presence || "#", item.html_options.merge(class: "#{classes} gap-1", data: { dropdown_toggle: menu_id, dropdown_trigger: "hover", dropdown_placement: "bottom-start", dropdown_offset_distance: 0, dropdown_delay: 100 }) do %>
<%= link_to url.presence || "#", item.html_options.merge(class: "#{classes} gap-1", "aria-haspopup": "true", "aria-controls": menu_id) do %>
<%= item.label(self) %>
<svg class="size-3.5 shrink-0 opacity-70" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z" clip-rule="evenodd" /></svg>
<% end %>
<div id="<%= menu_id %>" class="hidden z-40 min-w-40 max-w-65 py-1 text-[13px] bg-(--aat-menu-panel) text-(--aat-menu-text) shadow-lg">
<div id="<%= menu_id %>" class="aat-top-dropdown z-40 min-w-40 max-w-65 py-1 text-[13px] bg-(--aat-menu-panel) text-(--aat-menu-text) shadow-lg">
<%= render "active_admin_theme/menu_flyout", items: children %>
</div>
<% elsif url.present? %>
Expand Down
1 change: 1 addition & 0 deletions app/views/active_admin/_page_banner.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%# Empty on purpose: rendered below the flash messages on logged-in pages. An app overrides app/views/active_admin/_page_banner.html.erb to show a banner, such as the environment name. %>
2 changes: 1 addition & 1 deletion app/views/layouts/active_admin_logged_out.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</head>
<body class="bg-(--aat-page-bg) text-(--aat-text) antialiased">
<div class="flex flex-col items-center justify-center min-h-screen py-4 sm:px-6 sm:py-8 mx-auto" data-aat-login>
<%= render "active_admin/flash_messages" %>
<%= render "active_admin/flash_messages", page_banner: false %>
<%= yield %>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/migrating-from-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 13 additions & 6 deletions lib/active_admin_theme/page_objects/confirm_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ def field(locator)
own ? own.find("input:not([type=hidden]), select, textarea", match: :first) : modal.find(:field, locator.to_s)
end

# Clicks the confirm button, which submits the dialog's form. The
# browser keeps the dialog open while a required field is empty;
# +validate: false+ skips that check, so the server's own check runs.
# Waits for the confirm button to be enabled, then clicks it, which
# submits the dialog's form. The browser keeps the dialog open while a
# required field is empty; +validate: false+ skips that check, so the
# server's own check runs.
def confirm(validate: true)
button = modal.find(:active_admin, :confirm_dialog_submit)
button = enabled_button(:confirm_dialog_submit)
button.session.execute_script("arguments[0].form.noValidate = true", button) unless validate
button.click
end

# Clicks the cancel button and waits for the dialog to close.
# Waits for the cancel button to be enabled, clicks it, and waits for
# the dialog to close.
def cancel
modal.find(:active_admin, :confirm_dialog_cancel).click
enabled_button(:confirm_dialog_cancel).click
has_no_open?
end

Expand All @@ -138,6 +140,11 @@ def modal
find(:active_admin, :confirm_dialog_modal, visible: true)
end

# A dialog can enable its buttons after async content loads.
def enabled_button(key)
modal.find(:css, "#{sel(key)}:not(:disabled)")
end

def set_control(control, value)
if control.tag_name == "select"
Array(value).each { |text| control.select(text.to_s) }
Expand Down
9 changes: 9 additions & 0 deletions test/components_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading
Loading