fix(dayplan): calmer day dialogs, and the shrink question side by side

The day dialog hangs from a fixed top edge, so switching to the delete
question only moves its bottom edge, and the question opens at its top
with the focus on Cancel. Cancel, Close and the quiet add share one
outline; the dated add is drawn in the accent instead of filled with it.
Dates in the dialog, its hints and the new-day toast read the way the day
list writes them, and captions use the muted text colour for contrast. A
stay booked twice is named once in the warning. On the phone the dated
pill shows only its date, so both pills fit side by side.

When the trip dialog asks both how bookings follow a moved start and
which days the new dates remove, the two now stand side by side in a wide
dialog instead of one long column.
This commit is contained in:
Maurice
2026-09-23 22:20:59 +02:00
parent 83be759c49
commit 954758082b
35 changed files with 152 additions and 118 deletions
@@ -1,6 +1,6 @@
import { useId, useState } from 'react'
import { CalendarPlus, Plus } from 'lucide-react'
import { formatDate } from '../../utils/formatters'
import { dayDate } from '../../utils/dayLabel'
import type { DayAddControls } from '../../utils/dayAdd'
interface DayAddFooterProps {
@@ -15,10 +15,11 @@ interface DayAddFooterProps {
/** One button size for the whole foot of the reorder dialog, the delete question's included. */
export const FOOTER_BTN =
'inline-flex min-h-9 flex-shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-lg px-3 py-1.5 text-body font-medium transition-colors disabled:cursor-default disabled:opacity-40'
const SECONDARY_BTN = `${FOOTER_BTN} border border-edge text-content-secondary hover:bg-surface-hover disabled:hover:bg-transparent`
const CLOSE_BTN = `${FOOTER_BTN} ml-auto border border-edge text-content-muted hover:bg-surface-hover hover:text-content`
/** The add that matters most, tinted from the accent instead of filled with it. */
const MAIN_BTN = `${FOOTER_BTN} border border-[color:color-mix(in_srgb,var(--accent)_30%,transparent)] bg-[color:color-mix(in_srgb,var(--accent)_10%,transparent)] font-semibold text-accent-on hover:bg-[color:color-mix(in_srgb,var(--accent)_16%,transparent)] disabled:hover:bg-[color:color-mix(in_srgb,var(--accent)_10%,transparent)]`
/** Cancel, Close and the quiet add: one outline, one text colour, so none of them looks switched off beside another. */
export const SECONDARY_BTN = `${FOOTER_BTN} border border-edge text-content-secondary hover:bg-surface-hover hover:text-content disabled:hover:bg-transparent`
const CLOSE_BTN = `${SECONDARY_BTN} ml-auto`
/** The add that matters most: drawn in the accent, not filled with it, so it leads without weighing on the row. */
const MAIN_BTN = `${FOOTER_BTN} border border-accent-on bg-transparent font-semibold text-accent-on hover:bg-accent-subtle disabled:hover:bg-transparent`
/**
* The foot of the reorder dialog: close it, or add a day.
@@ -45,7 +46,7 @@ export function DayAddFooter({ dayAdd, onAddDay, onClose, t, locale }: DayAddFoo
if (!dayAdd?.nextDate) {
return (
<div className="flex flex-col gap-2.5">
{blocked && <p className="m-0 text-caption text-content-faint">{blocked}</p>}
{blocked && <p className="m-0 text-caption text-content-muted">{blocked}</p>}
<div className="flex flex-wrap items-center gap-2">
<button type="button" onClick={onAddDay} disabled={addOff} className={MAIN_BTN}>
<Plus size={15} strokeWidth={2} aria-hidden="true" />
@@ -57,7 +58,7 @@ export function DayAddFooter({ dayAdd, onAddDay, onClose, t, locale }: DayAddFoo
)
}
const date = formatDate(dayAdd.nextDate, locale) ?? dayAdd.nextDate
const date = dayDate(dayAdd.nextDate, locale) ?? dayAdd.nextDate
const hint = blocked
?? (aboutUndated ? t('dayplan.addUndatedDayHint') : dayAdd.datedBlocked ?? t('dayplan.addDatedDayHint', { date }))
const pointAtUndated = {
@@ -69,7 +70,7 @@ export function DayAddFooter({ dayAdd, onAddDay, onClose, t, locale }: DayAddFoo
return (
<div className="flex flex-col gap-2.5">
<p id={hintId} aria-live="polite" className="m-0 text-caption text-content-faint">
<p id={hintId} aria-live="polite" className="m-0 text-caption text-content-muted">
{hint}
</p>
{/* Should a language run long, the row wraps between buttons, never inside one. */}
@@ -3,7 +3,7 @@ import { GripVertical, ArrowUp, ArrowDown, Trash2, AlertTriangle } from 'lucide-
import Modal from '../shared/Modal'
import Tooltip from '../shared/Tooltip'
import DayImpactList from '../shared/DayImpactList'
import { DayAddFooter, FOOTER_BTN } from './DayAddFooter'
import { DayAddFooter, FOOTER_BTN, SECONDARY_BTN } from './DayAddFooter'
import { useNetworkMode } from '../../hooks/useNetworkMode'
import { dayLabel } from '../../utils/dayLabel'
import { deleteDayBlockedReason } from '../../utils/dayDeleteImpact'
@@ -35,7 +35,6 @@ interface ListSpot {
dayId: number
index: number
scrollTop: number
panelHeight: number
}
const ICON_BTN =
@@ -50,8 +49,10 @@ const DELETE_BTN =
* so the list reflects each move immediately.
*
* A delete only asks, and it asks right here: the dialog swaps its list for the
* question, what goes with the day and the two ways out, at the same size and in
* the same place. Cancel and Escape bring the list back where it was.
* question, what goes with the day and the two ways out, at the same width. The
* dialog hangs from a fixed top edge, so the swap only moves its bottom edge,
* and the question takes the height it needs. Cancel and Escape bring the list
* back where it was.
*/
export function DayReorderPopup({ isOpen, days, t, locale, onReorder, onAddDay, dayAdd, onDeleteDay, deleteQuestion, onClose }: DayReorderPopupProps) {
const [dragIndex, setDragIndex] = useState<number | null>(null)
@@ -77,13 +78,7 @@ export function DayReorderPopup({ isOpen, days, t, locale, onReorder, onAddDay,
}
const ask = (dayId: number, index: number) => {
const body = bodyRef.current
spot.current = {
dayId,
index,
scrollTop: body?.parentElement?.scrollTop ?? 0,
panelHeight: body?.closest<HTMLElement>('[role="presentation"]')?.offsetHeight ?? 0,
}
spot.current = { dayId, index, scrollTop: bodyRef.current?.parentElement?.scrollTop ?? 0 }
onDeleteDay?.(dayId)
}
@@ -108,43 +103,35 @@ export function DayReorderPopup({ isOpen, days, t, locale, onReorder, onAddDay,
return () => document.removeEventListener('keydown', onKey, true)
}, [asking])
// The question keeps the dialog at the height the list had, so nothing moves
// under the pointer; a longer one grows it and scrolls inside. Back at the
// list, the scroll position and the focus return to the row asked about.
// The question opens at its top with the focus on Cancel. Back at the list,
// the scroll position and the focus return to the row asked about.
const askedDayId = asking?.dayId ?? null
const lineCount = asking?.lines.length ?? 0
const shownDayId = useRef<number | null>(null)
useLayoutEffect(() => {
const body = bodyRef.current
if (!body) return
const scroller = body.parentElement
const turned = shownDayId.current !== askedDayId
// Closed with the question open: the next opening starts at the list, fresh.
if (!body) { shownDayId.current = null; spot.current = null; return }
if (shownDayId.current === askedDayId) return
shownDayId.current = askedDayId
body.style.minHeight = ''
const scroller = body.parentElement
if (askedDayId != null) {
const target = spot.current?.panelHeight ?? 0
const panel = body.closest<HTMLElement>('[role="presentation"]')
const short = target - (panel?.offsetHeight ?? target)
if (short > 0) body.style.minHeight = `${body.offsetHeight + short}px`
if (turned) {
if (scroller) scroller.scrollTop = 0
cancelRef.current?.focus()
}
if (scroller) scroller.scrollTop = 0
cancelRef.current?.focus()
return
}
const from = spot.current
if (!from || !turned) return
if (!from) return
spot.current = null
if (scroller) scroller.scrollTop = from.scrollTop
const buttons = body.querySelectorAll<HTMLButtonElement>('[data-delete-day]')
const again = body.querySelector<HTMLButtonElement>(`[data-delete-day="${from.dayId}"]`)
?? buttons[Math.min(from.index, buttons.length - 1)]
again?.focus()
}, [askedDayId, lineCount])
}, [askedDayId])
const footer = asking ? (
<div className="flex items-center justify-end gap-2">
<button ref={cancelRef} type="button" onClick={asking.onCancel} className={`${FOOTER_BTN} border border-edge text-content-secondary hover:bg-surface-hover`}>
<button ref={cancelRef} type="button" onClick={asking.onCancel} className={SECONDARY_BTN}>
{t('common.cancel')}
</button>
<button type="button" onClick={asking.onConfirm} className={`${FOOTER_BTN} bg-danger font-semibold text-white hover:opacity-90`}>
@@ -157,7 +144,7 @@ export function DayReorderPopup({ isOpen, days, t, locale, onReorder, onAddDay,
)
return (
<Modal isOpen={isOpen} onClose={close} title={t('dayplan.reorderTitle')} size="lg" footer={footer}>
<Modal isOpen={isOpen} onClose={close} title={t('dayplan.reorderTitle')} size="lg" align="top" footer={footer}>
<div ref={bodyRef}>
{asking ? (
<section aria-labelledby={titleId} aria-describedby={bodyId} className="trek-page-enter">
@@ -166,7 +153,7 @@ export function DayReorderPopup({ isOpen, days, t, locale, onReorder, onAddDay,
<AlertTriangle size={16} strokeWidth={2} aria-hidden="true" />
</span>
<div className="min-w-0 flex-1">
<h3 id={titleId} className="text-body font-semibold leading-snug text-content">{asking.title}</h3>
<h3 id={titleId} className="text-subtitle font-semibold leading-snug text-content">{asking.title}</h3>
<p id={bodyId} className="mt-0.5 text-caption text-content-muted">{t('dayplan.deleteDayBody')}</p>
</div>
</div>
@@ -174,7 +161,7 @@ export function DayReorderPopup({ isOpen, days, t, locale, onReorder, onAddDay,
</section>
) : (
<>
<p className="mb-3 text-caption text-content-faint">{t('dayplan.reorderHint')}</p>
<p className="mb-3 text-caption text-content-muted">{t('dayplan.reorderHint')}</p>
{/* The popup is a modal, so it portals out of the planner and has to opt
into the long-press drag itself (#1616). Without this a finger only
+19 -5
View File
@@ -14,11 +14,20 @@ interface TripDateReviewProps {
error?: string
}
/**
* Whether the step shows both of its parts. Then they stand side by side in a wide
* dialog, the question on the left and the removed days on the right, instead of one
* long column that has to be scrolled through before the buttons.
*/
export function dateReviewIsWide(askShift: boolean, removal: RangeCheck): boolean {
return askShift && !!removal && removal !== 'unknown'
}
/**
* The step the trip dialog puts between a change of dates and the save: how
* bookings follow a moved start, and which days the new range removes with what
* is on them. Either part can stand alone. The list's booking hint follows the
* shift mode picked above it, because the two modes leave those bookings in
* shift mode picked beside it, because the two modes leave those bookings in
* different places.
*/
export default function TripDateReview({ askShift, shiftMode, onShiftMode, removal, error }: TripDateReviewProps) {
@@ -28,13 +37,16 @@ export default function TripDateReview({ askShift, shiftMode, onShiftMode, remov
{ mode: 'shift_all', label: t('dashboard.dateShiftAll'), desc: t('dashboard.dateShiftAllDesc') },
]
const wide = dateReviewIsWide(askShift, removal)
return (
<div className="space-y-3">
{error && (
<div className="p-3 bg-danger-soft border border-danger/30 rounded-xl text-body text-danger">{error}</div>
)}
<div className={wide ? 'grid gap-5 md:grid-cols-2' : 'space-y-3'}>
{askShift && (
<>
<div className="space-y-3">
<p className="text-body text-content-secondary">{t('dashboard.dateShiftIntro')}</p>
{modes.map(({ mode, label, desc }) => (
<label key={mode}
@@ -47,7 +59,8 @@ export default function TripDateReview({ askShift, shiftMode, onShiftMode, remov
</span>
</label>
))}
</>
<p className="text-caption text-content-muted">{t('dashboard.dateShiftHint')}</p>
</div>
)}
{removal === 'unknown' && (
<div role="alert" className="flex items-start gap-3 rounded-xl border border-edge-faint bg-surface-secondary p-3">
@@ -58,7 +71,8 @@ export default function TripDateReview({ askShift, shiftMode, onShiftMode, remov
</div>
)}
{removal && removal !== 'unknown' && (
<div className={askShift ? 'border-t border-edge-faint pt-3' : ''}>
// Beside the question on a wide screen, below it on a narrow one.
<div className={wide ? 'border-t border-edge-faint pt-3 md:border-l md:border-t-0 md:pl-5 md:pt-0' : ''}>
<p className="text-body text-content-secondary">{t('dashboard.shrinkIntro')}</p>
<DayImpactList
lines={shrinkTripLines(removal, t, shiftMode)}
@@ -67,7 +81,7 @@ export default function TripDateReview({ askShift, shiftMode, onShiftMode, remov
/>
</div>
)}
{askShift && <p className="text-caption text-content-faint">{t('dashboard.dateShiftHint')}</p>}
</div>
</div>
)
}
@@ -14,7 +14,7 @@ import { getApiErrorMessage, type Trip } from '../../types'
import { MAX_TRIP_DAYS, tripSpanDays, type TripCreateRequest } from '@trek/shared'
import { NumericInput } from '../shared/NumericInput'
import { currenciesWith, SYMBOLS } from '../Budget/BudgetPanel.constants'
import TripDateReview from './TripDateReview'
import TripDateReview, { dateReviewIsWide } from './TripDateReview'
import { useTripRangeGuard, type RangeCheck } from '../../hooks/useTripRangeGuard'
import type { ShiftMode } from '../../utils/dayImpactLines'
@@ -410,9 +410,10 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
title={pendingReview
? t(pendingReview.askShift ? 'dashboard.dateShiftTitle' : 'dashboard.shrinkTitle')
: isEditing ? t('dashboard.editTrip') : t('dashboard.createTrip')}
/* The review step is a few radio buttons and a short list; it would look
lost across the width the form itself needs. */
size={pendingReview ? 'md' : '2xl'}
/* The review step is a few radio buttons and a short list; alone, either
takes the width of the day dialog, where the same list stands. With both,
they stand side by side at the form's own width. */
size={pendingReview && !dateReviewIsWide(pendingReview.askShift, pendingReview.removal) ? 'lg' : '2xl'}
footer={
<div className="flex gap-3 justify-end">
{pendingReview ? (
+8 -1
View File
@@ -24,6 +24,12 @@ interface ModalProps {
size?: string
footer?: React.ReactNode
hideCloseButton?: boolean
/**
* Where the panel stands on a wide screen. Centred by default; 'top' pins its
* upper edge, so a dialog whose content changes height grows and shrinks at
* the bottom only instead of jumping. Phones always start at the top.
*/
align?: 'center' | 'top'
}
export default function Modal({
@@ -34,6 +40,7 @@ export default function Modal({
size = 'md',
footer,
hideCloseButton = false,
align = 'center',
}: ModalProps) {
const handleEsc = useCallback((e: KeyboardEvent) => {
if (e.key === 'Escape') onClose()
@@ -63,7 +70,7 @@ export default function Modal({
// click-away, the panel only keeps that click from reaching it. Escape
// and the header's close button are the keyboard route out.
role="presentation"
className="fixed inset-0 z-[10000] flex items-start sm:items-center justify-center px-4 trek-modal-backdrop trek-backdrop-enter bg-[rgba(15,23,42,0.5)]"
className={`fixed inset-0 z-[10000] flex items-start ${align === 'top' ? '' : 'sm:items-center'} justify-center px-4 trek-modal-backdrop trek-backdrop-enter bg-[rgba(15,23,42,0.5)]`}
style={{ paddingTop: 70, paddingBottom: 'calc(20px + var(--bottom-nav-h))', overflow: 'hidden' }}
onMouseDown={e => { mouseDownTarget.current = e.target }}
onClick={e => {