Files
TREK/client/src/mobile/components/MNavRail.tsx
T
Maurice 5346182807 fix(mobile): the rail, the docks and the top-level screens on a large screen
From the large-screen review (visual findings of the shell and the top-level
screens):

- Rail: 80px wide, one caption size for every name (no shrinking per item),
  balanced two-line names with every entry as tall as the tallest, short rail
  names where a language's word is too long (mobileNav.rail*, all locales),
  and near-opaque glass so a map's colours no longer smear through it.
- Rail head: always one 56px circle, so the entries never jump between pages:
  the create action, the screen's own action (the vacation calendar's
  year/editor switch moves there instead of floating over the days) or the
  quiet logo on settings and administration. It stays put while a short rail
  scrolls.
- Vacation calendar: weekday letters over each month on a wide window; the
  editor's mode switch sits at the foot with room kept for it.
- Docks: More is marked with a ring rather than the centre button's fill, the
  dock glass is denser, and lists fade out under the dock instead of showing
  in the gap below it.
- Dashboard: trip names get the card's width with the dates under them, the
  hero's facts wrap as whole chips, the filter chips scroll with a fade, the
  hero ends above the dock on a phone on its side and its buttons sit on a
  dark ground; the header bar stands in the content's column.
- Journeys: on a wide window the header is the same glass bar, in the column
  of the cards, and the other journeys' label starts with them.
- Notifications: the round chevron back button, in the list's column.
- Settings and administration share one frame and width. Admin's new-user
  action sits under the section list's title, the users card header wraps
  inside the card, stat labels ellipsize, role badges read in dark mode.
- Collections: one card per place with the status inside it, worded in a
  readable mix of its colour.
- Atlas and the journey map frame clear of the rail and the header; the
  journey's day bar sits on a glass plate, and a phone on its side gets
  smaller cards.
- Rail label tests rewritten for the new rule; FE-MOB-PANES-016 duplicate
  renumbered to 017.
2026-11-07 23:25:15 +01:00

160 lines
5.7 KiB
TypeScript

import type { LucideIcon } from 'lucide-react';
import { Plus, Search, Settings2, Shield, Sparkles, Upload } from 'lucide-react';
import { useLocation, useNavigate } from 'react-router';
import { useAssistantHomeLauncher } from '../../components/Assistant/useAssistantHome';
import { useNavItems } from '../../components/Layout/navItems';
import { isNavItemActive, useCreateAction } from '../../components/Layout/useCreateAction';
import { useTranslation } from '../../i18n';
import { useAuthStore } from '../../store/authStore';
import MFab from './MFab';
import { MRail, MRailButton, MRailSpacer } from './MRail';
import { useRailAction } from './railAction';
interface RailEntry {
id: string;
label: string;
icon: LucideIcon;
active: boolean;
go: () => void;
}
const FOCUS_RING =
'outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--m-act)] focus-visible:ring-offset-2 focus-visible:ring-offset-[color:var(--m-bg)]';
/**
* The touch shell's navigation on a wide window (hooks/sizeClass.ts): a rail
* on the leading edge, where an iPad app keeps its sidebar, in place of the
* phone's bottom dock.
*
* It has the room the dock lacks, so every destination sits in it at once,
* with its name under the icon: the dock's own items, the ones the phone keeps
* under More, the home assistant, and settings and administration at the foot,
* which the phone reaches through the avatar menu.
*
* Its head is always one 56px circle, so no entry moves when the page changes:
* the create action with the dock's context-aware meaning, the screen's own
* action where it has one (the vacation calendar's switch), or the dock's
* quiet logo where there is nothing to create (settings, administration).
*/
export default function MNavRail() {
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const create = useCreateAction(true);
const assistant = useAssistantHomeLauncher();
const isAdmin = useAuthStore((s) => s.user?.role === 'admin');
const navItems = useNavItems();
const screenAction = useRailAction();
const isActive = (to: string) => isNavItemActive(location.pathname, to);
const main: RailEntry[] = [
...navItems.map(({ id, to, label, icon }) => ({
id: to,
// A few names are too long for a rail in some languages; the rail has its own words for those.
label: id === 'collections' ? t('mobileNav.railCollections') : label,
icon,
active: isActive(to),
go: () => void navigate(to),
})),
...(assistant.available
? [{ id: 'assistant', label: t('assistant.launcher.tooltip'), icon: Sparkles, active: false, go: assistant.open }]
: []),
];
const foot: RailEntry[] = [
{
id: '/settings',
label: t('mobileNav.railSettings'),
icon: Settings2,
active: isActive('/settings'),
go: () => void navigate('/settings'),
},
...(isAdmin
? [
{
id: '/admin',
label: t('mobileNav.railAdmin'),
icon: Shield,
active: isActive('/admin'),
go: () => void navigate('/admin'),
},
]
: []),
];
const path = location.pathname;
const nothingToCreate = path.startsWith('/settings') || path.startsWith('/admin');
// /vacay draws its own action (the year/editor switch) into the head, as it
// does into the dock's centre on the phone; until it has, the slot stays empty.
const screenOwnsHead = path.startsWith('/vacay');
const searchFab = path.startsWith('/atlas');
let head;
if (nothingToCreate) {
head = (
<span
aria-hidden="true"
className="flex h-14 w-14 items-center justify-center rounded-full bg-[color:var(--m-ic)] opacity-70"
>
<img src="/icons/icon-dark.svg" alt="" className="block h-6 w-6 opacity-75 dark:hidden" />
<img src="/icons/icon-white.svg" alt="" className="hidden h-6 w-6 opacity-75 dark:block" />
</span>
);
} else if (screenOwnsHead) {
head = screenAction ? <ScreenActionButton /> : <span aria-hidden="true" className="h-14 w-14" />;
} else {
head = (
<MFab onClick={create.run} ariaLabel={create.label} className={FOCUS_RING}>
{searchFab ? (
<Search size={22} strokeWidth={2.4} />
) : create.upload ? (
<Upload size={21} strokeWidth={2.4} />
) : (
<Plus size={24} strokeWidth={2.4} />
)}
</MFab>
);
}
return (
<MRail label={t('mobileNav.navigation')} fixed head={head}>
{main.map((entry) => (
<RailEntryButton key={entry.id} {...entry} />
))}
<MRailSpacer />
<div aria-hidden="true" className="my-1 h-px w-8 flex-none bg-[color:var(--m-rowbr)]" />
{foot.map((entry) => (
<RailEntryButton key={entry.id} {...entry} />
))}
</MRail>
);
}
/** The screen's own action, drawn like the dock's circle: filled, or a ring while it is on. */
function ScreenActionButton() {
const action = useRailAction();
if (!action) return null;
const Icon = action.icon;
return (
<button
type="button"
onClick={action.run}
aria-label={action.label}
className={`flex h-14 w-14 flex-none items-center justify-center rounded-full transition-[background,color] duration-300 ease-in-out ${FOCUS_RING} ${
action.pressed
? 'border-2 border-[color:var(--m-act)] bg-[color:var(--m-sheetop)] text-m-ink'
: 'bg-m-act text-m-actfg shadow-[0_8px_20px_-6px_rgba(0,0,0,.4)]'
}`}
>
<Icon size={24} strokeWidth={2.3} />
</button>
);
}
function RailEntryButton({ label, icon: Icon, active, go }: RailEntry) {
return (
<MRailButton label={label} active={active} onClick={go}>
<Icon size={20} strokeWidth={active ? 2.1 : 1.9} />
</MRailButton>
);
}