Skip to content

Commit

Permalink
popup interaction details
Browse files Browse the repository at this point in the history
  • Loading branch information
j8seangel committed Apr 24, 2024
1 parent 0c3e027 commit 83c8531
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 3 additions & 1 deletion apps/fishing-map/features/map/popups/MapPopups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function MapPopups() {

return (
<Fragment>
{hoverInteraction && <PopupWrapper interaction={hoverInteraction} type="hover" />}
{hoverInteraction && !clickInteraction?.features?.length && (
<PopupWrapper interaction={hoverInteraction} type="hover" />
)}
{clickInteraction && (
<PopupWrapper interaction={clickInteraction} type="click" onClose={closePopup} />
)}
Expand Down
6 changes: 5 additions & 1 deletion apps/fishing-map/features/map/popups/Popup.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
z-index: 2;
}

.contentWrapper {
filter: var(--filter-drop-shadow);
}

.arrow {
position: absolute;
width: 14px;
Expand Down Expand Up @@ -40,7 +44,7 @@
}

.hover .content {
transform: translate(var(--space-XS), var(--space-S));
min-width: max-content;
background: var(--color-primary-blue);
color: var(--color-white);
max-width: var(--sidebar-width);
Expand Down
13 changes: 4 additions & 9 deletions apps/fishing-map/features/map/popups/PopupWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cx from 'classnames'
import { groupBy } from 'lodash'
import { useSelector } from 'react-redux'
import {
offset,
autoPlacement,
autoUpdate,
useFloating,
Expand Down Expand Up @@ -105,9 +106,10 @@ function PopupWrapper({ interaction, type = 'hover', className = '', onClose }:
const apiEventStatus = useSelector(selectApiEventStatus)

const arrowRef = useRef<HTMLDivElement>(null)
const { refs, floatingStyles, placement, middlewareData /*, update, elements */ } = useFloating({
const { refs, floatingStyles, placement, middlewareData } = useFloating({
whileElementsMounted: autoUpdate,
middleware: [
offset(15),
autoPlacement({ padding: 10 }),
overflowMiddlware,
arrow({
Expand Down Expand Up @@ -136,20 +138,13 @@ function PopupWrapper({ interaction, type = 'hover', className = '', onClose }:
),
'category'
)

// useEffect(() => {
// if (elements.reference && elements.floating) {
// const cleanup = autoUpdate(elements.reference, elements.floating, update)
// return cleanup
// }

return (
<div
ref={refs.setReference}
style={{ position: 'absolute', top, left }}
className={cx(styles.popup, styles[type], className)}
>
<div ref={refs.setFloating} style={floatingStyles}>
<div className={styles.contentWrapper} ref={refs.setFloating} style={floatingStyles}>
{type === 'click' && (
<PopupArrow ref={arrowRef} placement={placement} arrow={middlewareData.arrow} />
)}
Expand Down

0 comments on commit 83c8531

Please sign in to comment.