feat: sidebar for mobiles

This commit is contained in:
Lucas
2026-10-26 15:27:04 +01:00
parent cb34e5ef41
commit 845b23cf21
7 changed files with 184 additions and 9 deletions
+103 -1
View File
@@ -2,7 +2,7 @@
.sidebar-rail {
position: fixed;
top: var(--header-height);
top: var(--topbar-h);
left: 0;
bottom: 0;
@@ -416,3 +416,105 @@
max-width: 200px;
border: none;
}
/* ---------- Phone / touch ---------- */
.sidebar-backdrop {
display: none;
}
@media (hover: none) {
.sidebar-item:hover {
background: transparent;
color: var(--text-muted);
border-color: transparent;
}
.sidebar-item--active:hover {
color: var(--text-primary);
border-color: var(--accent-brand);
}
.sidebar-toggle:hover {
background: var(--bg-void);
color: var(--text-muted);
border-color: transparent;
}
.sidebar-app-trigger:hover {
border-color: var(--border-hairline);
}
}
@media (pointer: coarse) {
/* Cancel the global 44px min-height, sizes are set explicitly below */
.sidebar-rail button {
min-height: 0;
}
/* No iOS/Android callout menu on long-press (we use it for rename) */
.sidebar-item,
.sidebar-app-trigger {
-webkit-touch-callout: none;
}
}
@media (max-width: 768px) {
.sidebar-rail {
top: var(--topbar-h);
bottom: 0;
padding-bottom: var(--safe-bottom);
padding-left: var(--safe-left);
width: calc(var(--sidebar-width-collapsed) + var(--safe-left));
}
/* Expanded = drawer on top of the content, not pushing it */
.sidebar-rail--expanded {
width: calc(var(--sidebar-width-expanded) + var(--safe-left));
z-index: 50;
box-shadow: 8px 0 24px rgba(0, 0, 0, 0.45);
}
.app-root--sidebar-expanded .sidebar-backdrop {
display: block;
position: fixed;
top: var(--topbar-h);
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 45;
}
.sidebar-scroll {
overscroll-behavior: contain;
-webkit-overflow-scrolling: touch;
}
/* Touch-sized items */
.sidebar-item,
.sidebar-item--editing {
height: 44px;
}
.sidebar-rail--expanded .sidebar-item {
width: 100%;
}
.sidebar-toggle {
height: 40px;
}
/* Preset dropdown */
.sidebar-app-trigger,
.sidebar-app-input {
height: 40px;
}
.sidebar-app-input,
.sidebar-item-input {
font-size: 16px; /* prevents iOS focus-zoom */
}
.sidebar-app-listbox {
max-height: min(240px, 50dvh);
-webkit-overflow-scrolling: touch;
}
.sidebar-app-option {
padding: var(--space-3) var(--space-2);
font-size: var(--font-sm);
}
}
+11 -1
View File
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import './Sidebar.css';
import { ChevronLeftIcon } from '../../assets/icons/ChevronLeftIcon';
import { useLongPress } from '../../hooks/useLongPress';
export type SidebarItem<T extends string = string> = {
id: T;
@@ -33,7 +34,7 @@ function SidebarButton<T extends string>({
if (!editing) setInputValue(item.label);
}, [item.label, editing]);
function startEditing(e: React.MouseEvent) {
function startEditing(e: { stopPropagation(): void }) {
e.stopPropagation();
if (!onRename) return;
@@ -68,6 +69,11 @@ function SidebarButton<T extends string>({
}
}
const longPress = useLongPress((e, el) => {
// only when the drawer is open (labels are invisible when collapsed)
if (onRename && el.closest('.sidebar-rail--expanded')) startEditing(e);
});
if (editing) {
return (
<div className="sidebar-item sidebar-item--editing">
@@ -90,6 +96,7 @@ function SidebarButton<T extends string>({
return (
<button
onClick={onSelect}
{...longPress}
title={item.label}
aria-label={item.label}
aria-current={active ? 'page' : undefined}
@@ -132,6 +139,8 @@ function AppCombobox({
const rootRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
const longPress = useLongPress((e) => startEditing(e));
useEffect(() => {
if (!editing) setInputValue(currentOption?.name ?? appName);
}, [currentOption?.id, currentOption?.name, appName, editing]);
@@ -256,6 +265,7 @@ function AppCombobox({
className={'sidebar-app-trigger' + (open ? ' sidebar-app-trigger--open' : '')}
onClick={() => (open ? setOpen(false) : openList())}
onDoubleClick={startEditing}
{...longPress}
onKeyDown={handleKeyDown}
aria-haspopup="listbox"
aria-expanded={open}