generated from taylorbryant/gatsby-starter-tailwind
-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66987e8
commit 41b5154
Showing
3 changed files
with
103 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as Popover from '@radix-ui/react-popover' | ||
import { useCallback } from 'react' | ||
import { MapInstance } from 'react-map-gl' | ||
|
||
interface CoordinatePickerPopupProps { | ||
info: { | ||
coordinates: { lng: number, lat: number } | ||
mapInstance: MapInstance | null | ||
} | ||
onConfirm: () => void | ||
onClose: () => void | ||
open: boolean | ||
} | ||
|
||
export const CoordinatePickerPopup: React.FC<CoordinatePickerPopupProps> = ({ info, onConfirm, onClose, open }) => { | ||
const { coordinates, mapInstance } = info | ||
const { lng: longitude, lat: latitude } = coordinates | ||
const screenXY = mapInstance?.project(coordinates) | ||
|
||
const handleConfirmClick = useCallback((e: React.MouseEvent) => { | ||
e.stopPropagation() | ||
onConfirm() | ||
}, [onConfirm]) | ||
|
||
if (screenXY == null) return null | ||
|
||
return ( | ||
<Popover.Root open={open}> | ||
<Popover.Anchor style={{ position: 'absolute', left: screenXY?.x, top: screenXY?.y + -10 }} /> | ||
<Popover.Content | ||
align='center' | ||
side='top' | ||
sideOffset={8} | ||
collisionPadding={24} | ||
className='z-[50] focus:outline-none cursor-pointer p-4 bg-white rounded shadow-md' | ||
onClick={(e) => e.stopPropagation()} | ||
> | ||
<div className='text-center'> | ||
<p className='text-sm'>Coordinates: {latitude.toFixed(5)}, {longitude.toFixed(5)}</p> | ||
<div className='flex justify-center mt-2'> | ||
<button | ||
className='btn btn-primary mr-2' | ||
onClick={handleConfirmClick} | ||
> | ||
Confirm | ||
</button> | ||
<button | ||
className='btn btn-secondary' | ||
onClick={onClose} | ||
> | ||
Cancel | ||
</button> | ||
</div> | ||
</div> | ||
</Popover.Content> | ||
</Popover.Root> | ||
) | ||
} |