infoalloggi-monorepo/apps/infoalloggi/src/components/MapDialog.tsx

66 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-08-04 17:45:44 +02:00
"use client";
2025-08-28 18:27:07 +02:00
import { MapIcon } from "lucide-react";
2025-08-04 17:45:44 +02:00
import dynamic from "next/dynamic";
2025-08-28 18:27:07 +02:00
import { useState } from "react";
2025-08-04 17:45:44 +02:00
import { Button } from "~/components/ui/button";
import {
2025-08-28 18:27:07 +02:00
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
2025-08-04 17:45:44 +02:00
} from "~/components/ui/dialog";
2025-08-28 18:27:07 +02:00
import { useTranslation } from "~/providers/I18nProvider";
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
const MapComp = dynamic(() => import("~/components/map/Map"), {
ssr: false,
2025-08-04 17:45:44 +02:00
});
export const MappaDialogFullscreen = ({
2025-08-28 18:27:07 +02:00
lat,
long,
2025-08-04 17:45:44 +02:00
}: {
2025-08-28 18:27:07 +02:00
lat: string | null;
long: string | null;
2025-08-04 17:45:44 +02:00
}) => {
2025-08-28 18:27:07 +02:00
const { t } = useTranslation();
const [open, setOpen] = useState(false);
return (
2025-08-29 16:18:32 +02:00
<Dialog onOpenChange={setOpen} open={open}>
2025-08-28 18:27:07 +02:00
<DialogTrigger asChild>
<Button className="w-auto grow" disabled={!lat || !long}>
<MapIcon className="size-5" /> {t.mappa}
</Button>
</DialogTrigger>
<DialogContent className="[&_[data-slot=dialog-close]>svg]:!size-6 h-full w-screen max-w-[100vw] p-0 sm:max-h-[60vh] sm:max-w-2xl [&_[data-slot=dialog-close]]:cursor-pointer [&_[data-slot=dialog-close]]:rounded-md [&_[data-slot=dialog-close]]:bg-white [&_[data-slot=dialog-close]]:opacity-100">
2025-08-28 18:27:07 +02:00
<DialogHeader className="hidden h-0">
<DialogTitle className="sr-only">{t.mappa}</DialogTitle>
<DialogDescription className="sr-only">{t.mappa}</DialogDescription>
</DialogHeader>
<div className="size-full">
{lat && long && (
<>
<MapComp
2025-08-29 16:18:32 +02:00
height="100%"
markerType="home"
2025-08-28 18:27:07 +02:00
posix={{
2025-08-29 16:18:32 +02:00
popupTxt:
"Posizione esatta fornita dopo la richiesta di contatto",
2025-08-28 18:27:07 +02:00
pos: {
lat: Number.parseFloat(lat),
lng: Number.parseFloat(long),
},
}}
scrollWheelZoom
width="100%"
zoom={14}
/>
</>
)}
</div>
</DialogContent>
</Dialog>
);
2025-08-04 17:45:44 +02:00
};