Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions modules/widgets/src/lib/components/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// Copyright (c) vis.gl contributors
import type {JSX, ComponentChildren} from 'preact';
import {useRef, useEffect, useMemo} from 'preact/hooks';
import {createPortal} from 'preact/compat';
import {
computePosition,
flip,
shift,
offset,
arrow,
autoUpdate,
type Placement,
type ComputePositionConfig
} from '@floating-ui/dom';
Expand Down Expand Up @@ -53,8 +53,9 @@ export const Popover = ({
const anchorRef = useRef<HTMLDivElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
const arrowRef = useRef<HTMLDivElement>(null);
const updaterRef = useRef<() => void>();

const updatePosition = () => {
updaterRef.current = () => {
if (!anchorRef.current || !contentRef.current) return;

const arrowWidth = Array.isArray(arrowSize) ? arrowSize[0] : arrowSize || 0;
Expand Down Expand Up @@ -87,36 +88,38 @@ export const Popover = ({
};

useMemo(() => {
updatePosition();
}, [x, y, placement, arrowSize, pixelOffset, children]);
updaterRef.current?.();
}, [placement, arrowSize, pixelOffset]);

useEffect(() => {
// initial mount
updatePosition();
if (contentRef.current) {
contentRef.current.style.visibility = 'visible';
}
const cleanup = autoUpdate(anchorRef.current!, contentRef.current!, () =>
updaterRef.current?.()
);
return () => {
cleanup();
};
}, []);

return (
<div style={{position: 'absolute', left: x, top: y}} ref={anchorRef}>
{createPortal(
<div
className="deck-widget deck-widget-popover"
style={{position: 'fixed', visibility: 'hidden', pointerEvents: 'none'}}
ref={contentRef}
>
{Boolean(arrowSize) && (
<div
className="deck-widget-popover-arrow"
style={{position: 'absolute'}}
ref={arrowRef}
/>
)}
{children}
</div>,
document.body
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, body wouldn't have these variables defined unless a stylesheet put them on :root. Everything can be inherited if they stay in the deck stack.

)}
<div
className="deck-widget deck-widget-popover"
style={{position: 'fixed', visibility: 'hidden', pointerEvents: 'none'}}
ref={contentRef}
>
{Boolean(arrowSize) && (
<div
className="deck-widget-popover-arrow"
style={{position: 'absolute'}}
ref={arrowRef}
/>
)}
{children}
</div>
</div>
);
};
Expand Down
15 changes: 11 additions & 4 deletions modules/widgets/src/popup-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,17 @@ export class PopupWidget extends Widget<PopupWidgetProps> {
className={`deck-widget-popup-content ${this.props.className}`}
style={style as JSX.CSSProperties}
>
<IconButton
className="deck-widget-popup-close-button"
onClick={() => this._setIsOpen(false)}
/>
{this.props.closeButton && (
<div
className="deck-widget-popup-controls"
style={{width: '100%', display: 'flex', justifyContent: 'end'}}
>
<IconButton
className="deck-widget-popup-close-button"
onClick={() => this._setIsOpen(false)}
/>
</div>
)}
<UserContent {...(typeof content === 'string' ? {text: content} : content)} />
</div>
</Popover>
Expand Down
8 changes: 4 additions & 4 deletions modules/widgets/src/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,14 @@
.deck-widget-popup-content {
border-radius: var(--button-corner-radius, 8px);
background: var(--menu-background, #fff);
color: var(--menu-text, rgb(24, 24, 26));
padding: 10px;
}
.deck-widget-popup-content > .deck-widget-button {
.deck-widget-popup-content .deck-widget-popup-controls {
--button-size: 20px;
}
.deck-widget-popup-content .deck-widget-popup-controls .deck-widget-button {
box-shadow: none;
width: 100%;
display: flex;
justify-content: end;
}
.deck-widget-popup-content button.deck-widget-popup-close-button .deck-widget-icon {
mask-image: var(
Expand Down
3 changes: 2 additions & 1 deletion test/apps/widgets-9.2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<meta charset="utf-8">
<title>deck.gl Example</title>
<style>
#app {position: fixed; top: 15vh; right: 0; width: 50vw; height: 70vh; overflow: hidden;}
body {height: 300vh; overflow-y: auto; }
#app {position: absolute; top: 15vh; right: 0; width: 50vw; height: 70vh; overflow: hidden;}
</style>
</head>
<body>
Expand Down
Loading