Files
TREK/client/src/components/Packing/PackingExportMenu.tsx
T
Maurice ba70ad28b8 fix(client): spacing and alignment follow the reading direction
Arabic runs the app right to left, but margins, paddings, insets, text
alignment, borders and corner radii were written for the left side, so
icons sat against the wrong edge of their labels, indents and badges
pointed the wrong way and amount columns aligned left. They now use the
logical forms (ms-, ps-, start-, text-start, marginInlineStart,
insetInlineEnd and their CSS equivalents), which are the very same sides
in a left to right language. Geometry stays physical on purpose: maps,
positions measured from the pointer or a bounding box, time axes,
sliders, transforms and print output.

Amounts drawn as several spans keep their order in a right to left row,
the time picker keeps hours before minutes, and two switches whose thumb
slid out of its track in Arabic now move the right way.

lint:rtl counts what is still physical per file against a baseline that
may only shrink (1512 uses in 370 files before, 319 in 113 now), and CI
runs it, so new code reaches for the logical forms.
2026-10-07 22:33:58 +00:00

90 lines
3.4 KiB
TypeScript

import React, { useEffect, useRef, useState } from 'react'
import type { LucideIcon } from 'lucide-react'
import { FileSpreadsheet, FileText, Printer, Upload } from 'lucide-react'
import { useTranslation } from '../../i18n'
import PackingPrintPreview from './PackingPrintPreview'
import { usePackingExport, type PackingView } from './usePackingExport'
interface PackingExportMenuProps {
tripId: number
view: PackingView
style: React.CSSProperties
className?: string
}
function MenuItem({ icon: Icon, label, onClick }: { icon: LucideIcon; label: string; onClick: () => void }) {
return (
<button
type="button"
role="menuitem"
onClick={onClick}
className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-start text-caption font-medium text-content hover:bg-surface-tertiary"
>
<Icon size={13} className="text-content-faint" />
{label}
</button>
)
}
/**
* The list's way out, beside Import in the Lists header (#875, #1420): print or save
* as PDF, a Markdown checklist, or CSV in the import's own format. Covers the view on
* screen and renders nothing while that view is empty.
*/
export default function PackingExportMenu({ tripId, view, style, className }: PackingExportMenuProps): React.ReactElement | null {
const { t } = useTranslation()
const packingExport = usePackingExport(tripId, view)
const [open, setOpen] = useState(false)
const menuRef = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!open) return
const onPointer = (e: MouseEvent) => {
if (menuRef.current && !menuRef.current.contains(e.target as Node)) setOpen(false)
}
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') setOpen(false) }
document.addEventListener('mousedown', onPointer)
document.addEventListener('keydown', onKey)
return () => {
document.removeEventListener('mousedown', onPointer)
document.removeEventListener('keydown', onKey)
}
}, [open])
if (!packingExport.hasItems && !packingExport.printHtml) return null
const choose = (action: () => void | Promise<void>) => () => {
setOpen(false)
void action()
}
return (
// A flex box, so the button stretches to the row height like its neighbours in the header.
<div ref={menuRef} className="relative flex">
<button
type="button"
onClick={() => setOpen(v => !v)}
aria-haspopup="menu"
aria-expanded={open}
aria-label={t('packing.export')}
title={t('packing.export')}
className={className ?? 'hover:opacity-[0.88]'}
style={style}
>
<Upload size={14} strokeWidth={2.5} />
</button>
{open && (
<div
role="menu"
className="trek-menu-enter absolute end-0 top-full z-50 mt-1.5 min-w-[220px] origin-top-right rounded-[10px] border border-edge bg-surface-card p-1 shadow-dropdown"
>
<MenuItem icon={Printer} label={t('packing.exportPrint')} onClick={choose(packingExport.openPrint)} />
<MenuItem icon={FileText} label={t('packing.exportMarkdown')} onClick={choose(packingExport.exportMarkdown)} />
<MenuItem icon={FileSpreadsheet} label={t('packing.exportCsv')} onClick={choose(packingExport.exportCsv)} />
</div>
)}
<PackingPrintPreview html={packingExport.printHtml} title={packingExport.printTitle} onClose={packingExport.closePrint} />
</div>
)
}