From 5737b2f7dcf2625758898e9bafeedade1be842d1 Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <davidsneighbourdev+gh@gmail.com>
Date: Thu, 19 Nov 2026 11:51:53 +0000
Subject: [PATCH] feat(css): collapse the header navigation below 60em

---
 assets/ananke/css/navigation-classes.css |  160 ++++++++++++++++++++++
 assets/ananke/css/_styles.css            |  217 +++++++++++++++++++++++-------
 2 files changed, 324 insertions(+), 53 deletions(-)

diff --git a/assets/ananke/css/_styles.css b/assets/ananke/css/_styles.css
index cc12d4f..61b7d5f 100644
--- a/assets/ananke/css/_styles.css
+++ b/assets/ananke/css/_styles.css
@@ -19,111 +19,222 @@
 }
 
 /* ------------------------------------------------------------------ *
- * Header navigation submenus (see layouts/_partials/site-navigation.html)
- * Without JavaScript the child list stays visible in the page flow.
- * site-scripts.html reveals the toggle button and collapses the list;
- * only then is the list positioned as a dropdown.
+ * Header navigation (see layouts/_partials/site-navigation.html)
+ *
+ * Colours, type, and spacing come from Tachyons classes in the template;
+ * sites replace them with [params.ananke.navigation.classes]. This file only
+ * holds behaviour: the collapsed panel below the Tachyons `-l` breakpoint and
+ * the dropdown position above it. Without JavaScript the toggle buttons stay
+ * hidden and every list stays visible.
  * ------------------------------------------------------------------ */
 
-.ananke-has-submenu {
-  position: relative;
-}
-
-/* Without JavaScript, align the item with the nested list to the top. */
-.ananke-has-submenu:has(> .ananke-submenu-toggle[hidden]) {
-  vertical-align: top;
-}
-
+.ananke-nav-toggle,
 .ananke-submenu-toggle {
   display: inline-flex;
   align-items: center;
-  gap: 0.25em;
-  min-width: 24px;
-  min-height: 24px;
   justify-content: center;
+  gap: 0.375em;
   margin: 0;
   padding: 0 0.25rem;
+  min-width: 24px;
+  min-height: 24px;
   font: inherit;
   vertical-align: middle;
   background: transparent;
   border: 0;
+  border-radius: 0.25rem;
   cursor: pointer;
 }
 
+.ananke-nav-toggle[hidden],
 .ananke-submenu-toggle[hidden],
 .ananke-submenu[hidden] {
   display: none;
 }
 
-.ananke-submenu-icon {
+.ananke-nav-toggle:focus-visible,
+.ananke-submenu-toggle:focus-visible {
+  outline: 2px solid currentColor;
+  outline-offset: 2px;
+}
+
+.ananke-nav-slot {
+  min-width: 0;
+}
+
+.ananke-submenu-icon,
+.ananke-nav-toggle-icon {
   flex: none;
-  transition: transform 0.15s ease-in-out;
+}
+
+.ananke-submenu-icon,
+.ananke-nav-toggle-line {
+  transition:
+    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
+    opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1);
 }
 
 .ananke-submenu-toggle[aria-expanded="true"] .ananke-submenu-icon {
   transform: rotate(180deg);
 }
 
-.ananke-submenu-toggle:focus-visible {
-  outline: 2px solid currentColor;
-  outline-offset: 2px;
+/* The hamburger lines turn into a cross while the menu is open. */
+.ananke-nav-toggle-line {
+  transform-box: fill-box;
+  transform-origin: center;
+}
+
+.ananke-nav-toggle[aria-expanded="true"] .ananke-nav-toggle-line:nth-child(1) {
+  transform: translateY(5px) rotate(45deg);
+}
+
+.ananke-nav-toggle[aria-expanded="true"] .ananke-nav-toggle-line:nth-child(2) {
+  opacity: 0;
+}
+
+.ananke-nav-toggle[aria-expanded="true"] .ananke-nav-toggle-line:nth-child(3) {
+  transform: translateY(-5px) rotate(-45deg);
 }
 
 .ananke-submenu {
-  font-size: 1rem;
   text-align: start;
 }
 
 .ananke-submenu-nested {
   padding-inline-start: 1rem;
-  padding-inline-end: 0;
-}
-
-.ananke-submenu-item > a,
-.ananke-submenu-item > span {
-  display: block;
-  padding: 0.5rem 1rem;
 }
 
 .ananke-submenu a[aria-current="page"] {
   text-decoration: underline;
+  text-underline-offset: 0.25em;
 }
 
-/* Dropdown, only after the script has revealed the toggle button. */
-.ananke-submenu-toggle:not([hidden]) + .ananke-submenu {
-  position: absolute;
-  top: 100%;
-  inset-inline-start: 0;
-  z-index: 10;
-  min-width: 12rem;
-  max-width: calc(100vw - 2rem);
-  padding: 0.5rem 0;
-  border: 1px solid rgba(255, 255, 255, 0.25);
-  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
+/* Small and medium screens: brand and menu button in one row, an optional
+   slot (search) below, then the menu panel as a stacked list. */
+@media not all and (min-width: 60em) {
+  /* A long site title wraps instead of pushing the menu button down. */
+  .ananke-nav-brand {
+    flex: 1 1 0%;
+    min-width: 0;
+  }
+
+  .ananke-nav-toggle {
+    order: 1;
+    min-height: 2.75rem;
+    padding: 0 0.5rem;
+  }
+
+  .ananke-nav-slot {
+    order: 2;
+    flex-basis: 100%;
+    margin-top: 1rem;
+  }
+
+  .ananke-nav-panel {
+    order: 3;
+    flex-basis: 100%;
+    margin-top: 0.75rem;
+    padding-top: 0.5rem;
+    border-top: 1px solid rgba(255, 255, 255, 0.2);
+  }
+
+  .ananke-nav-collapsed .ananke-nav-panel {
+    display: none;
+  }
+
+  .ananke-nav-menu {
+    margin: 0;
+    padding: 0;
+  }
+
+  .ananke-nav-item {
+    display: flex;
+    flex-wrap: wrap;
+    align-items: center;
+    padding: 0;
+  }
+
+  .ananke-nav-item > .ananke-nav-link,
+  .ananke-nav-item > .ananke-submenu-label {
+    flex: 1 1 auto;
+    padding: 0.5rem 0;
+  }
+
+  .ananke-nav-item > .ananke-submenu-toggle {
+    min-width: 2.75rem;
+    min-height: 2.75rem;
+  }
+
+  /* A parent without a URL: the button spans the row, and its chevron
+     lines up with the chevrons of the other parents. */
+  .ananke-nav-item
+    > .ananke-submenu-label
+    + .ananke-submenu-toggle:not([hidden]) {
+    flex: 1 1 auto;
+    justify-content: space-between;
+    padding: 0;
+    padding-inline-end: 1rem;
+  }
+
+  .ananke-submenu {
+    flex-basis: 100%;
+    margin: 0 0 0.5rem;
+    padding: 0;
+    padding-inline-start: 1rem;
+    background-color: transparent;
+    border: 0;
+  }
+
+  .ananke-submenu-link {
+    padding-inline: 0;
+  }
 }
 
-/* Set by the script when the dropdown would leave the viewport. */
-.ananke-submenu-toggle:not([hidden]) + .ananke-submenu-flip {
-  inset-inline-start: auto;
-  inset-inline-end: 0;
-}
+/* Large screens: one row, submenus as compact dropdowns. */
+@media screen and (min-width: 60em) {
+  .ananke-nav-toggle {
+    display: none;
+  }
 
-/* Narrow screens: the dropdown spans the viewport below its parent item. */
-@media screen and (max-width: 29.99em) {
+  /* The slot shrinks before the row wraps. */
+  .ananke-nav-slot {
+    flex: 1 1 10rem;
+    max-width: 28rem;
+    margin-inline: 1.5rem;
+  }
+
+  .ananke-submenu-toggle {
+    vertical-align: baseline;
+  }
+
   .ananke-has-submenu {
-    position: static;
+    position: relative;
   }
 
   .ananke-submenu-toggle:not([hidden]) + .ananke-submenu {
-    top: auto;
-    inset-inline: 1rem;
-    min-width: 0;
-    max-width: none;
+    position: absolute;
+    top: calc(100% + 0.5rem);
+    inset-inline-start: 0;
+    z-index: 10;
+    min-width: 11rem;
+    max-width: calc(100vw - 2rem);
+  }
+
+  /* Set by the script when the dropdown would leave the viewport. */
+  .ananke-submenu-toggle:not([hidden]) + .ananke-submenu-flip {
+    inset-inline-start: auto;
+    inset-inline-end: 0;
   }
 }
 
+/* Without JavaScript, align an item with a nested list to the top. */
+.ananke-has-submenu:has(> .ananke-submenu-toggle[hidden]) {
+  vertical-align: top;
+}
+
 @media (prefers-reduced-motion: reduce) {
-  .ananke-submenu-icon {
+  .ananke-submenu-icon,
+  .ananke-nav-toggle-line {
     transition: none;
   }
 }
diff --git a/assets/ananke/css/navigation-classes.css b/assets/ananke/css/navigation-classes.css
new file mode 100644
index 0000000..2b2c455
--- /dev/null
+++ b/assets/ananke/css/navigation-classes.css
@@ -0,0 +1,160 @@
+/*
+ * Header navigation: hook classes
+ *
+ * Every class and state that layouts/_partials/site-navigation.html renders,
+ * with empty rules. Ananke does not load this file. To style the navigation,
+ * copy it to `assets/ananke/css/navigation.css` in your site, fill in the rules
+ * you need, delete the rest, and add it to your configuration:
+ *
+ *   [params.ananke]
+ *   custom_css = ["navigation.css"]
+ *
+ * To change colours, type, or spacing with Tachyons classes instead, use
+ * [params.ananke.navigation.classes].
+ *
+ * Breakpoint: below 60em (Tachyons `-l`) the menu collapses behind the menu
+ * button and submenus open inline. From 60em the navigation is one row and
+ * submenus open as dropdowns.
+ */
+
+/* <nav> element. */
+.ananke-nav {
+  /* */
+}
+
+/* Set on .ananke-nav by the script while the menu panel is closed. */
+.ananke-nav-collapsed {
+  /* */
+}
+
+/* Row inside <nav> that holds brand, slot, menu button, and panel. */
+.ananke-nav-inner {
+  /* */
+}
+
+/* Site title or logo link. */
+.ananke-nav-brand {
+  /* */
+}
+
+/* Wrapper of the `navigation-start` hook, for example a search box. */
+.ananke-nav-slot {
+  /* */
+}
+
+/* Menu button below the -l breakpoint. Only visible with JavaScript. */
+.ananke-nav-toggle {
+  /* */
+}
+
+.ananke-nav-toggle[aria-expanded="true"] {
+  /* */
+}
+
+.ananke-nav-toggle-icon {
+  /* */
+}
+
+/* The three lines of the menu icon. */
+.ananke-nav-toggle-line {
+  /* */
+}
+
+.ananke-nav-toggle-label {
+  /* */
+}
+
+/* Collapsible panel with languages, main menu, social links, and the
+   `navigation-end` hook. */
+.ananke-nav-panel {
+  /* */
+}
+
+/* Main menu <ul>. */
+.ananke-nav-menu {
+  /* */
+}
+
+/* Main menu <li>. */
+.ananke-nav-item {
+  /* */
+}
+
+/* Main menu <li> with a submenu. */
+.ananke-has-submenu {
+  /* */
+}
+
+/* Main menu link. */
+.ananke-nav-link {
+  /* */
+}
+
+/* Link to the current page. */
+.ananke-nav-link[aria-current="page"] {
+  /* */
+}
+
+/* Link to a section or parent of the current page. */
+.ananke-nav-link[aria-current="true"] {
+  /* */
+}
+
+/* Name of a parent entry without a URL, shown when JavaScript is off. */
+.ananke-submenu-label {
+  /* */
+}
+
+/* Button that opens a submenu. Only visible with JavaScript. */
+.ananke-submenu-toggle {
+  /* */
+}
+
+.ananke-submenu-toggle[aria-expanded="true"] {
+  /* */
+}
+
+/* Parent entry without a URL that contains the current page. */
+.ananke-submenu-toggle[aria-current="true"] {
+  /* */
+}
+
+/* Chevron inside the submenu button. */
+.ananke-submenu-icon {
+  /* */
+}
+
+/* Submenu <ul> (second level). */
+.ananke-submenu {
+  /* */
+}
+
+/* Set by the script when the dropdown aligns to the other edge to stay in
+   the viewport. */
+.ananke-submenu-flip {
+  /* */
+}
+
+/* Submenu <li>. */
+.ananke-submenu-item {
+  /* */
+}
+
+/* Submenu link, or the name of an entry without a URL. */
+.ananke-submenu-link {
+  /* */
+}
+
+.ananke-submenu-link[aria-current="page"] {
+  /* */
+}
+
+/* Third and deeper levels: nested <ul> inside a submenu item. */
+.ananke-submenu-nested {
+  /* */
+}
+
+/* Wrapper of the `navigation-end` hook, at the end of the panel. */
+.ananke-nav-end {
+  /* */
+}

--
Gitblit v1.10.0