fix(transit): keep stop names readable beside long route names

Line badges could take the width of a transit row and squeeze its stops. Bound badge width across the itinerary views, wrap full labels in details, and keep compact summaries within their container.

Closes #3287
This commit is contained in:
Maurice
2026-12-01 11:10:53 +01:00
parent 82b2a530f3
commit 67b65a7647
8 changed files with 85 additions and 46 deletions
@@ -15,7 +15,7 @@ import { useTranslation } from '../../i18n'
import { useSettingsStore } from '../../store/settingsStore'
import { useTripStore } from '../../store/tripStore'
import { splitReservationDateTime, formatTime } from '../../utils/formatters'
import { TransitTitle, TransitMetaBadges, TransitWalkDivider, fmtTransitDuration } from './transitDisplay'
import { TransitTitle, TransitLineBadge, TransitMetaBadges, TransitWalkDivider, fmtTransitDuration } from './transitDisplay'
import type { Reservation } from '../../types'
import { useIsPhone } from '../../mobile/useIsPhone'
@@ -423,9 +423,7 @@ export default function TransitJourneyModal({ reservation, onClose, onSave, onDe
</div>
<div style={{ padding: '6px 0 8px', minWidth: 0 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 }}>
<span style={{ display: 'inline-flex', alignItems: 'center', background: leg.line_color || 'var(--bg-hover)', color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--text-primary)', borderRadius: 6, padding: '1px 7px', fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 700, flexShrink: 0 }}>
{leg.line || leg.mode}
</span>
<TransitLineBadge label={leg.line || leg.mode} besideText={Boolean(leg.headsign)} wrap style={{ background: leg.line_color || 'var(--bg-hover)', color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--text-primary)', borderRadius: 6, padding: '1px 7px', fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 700, flexShrink: 0 }} />
{leg.headsign && (
<span className="text-content-faint" style={{ display: 'inline-flex', alignItems: 'center', gap: 3, fontSize: 'calc(11px * var(--fs-scale-caption, 1))', minWidth: 0 }}>
<MoveRight size={10} style={{ flexShrink: 0 }} />
@@ -450,15 +448,13 @@ export default function TransitJourneyModal({ reservation, onClose, onSave, onDe
<div className="text-content-muted" style={{ width: 44, flexShrink: 0, textAlign: 'end', fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600, paddingTop: 1 }}>
{leg.from?.time || ''}
</div>
<span style={{ display: 'inline-flex', alignItems: 'center', background: leg.line_color || 'var(--bg-hover)', color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--text-primary)', borderRadius: 6, padding: '2px 8px', fontSize: 'calc(11.5px * var(--fs-scale-caption, 1))', fontWeight: 700, flexShrink: 0 }}>
{leg.line || leg.mode}
</span>
<TransitLineBadge label={leg.line || leg.mode} besideText style={{ background: leg.line_color || 'var(--bg-hover)', color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--text-primary)', borderRadius: 6, padding: '2px 8px', fontSize: 'calc(11.5px * var(--fs-scale-caption, 1))', fontWeight: 700, flexShrink: 0 }} />
<div style={{ flex: 1, minWidth: 0 }}>
<div className="text-content" style={{ fontSize: 'calc(13.5px * var(--fs-scale-body, 1))', fontWeight: 600, display: 'flex', alignItems: 'center', gap: 5, flexWrap: 'wrap' }}>
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{leg.from?.name}</span>
<span dir="auto" style={{ minWidth: 0, overflowWrap: 'anywhere' }}>{leg.from?.name}</span>
{leg.from?.track && <span className="text-content-faint" style={{ fontWeight: 500 }}>({t('transit.platform', { track: leg.from.track })})</span>}
<ArrowRight size={12} className="text-content-faint" style={{ flexShrink: 0 }} />
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{leg.to?.name}</span>
<span dir="auto" style={{ minWidth: 0, overflowWrap: 'anywhere' }}>{leg.to?.name}</span>
</div>
<div style={{ marginTop: 3 }}>
<TransitMetaBadges items={[
@@ -3,7 +3,7 @@ import { createPortal } from 'react-dom'
import tzlookup from 'tz-lookup'
import { ArrowLeftRight, ArrowRight, Bus, CableCar, ChevronDown, ChevronUp, Clock, Footprints, MapPin, Sailboat, Search, TramFront, TrainFront, TrainFrontTunnel } from 'lucide-react'
import CustomTimePicker from '../shared/CustomTimePicker'
import { TransitMetaBadges } from './transitDisplay'
import { TransitLineBadge, TransitMetaBadges } from './transitDisplay'
import { transitApi } from '../../api/client'
import { useSettingsStore } from '../../store/settingsStore'
import { useToast } from '../shared/Toast'
@@ -326,15 +326,17 @@ function StopPicker({ label, value, onPick, quickPicks, near, placeholder }: {
// ── itinerary card ───────────────────────────────────────────────────────────
function LineBadge({ leg }: { leg: TransitLeg }) {
function LineBadge({ leg, wrap = false }: { leg: TransitLeg; wrap?: boolean }) {
const bg = leg.lineColor || 'var(--bg-tertiary)'
const fg = leg.lineColor ? (leg.lineTextColor || '#fff') : 'var(--text-primary)'
const Icon = legIcon(leg.mode)
return (
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, background: bg, color: fg, borderRadius: 6, padding: '2px 7px', fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 700, whiteSpace: 'nowrap' }}>
<Icon size={11} strokeWidth={2.2} />
{leg.line || leg.mode}
</span>
<TransitLineBadge
label={leg.line || leg.mode}
wrap={wrap}
icon={<Icon size={11} strokeWidth={2.2} className="shrink-0" />}
style={{ gap: 4, background: bg, color: fg, borderRadius: 6, padding: '2px 7px', fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 700 }}
/>
)
}
@@ -425,7 +427,7 @@ function ItineraryCard({ it, tzFrom, tzTo, is12h, expanded, onToggle, onAdd, add
]} />
) : (
<>
<LineBadge leg={leg} />
<LineBadge leg={leg} wrap />
<TransitMetaBadges size="sm" items={[
{ icon: ArrowRight, text: leg.headsign || '' },
{ text: fmtDuration(leg.duration, t) },
@@ -71,14 +71,14 @@ describe('TransitLegs', () => {
it('FE-PLANNER-BKTRANSIT-007: a line without its own colour and a leg without times or name', () => {
render(<TransitLegs legs={[{ mode: 'BUS', from: { name: 'A' }, to: { name: 'B' } }, { mode: 'WALK' }]} compact />);
expect(screen.getByText('BUS')).toHaveStyle({ background: 'var(--bg-tertiary)' });
expect(screen.getByText('BUS').parentElement).toHaveStyle({ background: 'var(--bg-tertiary)' });
expect(screen.getByText('Walk to')).toBeInTheDocument();
expect(screen.queryByText(/min$/)).toBeNull();
});
it('FE-PLANNER-BKTRANSIT-008: a coloured line without a text colour is written in white', () => {
render(<TransitLegs legs={[{ mode: 'TRAM', line: 'M10', line_color: '#16a34a', from: { name: 'A', time: '09:00' }, to: { name: 'B' } }]} />);
expect(screen.getByText('M10')).toHaveStyle({ color: '#fff' });
expect(screen.getByText('M10').parentElement).toHaveStyle({ color: '#fff' });
expect(screen.getByText('09:00')).toBeInTheDocument();
});
});
@@ -1,6 +1,6 @@
import { ArrowRight, Clock, Footprints, MoveRight } from 'lucide-react'
import { useTranslation } from '../../../i18n'
import { TransitMetaBadges, type TransitLegDisplay } from '../transitDisplay'
import { TransitLineBadge, TransitMetaBadges, type TransitLegDisplay } from '../transitDisplay'
import { BOX, fs } from './bookingParts'
export interface TransitSummary {
@@ -41,11 +41,11 @@ export function TransitLegs({ legs, compact = false }: { legs: TransitLegDisplay
return (
<div key={i} className="flex items-start gap-2.5">
{walk ? <Footprints size={compact ? 13 : 14} strokeWidth={2} className="mt-0.5 w-[26px] flex-none text-content-faint" /> : (
<span className="min-w-[26px] flex-none rounded-[5px] px-1.5 py-px text-center font-bold" style={{
<TransitLineBadge label={leg.line || leg.mode} besideText className="min-w-[26px] flex-none justify-center rounded-[5px] px-1.5 py-px text-center font-bold" style={{
...fs(compact ? 10.5 : 11),
background: leg.line_color || 'var(--bg-tertiary)',
color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--text-primary)', // theme-lint-disable: a transit line's own colours
}}>{leg.line || leg.mode}</span>
}} />
)}
<div className={`flex min-w-0 flex-1 flex-col ${compact ? 'gap-1' : 'gap-1.5'}`}>
{/* Detail views show a stop name whole: the names wrap and the
@@ -1,8 +1,8 @@
// FE-PLANNER-TRANSITDISPLAY-001 to FE-PLANNER-TRANSITDISPLAY-003
// FE-PLANNER-TRANSITDISPLAY-001 to FE-PLANNER-TRANSITDISPLAY-005
import { describe, expect, it } from 'vitest';
import { render, screen } from '../../../tests/helpers/render';
import type { TransitLegDisplay } from './transitDisplay';
import { TransitItineraryInline, TransitWalkDivider } from './transitDisplay';
import { TransitItineraryInline, TransitLegChips, TransitWalkDivider } from './transitDisplay';
const t = (key: string, params?: Record<string, string | number>) =>
params ? `${key}:${Object.values(params).join(',')}` : key;
@@ -22,6 +22,21 @@ function clipsToOneLine(el: HTMLElement): boolean {
}
describe('TransitItineraryInline (#3139)', () => {
it('FE-PLANNER-TRANSITDISPLAY-004: a long line name leaves room for both stops', () => {
const line = 'Skybus - Melbourne Airport - Melbourne City';
const from = 'Skybus Coach Terminal/Spencer St';
const to = 'Melbourne (Tullamarine) Airport';
render(<TransitItineraryInline legs={[{ ...ride, line, from: { name: from }, to: { name: to } }]} t={t} />);
const label = screen.getByText(line);
expect(label.parentElement?.style.maxInlineSize).toBe('40%');
expect(label).toHaveClass('[overflow-wrap:anywhere]');
expect(label).not.toHaveClass('truncate');
expect(label).toHaveAttribute('title', line);
expect(screen.getByText(from)).toBeInTheDocument();
expect(screen.getByText(to)).toBeInTheDocument();
});
it('FE-PLANNER-TRANSITDISPLAY-001: a ride shows both stop names in full', () => {
render(<TransitItineraryInline legs={[ride]} t={t} />);
for (const name of ['Basingstoke', 'Reading']) {
@@ -45,3 +60,15 @@ describe('TransitWalkDivider (#3139)', () => {
expect(clipsToOneLine(text)).toBe(false);
});
});
describe('TransitLegChips', () => {
it('FE-PLANNER-TRANSITDISPLAY-005: a long badge fits within the chip row', () => {
const line = 'Skybus Melbourne Airport Express';
const { container } = render(<TransitLegChips legs={[{ ...ride, line }]} t={t} />);
expect(container.firstElementChild).toHaveStyle({ minInlineSize: '0px', maxInlineSize: '100%' });
const label = screen.getByText(line);
expect(label).toHaveClass('truncate');
expect(label).toHaveAttribute('title', line);
});
});
@@ -22,6 +22,23 @@ export interface TransitLegDisplay {
to?: { name?: string; time?: string | null; track?: string | null }
}
/** Limit the line badge when it shares a row with stop or headsign text. */
export function TransitLineBadge({ label, besideText = false, wrap = besideText, icon, className = '', style }: {
label?: string
besideText?: boolean
wrap?: boolean
icon?: React.ReactNode
className?: string
style?: React.CSSProperties
}) {
return (
<span className={`inline-flex items-center overflow-hidden ${className}`} style={{ ...style, maxInlineSize: besideText ? '40%' : '100%' }}>
{icon}
<span className={wrap ? 'min-w-0 [overflow-wrap:anywhere]' : 'min-w-0 truncate'} dir="auto" title={label}>{label}</span>
</span>
)
}
/**
* A walk leg as a one-line centred divider — dashed rules left and right,
@@ -77,14 +94,12 @@ export function TransitItineraryInline({ legs, t }: {
<span>{leg.from?.time || ''}</span>
{leg.to?.time && <span className="text-content-faint">{leg.to.time}</span>}
</span>
<span style={{
display: 'inline-flex', alignItems: 'center', borderRadius: 4, padding: '0 5px',
<TransitLineBadge label={leg.line || leg.mode} besideText style={{
borderRadius: 4, padding: '0 5px',
fontSize: 'calc(9.5px * var(--fs-scale-caption, 1))', fontWeight: 700, lineHeight: '15px', flexShrink: 0,
background: leg.line_color || 'var(--bg-tertiary)',
color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--text-primary)',
}}>
{leg.line || leg.mode}
</span>
}} />
<div style={{ flex: 1, minWidth: 0 }}>
{/* The folded-out itinerary is where a journey is read in full: stop names wrap (#3139). */}
<div className="text-content" style={{ fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 500, display: 'flex', flexWrap: 'wrap', alignItems: 'center', columnGap: 4, minWidth: 0 }}>
@@ -185,7 +200,7 @@ export function TransitLegChips({ legs, transfers, size = 'sm', t }: {
const walkIcon = size === 'sm' ? 10 : 12
const shown = legs.filter(l => l.mode !== 'WALK' || (l.duration || 0) >= 60)
return (
<span style={{ display: 'inline-flex', alignItems: 'center', gap: size === 'sm' ? 4 : 5, flexWrap: 'wrap' }}>
<span style={{ display: 'inline-flex', alignItems: 'center', gap: size === 'sm' ? 4 : 5, flexWrap: 'wrap', minInlineSize: 0, maxInlineSize: '100%' }}>
{shown.map((leg, i) => (
<React.Fragment key={i}>
{i > 0 && <span className="text-content-faint" style={{ fontSize: size === 'sm' ? 9 : 10 }}>›</span>}
@@ -195,15 +210,13 @@ export function TransitLegChips({ legs, transfers, size = 'sm', t }: {
{Math.round((leg.duration || 0) / 60)}
</span>
) : (
<span style={{
display: 'inline-flex', alignItems: 'center', borderRadius: size === 'sm' ? 4 : 5,
<TransitLineBadge label={leg.line || leg.mode} style={{
borderRadius: size === 'sm' ? 4 : 5,
padding: size === 'sm' ? '0 5px' : '1px 7px', lineHeight: size === 'sm' ? '15px' : undefined,
fontSize: badgeFont, fontWeight: 700,
background: leg.line_color || 'var(--bg-tertiary)',
color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--text-primary)',
}}>
{leg.line || leg.mode}
</span>
}} />
)}
</React.Fragment>
))}
@@ -13,7 +13,7 @@ import { formatTime, splitReservationDateTime } from '../../../../utils/formatte
import { transportSubtitle, type TransitMeta, type TransportEntry } from './planTimelineModel'
import { splitNoteTime } from '../lib/dayNotes'
import type { DragRowProps } from './useMPlanDragReorder'
import type { TransitLegDisplay } from '../../../../components/Planner/transitDisplay'
import { TransitLineBadge, type TransitLegDisplay } from '../../../../components/Planner/transitDisplay'
import type { Assignment, DayNote, Place, Reservation, RouteSegment, TranslationFn } from '../../../../types'
import { formatScheduleMinutes } from '../../../../components/Plugins/PluginDaySchedule'
import type { PluginDayScheduleItem } from '../../../../api/client'
@@ -308,17 +308,17 @@ export function TransportRow({ res, dayId, chrome, reorder, drag, onOpen }: {
// ── b2) Auto-transit row with collapsible legs ───────────────────────────────
function LineBadge({ leg, className = '' }: { leg: TransitLegDisplay; className?: string }) {
function LineBadge({ leg, besideText = false, className = '' }: { leg: TransitLegDisplay; besideText?: boolean; className?: string }) {
return (
<span
<TransitLineBadge
label={leg.line || leg.mode}
besideText={besideText}
className={`rounded-[6px] px-[7px] py-px text-[0.59375rem] font-extrabold ${className}`}
style={{
background: leg.line_color || 'var(--m-faint)',
color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--m-actfg)',
}}
>
{leg.line || leg.mode}
</span>
/>
)
}
@@ -329,7 +329,7 @@ function TransitStrip({ legs }: { legs: TransitLegDisplay[] }) {
return (
<div className="mt-1.5 flex flex-wrap items-center gap-1 text-m-faint">
{shown.map((leg, i) => (
<span key={i} className="inline-flex items-center gap-[2px]">
<span key={i} className="inline-flex max-w-full items-center gap-[2px]">
{i > 0 && <span className="text-[0.5rem]">›</span>}
{leg.mode === 'WALK' ? (
<span className="inline-flex items-center gap-[2px] font-geist text-[0.625rem] font-bold">
@@ -387,7 +387,7 @@ function TransitLegRows({ legs, t }: { legs: TransitLegDisplay[]; t: Translation
) : (
<div>
<div className="flex items-start gap-1.5">
<LineBadge leg={leg} className="mt-px flex-none" />
<LineBadge leg={leg} besideText className="mt-px flex-none" />
<span dir="auto" className="min-w-0 break-words text-[0.78125rem] font-bold [overflow-wrap:anywhere]">
{flowText([leg.from?.name, leg.to?.name].filter((n): n is string => !!n))}
</span>
@@ -11,6 +11,7 @@ import { getFlightLegs, getTrainLegs, seatLabel, seatsOfLegs, usesStationRoute,
import { runsOnDay } from '../../../../utils/reservationRoutes'
import { filesFor } from '../../../../utils/reservationFiles'
import { bookingDayLabel, segmentCodeLabel } from '../../../../components/Planner/transportDetailModel'
import { TransitLineBadge } from '../../../../components/Planner/transitDisplay'
import type { Reservation } from '../../../../types'
import { useSearchParams } from 'react-router'
import { isTransportReservationType } from '@trek/shared'
@@ -311,15 +312,15 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
{isWalk ? (
<Footprints size={12} strokeWidth={2} className="mt-[2px] flex-none text-m-faint" />
) : (
<span
<TransitLineBadge
label={leg.line || leg.mode}
besideText
className="flex-none rounded-[5px] px-[6px] py-px text-[0.625rem] font-bold"
style={{
background: leg.line_color || 'var(--m-ic)',
color: leg.line_color ? (leg.line_text_color || '#fff') : 'var(--m-ink)',
}}
>
{leg.line || leg.mode}
</span>
/>
)}
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-1 text-[0.71875rem] font-medium">