Skip to content

Commit 5b1544f

Browse files
feat: add '← Back to main menu' row and remove mobile sidebar divider
- Add .sidebar-back button below the mobile header, hidden on desktop, matching Docusaurus's secondary-panel back-link appearance; clicking it removes the 'open' class from .sidebar-container to close the panel (handled via extended _toggleScript event delegation) - Remove border-bottom from .sidebar-mobile-header (and its dark mode override) so there is no divider line between the header row and the back-link row, matching the Docusaurus screenshot
1 parent 52d47b9 commit 5b1544f

1 file changed

Lines changed: 63 additions & 18 deletions

File tree

β€Žsite_jaspr/lib/components/collapsible_sidebar.dartβ€Ž

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ class CollapsibleSidebar extends StatelessComponent {
5858
final currentRoute = context.page.url;
5959

6060
return Component.fragment([
61-
Document.head(children: [
62-
script(defer: true, content: _toggleScript),
63-
]),
61+
Document.head(
62+
children: [
63+
script(defer: true, content: _toggleScript),
64+
],
65+
),
6466
nav(classes: 'sidebar', [
6567
// Mobile-only header: nav items (flex row) + close button.
6668
// Mirrors Docusaurus's navbar-sidebar__brand / navbar-sidebar__items.
@@ -96,6 +98,14 @@ class CollapsibleSidebar extends StatelessComponent {
9698
],
9799
),
98100
]),
101+
// Mobile-only "← Back to main menu" β€” mirrors Docusaurus's secondary
102+
// panel back-link; closes the sidebar panel when clicked.
103+
// Hidden on desktop (β‰₯ 1024 px) via CSS.
104+
button(
105+
classes: 'sidebar-back',
106+
attributes: {'type': 'button'},
107+
[Component.text('← Back to main menu')],
108+
),
99109
div(classes: 'sidebar-group', [
100110
ul([
101111
for (final item in items) _buildItem(item, currentRoute),
@@ -132,8 +142,13 @@ class CollapsibleSidebar extends StatelessComponent {
132142
href: item.href,
133143
// Full .active (color + bg tint) when the category page itself is
134144
// current; color-only .parent-active when a child page is current.
135-
classes: 'sidebar-link sidebar-category-link'
136-
'${isActive ? ' active' : isChildActive ? ' parent-active' : ''}',
145+
classes:
146+
'sidebar-link sidebar-category-link'
147+
'${isActive
148+
? ' active'
149+
: isChildActive
150+
? ' parent-active'
151+
: ''}',
137152
[Component.text(item.text)],
138153
),
139154
button(
@@ -166,8 +181,7 @@ class CollapsibleSidebar extends StatelessComponent {
166181
li([
167182
a(
168183
href: child.href,
169-
classes:
170-
'sidebar-link${currentRoute == child.href ? ' active' : ''}',
184+
classes: 'sidebar-link${currentRoute == child.href ? ' active' : ''}',
171185
[Component.text(child.text)],
172186
),
173187
]),
@@ -177,14 +191,22 @@ class CollapsibleSidebar extends StatelessComponent {
177191
);
178192
}
179193

180-
/// Toggles the `.expanded` class on `.sidebar-collapsible` when the caret
181-
/// button is clicked. The link itself navigates normally (browser default).
194+
/// Handles sidebar interactions:
195+
/// - `.sidebar-caret` clicks toggle the `.expanded` class on the parent
196+
/// collapsible item.
197+
/// - `.sidebar-back` clicks close the mobile sidebar panel (same as Γ—).
182198
static const _toggleScript = '''
183199
(function(){
184200
document.addEventListener('click', function(e){
185201
var caret = e.target.closest('.sidebar-caret');
186-
if (!caret) return;
187-
caret.closest('.sidebar-collapsible').classList.toggle('expanded');
202+
if (caret) {
203+
caret.closest('.sidebar-collapsible').classList.toggle('expanded');
204+
return;
205+
}
206+
if (e.target.closest('.sidebar-back')) {
207+
var c = document.querySelector('.sidebar-container');
208+
if (c) c.classList.remove('open');
209+
}
188210
});
189211
})();
190212
''';
@@ -206,9 +228,6 @@ class CollapsibleSidebar extends StatelessComponent {
206228
css('&').styles(
207229
display: Display.flex,
208230
padding: Padding.symmetric(horizontal: 0.5.rem, vertical: 0.5.rem),
209-
border: Border.only(
210-
bottom: BorderSide(width: 1.px, color: Color('#dadde1')),
211-
),
212231
alignItems: AlignItems.center,
213232
raw: {'flex-shrink': '0'},
214233
),
@@ -255,6 +274,34 @@ class CollapsibleSidebar extends StatelessComponent {
255274
),
256275
]),
257276

277+
// ── "← Back to main menu" button ────────────────────────────────────
278+
// Shown only on mobile. Mirrors Docusaurus's secondary-panel back link.
279+
// Clicking closes the sidebar panel (handled in _toggleScript).
280+
css('.sidebar-back', [
281+
css('&').styles(
282+
display: Display.block,
283+
width: Unit.percent(100),
284+
padding: Padding.symmetric(horizontal: 0.75.rem, vertical: 0.625.rem),
285+
opacity: 0.7,
286+
cursor: Cursor.pointer,
287+
transition: Transition('all', duration: 150.ms, curve: Curve.easeInOut),
288+
fontSize: 0.875.rem,
289+
raw: {
290+
'text-align': 'left',
291+
'background': 'none',
292+
'border': 'none',
293+
'color': 'inherit',
294+
},
295+
),
296+
css('&:hover').styles(
297+
opacity: 1,
298+
backgroundColor: Color('rgba(0, 0, 0, 0.05)'),
299+
),
300+
css.media(MediaQuery.all(minWidth: 1024.px), [
301+
css('&').styles(display: Display.none),
302+
]),
303+
]),
304+
258305
// ── Sidebar link group ───────────────────────────────────────────────
259306
css('.sidebar-group', [
260307
css('&').styles(
@@ -371,10 +418,8 @@ class CollapsibleSidebar extends StatelessComponent {
371418
css('[data-theme="dark"] .sidebar-close:hover').styles(
372419
backgroundColor: Color('rgba(255, 255, 255, 0.05)'),
373420
),
374-
css('[data-theme="dark"] .sidebar-mobile-header').styles(
375-
border: Border.only(
376-
bottom: BorderSide(width: 1.px, color: Color('#444950')),
377-
),
421+
css('[data-theme="dark"] .sidebar-back:hover').styles(
422+
backgroundColor: Color('rgba(255, 255, 255, 0.05)'),
378423
),
379424
];
380425
}

0 commit comments

Comments
Β (0)