mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
8955790f17
- Top bar: the segmented control keeps to the room between the back button and the trailing button, draws its segments tighter and then scrolls with faded edges instead of covering the back button. On a wide window every list tab puts its primary pill in the middle and its round buttons at the trailing end, so the pill no longer jumps between tabs. - Day strip: a chevron over the faded end pages the days along on a wide window, and the fade reaches further; the chips keep clear of it. - Plan pane: the day card ends on the rail's bottom line beside the map (as tall as its day across the page), scrolls inside a frame and fades the rows at its edges. Addresses and the hotel chip end in an ellipsis instead of being cut mid-letter; the weather chip keeps its width. - Map: in the dark theme the map beside the pane takes the dark basemap. - Places: the All / Unplanned / Planned chips are never narrower than their names and scroll with a faded edge; on a short screen Places/Tours shares their row. - Chat: the list fades out under the floating controls instead of cutting a bubble. Notes and to-do chip rows fade at their edges and New Note stays outside the scrolling chips. - Costs: the balance amounts share a line, the settle-up action wraps to a line of its own, the totals stand under their labels. - Bookings and transports: one column until two cards fit, titles take two lines with the type under them, the time cell is never cut and a range names its unit once. - Files: the preview pane shows a type tile beside the name where no PDF can be drawn in place, its actions keep their labels on one line and wrap as a row, link labels are badges, and a tile that opens its file is no toggle. - Polls get a fill that differs from card and track, packing filters are two segmented controls, empty checkboxes get an edge with 3:1 contrast, and the middle dots between values are gone.
66 lines
2.6 KiB
TypeScript
66 lines
2.6 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
export interface EdgeFade {
|
|
/** Content is scrolled past the leading (or top) edge. */
|
|
start: boolean;
|
|
/** More content waits beyond the trailing (or bottom) edge. */
|
|
end: boolean;
|
|
}
|
|
|
|
/** Which way a scroller runs: a strip of chips sideways, a list or a card down. */
|
|
export type FadeAxis = 'x' | 'y';
|
|
|
|
const NONE: EdgeFade = { start: false, end: false };
|
|
|
|
/**
|
|
* Which ends of a scroller have more behind them, so it can fade out there
|
|
* (m-fade-s / m-fade-e, m-fade-t / m-fade-b in mobile.css) instead of cutting a
|
|
* chip or a row in half with nothing to say the content goes on. Follows
|
|
* scrolling, every change of size (a rotation, a fold, the pane beside the map
|
|
* opening) and every change of what it holds (a day switched, a message in).
|
|
*/
|
|
export function useEdgeFade(el: HTMLElement | null, axis: FadeAxis = 'x'): EdgeFade {
|
|
const [fade, setFade] = useState<EdgeFade>(NONE);
|
|
useEffect(() => {
|
|
if (!el) return;
|
|
const measure = () => {
|
|
// scrollLeft runs from 0 towards the negative in a right-to-left strip.
|
|
const scrolled = Math.abs(axis === 'x' ? el.scrollLeft : el.scrollTop);
|
|
const room = axis === 'x' ? el.scrollWidth - el.clientWidth : el.scrollHeight - el.clientHeight;
|
|
const next = { start: scrolled > 1, end: room - scrolled > 1 };
|
|
setFade((prev) => (prev.start === next.start && prev.end === next.end ? prev : next));
|
|
};
|
|
measure();
|
|
el.addEventListener('scroll', measure, { passive: true });
|
|
const resize = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(measure);
|
|
resize?.observe(el);
|
|
// New content changes what lies past an edge without changing the box itself.
|
|
let frame = 0;
|
|
const changed =
|
|
typeof MutationObserver === 'undefined'
|
|
? null
|
|
: new MutationObserver(() => {
|
|
cancelAnimationFrame(frame);
|
|
frame = requestAnimationFrame(measure);
|
|
});
|
|
changed?.observe(el, { childList: true, subtree: true, characterData: true });
|
|
return () => {
|
|
el.removeEventListener('scroll', measure);
|
|
resize?.disconnect();
|
|
changed?.disconnect();
|
|
cancelAnimationFrame(frame);
|
|
};
|
|
}, [el, axis]);
|
|
return fade;
|
|
}
|
|
|
|
/** The mask classes for a fade state: sideways by default, `y` for a scroller that runs down. */
|
|
export function edgeFadeClass(fade: EdgeFade, axis: FadeAxis = 'x'): string {
|
|
const [both, start, end] =
|
|
axis === 'x' ? ['m-fade-se', 'm-fade-s', 'm-fade-e'] : ['m-fade-tb', 'm-fade-t', 'm-fade-b'];
|
|
if (fade.start && fade.end) return both;
|
|
if (fade.start) return start;
|
|
if (fade.end) return end;
|
|
return '';
|
|
}
|