feat: sidebar for mobiles
This commit is contained in:
@@ -13,10 +13,11 @@
|
||||
"windows": [
|
||||
{
|
||||
"title": "Thomann DSP Controller",
|
||||
"width": 360,
|
||||
"height": 800,
|
||||
"minWidth": 320,
|
||||
"minHeight": 500
|
||||
"width": 1600,
|
||||
"height": 950,
|
||||
"minWidth": 1200,
|
||||
"minHeight": 600
|
||||
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
position: fixed;
|
||||
left: var(--sidebar-width-collapsed);
|
||||
right: 0;
|
||||
top: var(--header-height);
|
||||
top: var(--topbar-h, var(--header-height));
|
||||
bottom: 0;
|
||||
|
||||
display: flex;
|
||||
@@ -21,7 +21,7 @@
|
||||
position: fixed;
|
||||
left: var(--sidebar-width-collapsed);
|
||||
right: 0;
|
||||
top: var(--header-height, 0);
|
||||
top: var(--topbar-h, var(--header-height));
|
||||
bottom: 0;
|
||||
transition: left var(--dur-base) var(--ease-standard);
|
||||
}
|
||||
@@ -35,3 +35,19 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.sidebar-backdrop {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dsp-content,
|
||||
.dsp-loading-overlay,
|
||||
.app-root:has(.sidebar-rail--expanded) .dsp-content,
|
||||
.app-root:has(.sidebar-rail--expanded) .dsp-loading-overlay {
|
||||
top: var(--topbar-h);
|
||||
bottom: var(--safe-bottom);
|
||||
left: calc(var(--sidebar-width-collapsed) + var(--safe-left));
|
||||
right: var(--safe-right);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import { SidebarId } from '../../constants';
|
||||
import './DSP408Panel.css';
|
||||
import MiscellaneousPanel from '../MiscellaneousSection/MiscellaneousSection';
|
||||
import { PasswordDialog } from '../PasswordDialog/PasswordDialog';
|
||||
import { useIsMobile } from '../../../../hooks/useIsMobile';
|
||||
|
||||
const activeSidebarByDsp = new Map<number, SidebarId>();
|
||||
|
||||
@@ -36,6 +37,7 @@ function DSP408Panel({ dsp, api }: { dsp: DSP408; api: DSP408Api }) {
|
||||
const [sidebarExpanded, setSidebarExpanded] = useState(false);
|
||||
const [selectedPreset, setSelectedPreset] = useState(dsp.state.presets.current_index);
|
||||
const [presetLoading, setPresetLoading] = useState(false);
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const inputStates = dsp.state.current_config.input_states;
|
||||
const outputStates = dsp.state.current_config.output_states;
|
||||
@@ -80,6 +82,11 @@ function DSP408Panel({ dsp, api }: { dsp: DSP408; api: DSP408Api }) {
|
||||
() => activeSidebarByDsp.get(dsp.id) ?? 'overview'
|
||||
);
|
||||
|
||||
const handleSelect = (id: SidebarId) => {
|
||||
setActiveSidebar(id);
|
||||
if (isMobile) setSidebarExpanded(false); // close drawer after picking
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const saved = activeSidebarByDsp.get(dsp.id) ?? 'overview';
|
||||
setActiveSidebarState(saved);
|
||||
@@ -204,10 +211,11 @@ function DSP408Panel({ dsp, api }: { dsp: DSP408; api: DSP408Api }) {
|
||||
|
||||
return (
|
||||
<div className={`app-root ${sidebarExpanded ? 'app-root--sidebar-expanded' : ''}`}>
|
||||
<div className="sidebar-backdrop" onClick={() => setSidebarExpanded(false)} />
|
||||
<Sidebar
|
||||
items={sidebarItems}
|
||||
activeId={activeSidebar}
|
||||
onSelect={setActiveSidebar}
|
||||
onSelect={handleSelect}
|
||||
appName={dsp.name}
|
||||
appOptions={presets}
|
||||
selectedAppId={presets[selectedPreset]?.id}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { useRef } from 'react';
|
||||
|
||||
export function useLongPress(
|
||||
onLong: (e: React.PointerEvent, el: HTMLElement) => void,
|
||||
ms = 500
|
||||
) {
|
||||
const timer = useRef<number>(0);
|
||||
const clear = () => window.clearTimeout(timer.current);
|
||||
|
||||
return {
|
||||
onPointerDown: (e: React.PointerEvent<HTMLElement>) => {
|
||||
if (e.pointerType !== 'touch') return; // mouse keeps double-click
|
||||
const el = e.currentTarget; // currentTarget is null inside a timeout
|
||||
clear();
|
||||
timer.current = window.setTimeout(() => onLong(e, el), ms);
|
||||
},
|
||||
onPointerUp: clear,
|
||||
onPointerLeave: clear,
|
||||
onPointerCancel: clear, // fires when the user scrolls
|
||||
onContextMenu: (e: React.MouseEvent) => e.preventDefault(),
|
||||
};
|
||||
}
|
||||
@@ -90,4 +90,20 @@
|
||||
|
||||
/* ---------- DSP ---------- */
|
||||
--dsp-control-heigth: 40%;
|
||||
|
||||
/* ---------- Mobile ---------- */
|
||||
--safe-top: env(safe-area-inset-top, 0px);
|
||||
--safe-bottom: env(safe-area-inset-bottom, 0px);
|
||||
--safe-left: env(safe-area-inset-left, 0px);
|
||||
--safe-right: env(safe-area-inset-right, 0px);
|
||||
--topbar-h: calc(var(--header-height) + var(--safe-top));
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
:root {
|
||||
--header-height: 56px;
|
||||
--tab-height: 40px;
|
||||
--sidebar-width-collapsed: 56px;
|
||||
--sidebar-width-expanded: min(80vw, 280px);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user