mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +00:00
feat(mobile): the trip's tabs, administration, collections and the journal use the large screen
On an iPad or an unfolded foldable the list screens kept one phone-wide column in the middle of the page. They now lay out for the room they have: - Transports, bookings, polls and tasks put their cards in a grid of as many phone-wide columns as the page holds (CardGrid), three on a 13" iPad on its side, two upright, one in a narrow Split View. - Costs: with room for two panes (split size class) the summary (total, owe and owed, settle up, final budget, categories) stands in a pane of its own beside the expenses, each scrolling on its own (TabPanes). The search field sits in the expenses' column again instead of running past it. - Files: a grid of tiles with each photo's picture; with room for two panes the picked file is previewed beside the grid with what it belongs to and its actions, the way Files on an iPad does. The signed preview address comes through fileRepo.previewUrl. - Packing: the categories stand in columns, each card whole in its column; the action menu drops from its button at a popover's width. - To-dos: the four smart filters as tiles and the trip's lists in a pane beside the tasks, which take the filter's name as their head. - Collab: the chat stays in view at the trailing edge beside the notes, links or polls, and the header switches only the board. The chat keeps its place in the tree, so a fold or a rotation into two panes keeps the draft; a chat at its newest message stays there when its box changes size. Notes stand as a board in columns. - Administration and settings share a section list beside the page (MSectionNav); the stats grid takes four columns. - Collections: the lists stand in a column beside the places, which take two columns, and the head names the list on show. - Journal: the entries become a feed beside the map, under their days, with photo, place and the start of the story, in step with the map like the strip of cards it replaces; it fades out under the header. - The assistant opens as a tall panel at the trailing edge over a dimmed page, as Slide Over would, instead of covering the whole screen. - The rail fits every name: a word too wide for it shrinks the label before it is hyphenated, and the admin entry uses its short name. - The journeys and notifications headers keep to their column. - The address screen of the native shell sets the photo as a panel beside the choices on a large screen on its side. On a foldable that reports its fold, a leading pane ends at the fold and a trailing one starts there. Phones keep their layout.
This commit is contained in:
@@ -62,7 +62,7 @@ export default function MNavRail() {
|
||||
? [
|
||||
{
|
||||
id: '/admin',
|
||||
label: t('nav.bottomAdmin'),
|
||||
label: t('nav.admin'),
|
||||
icon: Shield,
|
||||
active: isActive('/admin'),
|
||||
go: () => void navigate('/admin'),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import { useFitLabel } from './useFitLabel';
|
||||
|
||||
/**
|
||||
* The glass rail on the leading edge that takes the dock's place on a wide
|
||||
* window (hooks/sizeClass.ts): the app's sections (MNavRail) or a trip's
|
||||
@@ -32,9 +34,9 @@ interface MRailButtonProps {
|
||||
|
||||
/**
|
||||
* One destination: the icon on the dock's 40px circle, filled while it is the
|
||||
* current one, its name underneath. Names wrap to two lines rather than being
|
||||
* cut, since a rail entry has no other way to say what it is; the title gives
|
||||
* the whole name to a pointer hovering it.
|
||||
* current one, its name underneath. The name is never cut: it wraps to two
|
||||
* lines and, where a word is still too long for the rail, shrinks to fit
|
||||
* (useFitLabel), since a touch screen has no hover to tell the rest.
|
||||
*/
|
||||
export function MRailButton({ label, active, onClick, children }: MRailButtonProps) {
|
||||
return (
|
||||
@@ -53,13 +55,21 @@ export function MRailButton({ label, active, onClick, children }: MRailButtonPro
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
<span
|
||||
className={`line-clamp-2 w-full hyphens-auto break-words text-center font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] leading-[1.2] ${
|
||||
active ? 'font-bold text-m-ink' : 'font-semibold text-m-muted'
|
||||
}`}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
<RailLabel label={label} active={active} />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function RailLabel({ label, active }: { label: string; active: boolean }) {
|
||||
const ref = useFitLabel<HTMLSpanElement>(label);
|
||||
return (
|
||||
<span
|
||||
ref={ref}
|
||||
className={`line-clamp-2 w-full text-center font-geist text-[length:calc(10px*var(--fs-scale-caption,1)*var(--fit,1))] leading-[1.2] ${
|
||||
active ? 'font-bold text-m-ink' : 'font-semibold text-m-muted'
|
||||
}`}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import { ChevronLeft } from 'lucide-react';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
export interface MSection {
|
||||
id: string;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
}
|
||||
|
||||
interface MSectionRowProps {
|
||||
section: MSection;
|
||||
active: boolean;
|
||||
/** Marks the row as the page on show, for the list that stands beside the page. */
|
||||
current?: boolean;
|
||||
onPick: () => void;
|
||||
}
|
||||
|
||||
/** One section of a settings-like screen, in its dropdown or in the list beside the page. */
|
||||
export function MSectionRow({ section, active, current = false, onPick }: MSectionRowProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onPick}
|
||||
aria-current={current ? 'page' : undefined}
|
||||
className={`flex w-full items-center gap-[10px] rounded-[11px] p-[10px] text-start text-[length:calc(13px*var(--fs-scale-body,1))] font-semibold text-m-ink outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--m-act)] ${
|
||||
active ? 'bg-[color:var(--m-ic)]' : 'hover:bg-[color:var(--m-ic)]'
|
||||
}`}
|
||||
>
|
||||
<section.icon size={15} strokeWidth={2} className="flex-none" />
|
||||
<span className="min-w-0 flex-1 truncate">{section.label}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
interface MSectionNavProps {
|
||||
title: string;
|
||||
backLabel: string;
|
||||
onBack: () => void;
|
||||
sections: MSection[];
|
||||
activeId: string;
|
||||
onPick: (id: string) => void;
|
||||
/** An action of the screen, at the end of the list's head (admin: a new user). */
|
||||
action?: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sections of a settings-like screen (settings, administration) as a list
|
||||
* of their own beside the page, the way Settings on an iPad shows them, once
|
||||
* the window has room for two panes. It stays in view while the page scrolls.
|
||||
* Narrower windows keep the dropdown in the screen's header.
|
||||
*/
|
||||
export default function MSectionNav({
|
||||
title,
|
||||
backLabel,
|
||||
onBack,
|
||||
sections,
|
||||
activeId,
|
||||
onPick,
|
||||
action,
|
||||
}: MSectionNavProps) {
|
||||
return (
|
||||
<nav
|
||||
aria-label={title}
|
||||
className="sticky top-[var(--m-safe-top,12px)] flex max-h-[calc(100dvh-var(--m-safe-top,12px)-16px)] flex-col gap-1 overflow-y-auto rounded-2xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-sheet)] p-[6px] shadow-[0_16px_40px_-24px_rgba(0,0,0,.3)] [scrollbar-width:none]"
|
||||
>
|
||||
<div className="mb-1 flex items-center gap-2 p-[4px]">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={backLabel}
|
||||
onClick={onBack}
|
||||
className="flex h-[34px] w-[34px] flex-none items-center justify-center rounded-full text-m-ink outline-none hover:bg-[color:var(--m-ic)] focus-visible:ring-2 focus-visible:ring-[color:var(--m-act)]"
|
||||
>
|
||||
<ChevronLeft size={18} strokeWidth={2.2} className="rtl:-scale-x-100" />
|
||||
</button>
|
||||
<span className="min-w-0 flex-1 truncate text-subtitle font-bold text-m-ink">{title}</span>
|
||||
{action}
|
||||
</div>
|
||||
{sections.map((section) => (
|
||||
<MSectionRow
|
||||
key={section.id}
|
||||
section={section}
|
||||
active={section.id === activeId}
|
||||
current={section.id === activeId}
|
||||
onPick={() => onPick(section.id)}
|
||||
/>
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useLayoutEffect, useRef } from 'react';
|
||||
|
||||
/** The smallest share of its size a label may shrink to. */
|
||||
const MIN_SCALE = 0.72;
|
||||
const STEP = 0.04;
|
||||
|
||||
/**
|
||||
* Fits a short label into a narrow, fixed box, such as a navigation rail
|
||||
* entry: a name in its own words, on at most two lines, whatever the language.
|
||||
*
|
||||
* The label wraps between words. A word that is still too wide for the box
|
||||
* (German "Einstellungen", Russian "Администрирование") first shrinks the
|
||||
* label, step by step down to MIN_SCALE, the way a tab bar fits its titles; a
|
||||
* name read whole beats one split over two lines. Only a word too long even
|
||||
* then is hyphenated, where the browser knows the language, and past that
|
||||
* broken anywhere. A tap target has no hover, so the whole name has to be on
|
||||
* screen.
|
||||
*
|
||||
* What it settles on is written to the element's own style: `--fit`, which the
|
||||
* element multiplies its font size with, and its hyphenation and wrapping. A
|
||||
* measurement is a fact about the laid-out element, not React state, and
|
||||
* keeping it there spares a second render of every rail entry.
|
||||
*/
|
||||
export function useFitLabel<T extends HTMLElement>(label: string) {
|
||||
const ref = useRef<T>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const el = ref.current;
|
||||
if (!el) return;
|
||||
let cancelled = false;
|
||||
const fits = () => {
|
||||
const lineHeight = parseFloat(getComputedStyle(el).lineHeight) || 0;
|
||||
const tooWide = el.scrollWidth > el.clientWidth + 0.5;
|
||||
const tooTall = lineHeight > 0 && el.scrollHeight > lineHeight * 2 + 1;
|
||||
return !tooWide && !tooTall;
|
||||
};
|
||||
const shrink = (hyphens: 'manual' | 'auto') => {
|
||||
el.style.hyphens = hyphens;
|
||||
let scale = 1;
|
||||
el.style.setProperty('--fit', '1');
|
||||
while (!fits() && scale - STEP >= MIN_SCALE) {
|
||||
scale = Math.round((scale - STEP) * 100) / 100;
|
||||
el.style.setProperty('--fit', String(scale));
|
||||
}
|
||||
return fits();
|
||||
};
|
||||
const measure = () => {
|
||||
if (cancelled) return;
|
||||
el.style.overflowWrap = 'normal';
|
||||
if (shrink('manual') || shrink('auto')) return;
|
||||
el.style.overflowWrap = 'anywhere';
|
||||
};
|
||||
measure();
|
||||
// The label's font may arrive after the first layout, and it measures differently.
|
||||
void document.fonts?.ready.then(measure);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [label]);
|
||||
|
||||
return ref;
|
||||
}
|
||||
Reference in New Issue
Block a user