mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 11:06:06 +00:00
5536d29cbf
A row now shows its box, its name and only what is set: the amount from two up, the pieces packed while packing, and who brings it. A click on the name opens a small window at the row with the list, amount, pieces packed, weight, bag, who brings it and who sees it, each as one pill, plus copy and delete, instead of fields, a bin and menus in menus on every row. Above the lists the Lists bar keeps Add list and gathers templates, import, export, the order, hiding packed items, the bags on a narrow screen and the clean-up in one menu; the progress moves next to the Shared/My list switch. The bag overview stays. The phone follows the same shape: one "..." sheet for the list's actions, a sheet per list for its own, a slim row and an item sheet that saves as you go. Who may change what about an item lives in one module both views read.
104 lines
4.2 KiB
TypeScript
104 lines
4.2 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 { PopoverItem } from './PackingPopover'
|
|
import { usePackingExport, type PackingView } from './usePackingExport'
|
|
|
|
interface PackingExportMenuProps {
|
|
tripId: number
|
|
view: PackingView
|
|
style?: React.CSSProperties
|
|
className?: string
|
|
/** 'menu' draws the three ways out as lines of the Lists menu; onChosen closes that menu. */
|
|
variant?: 'button' | 'menu'
|
|
onChosen?: () => void
|
|
}
|
|
|
|
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, variant = 'button', onChosen }: 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)
|
|
onChosen?.()
|
|
void action()
|
|
}
|
|
|
|
if (variant === 'menu') return (
|
|
<>
|
|
<PopoverItem icon={<Printer size={13} />} label={t('packing.exportPrint')} onClick={choose(packingExport.openPrint)} />
|
|
<PopoverItem icon={<FileText size={13} />} label={t('packing.exportMarkdown')} onClick={choose(packingExport.exportMarkdown)} />
|
|
<PopoverItem icon={<FileSpreadsheet size={13} />} label={t('packing.exportCsv')} onClick={choose(packingExport.exportCsv)} />
|
|
<PackingPrintPreview html={packingExport.printHtml} title={packingExport.printTitle} onClose={packingExport.closePrint} />
|
|
</>
|
|
)
|
|
|
|
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>
|
|
)
|
|
}
|