feat(mobile): one glass language across the day plan's controls

- The rename and reorder controls beside the day's name, and the day and
  weather chips on the timeline card, are now round or pill glass controls of
  one height, so they read as tappable; the stay chips follow.
- A leg between two stops is one pill, as on the desktop: the mode, the time
  in full weight and the distance beside it, larger and without a dot.
- The timeline flows under the up-next card at a fixed 12px, whatever its
  height, instead of an offset that left a gap when the stop has no address.
- The places bar on the map wears the day rail's glass at its 36px height.
- A context menu stays inside all four edges of the screen, measured at its
  real size rather than mid-animation, and scrolls when taller than it.
This commit is contained in:
Maurice
2026-11-06 12:37:00 +01:00
parent 01ddcc63bb
commit 6d093d1102
9 changed files with 129 additions and 53 deletions
@@ -101,12 +101,15 @@ describe('ContextMenu', () => {
expect(onClose).toHaveBeenCalledTimes(2)
})
it('FE-W4CTX-010: flips the menu back inside the viewport when it would overflow', () => {
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
width: 200, height: 120, top: 0, left: 0, right: 0, bottom: 0, x: 0, y: 0, toJSON: () => ({}),
} as DOMRect)
function layoutSize(width: number, height: number) {
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(width)
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(height)
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 400 })
Object.defineProperty(window, 'innerHeight', { writable: true, configurable: true, value: 300 })
}
it('FE-W4CTX-010: flips the menu back inside the viewport when it would overflow', () => {
layoutSize(200, 120)
const { baseElement } = render(<ContextMenu menu={{ x: 380, y: 290, items: [{ label: 'Open' }] }} onClose={() => {}} />)
@@ -115,6 +118,18 @@ describe('ContextMenu', () => {
expect(menu.style.top).toBe('172px')
})
it('FE-W4CTX-010b: keeps an end-aligned menu off the left edge, and caps one taller than the screen', () => {
layoutSize(200, 500)
const { baseElement } = render(<ContextMenu menu={{ x: 40, y: 20, alignEnd: true, items: [{ label: 'Open' }] }} onClose={() => {}} />)
const menu = baseElement.querySelector('.trek-popover-enter') as HTMLElement
expect(menu.style.left).toBe('8px')
expect(menu.style.top).toBe('8px')
expect(menu.style.maxHeight).toBe('284px')
expect(menu.style.overflowY).toBe('auto')
})
it('FE-W4CTX-011: Escape, a scroll and a resize close it', () => {
const onClose = vi.fn()
render(<ContextMenu menu={{ x: 0, y: 0, items: [{ label: 'Open' }] }} onClose={onClose} />)
+18 -6
View File
@@ -97,14 +97,26 @@ export function ContextMenu({ menu, onClose }: ContextMenuProps) {
useLayoutEffect(() => {
if (!menu || !ref.current) return
const el = ref.current
const rect = el.getBoundingClientRect()
// The layout size, not getBoundingClientRect: the menu is still mid enter
// animation (scaled down) here, and the smaller box let a menu opened near an
// edge end up partly off screen.
const width = el.offsetWidth
const viewW = window.innerWidth
const viewH = window.innerHeight
// Taller than the screen (a long list on a phone): cap it and let it scroll.
if (el.offsetHeight > viewH - 16) {
el.style.maxHeight = `${viewH - 16}px`
el.style.overflowY = 'auto'
}
const height = Math.min(el.offsetHeight, viewH - 16)
let { x, y } = menu
if (menu.alignEnd) x = Math.max(8, x - rect.width)
if (x + rect.width > window.innerWidth - 8) x = window.innerWidth - rect.width - 8
if (y + rect.height > window.innerHeight - 8) y = window.innerHeight - rect.height - 8
if (menu.alignEnd) x = x - width
// Kept inside all four edges with 8px to spare.
x = Math.min(Math.max(8, x), viewW - width - 8)
y = Math.min(Math.max(8, y), viewH - height - 8)
if (x !== menu.x || y !== menu.y) {
el.style.left = `${x}px`
el.style.top = `${y}px`
el.style.left = `${Math.max(8, x)}px`
el.style.top = `${Math.max(8, y)}px`
}
}, [menu])