Skip to content

Commit 123c3cd

Browse files
committed
use DecoupledOverlay for VisualTour
1 parent 39f406c commit 123c3cd

2 files changed

Lines changed: 28 additions & 82 deletions

File tree

src/components/VisualTour/VisualTour.tsx

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React from "react";
22
import { createPortal } from "react-dom";
3-
import { Classes as BlueprintClasses } from "@blueprintjs/core";
4-
import { createPopper } from "@popperjs/core";
53

64
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
75
import {
@@ -14,6 +12,7 @@ import {
1412
CardHeader,
1513
CardOptions,
1614
CardTitle,
15+
DecoupledOverlay,
1716
IconButton,
1817
Markdown,
1918
ModalSize,
@@ -292,25 +291,6 @@ interface StepPopoverProps {
292291

293292
/** Popover that is displayed and points at the highlighted element. */
294293
const StepPopover = ({ highlightedElement, step, titleOption, actionButtons }: StepPopoverProps) => {
295-
const tooltipRef = React.useCallback(
296-
(tooltip: HTMLDivElement | null) => {
297-
if (tooltip) {
298-
createPopper(highlightedElement, tooltip, {
299-
placement: "auto",
300-
modifiers: [
301-
{
302-
name: "offset",
303-
options: {
304-
offset: [0, 15],
305-
},
306-
},
307-
],
308-
});
309-
}
310-
},
311-
[highlightedElement]
312-
);
313-
314294
const backdropRef = React.useCallback(
315295
(backdrop: HTMLDivElement | null) => {
316296
const highlightStencil = () => {
@@ -340,39 +320,39 @@ const StepPopover = ({ highlightedElement, step, titleOption, actionButtons }: S
340320
[highlightedElement]
341321
);
342322

323+
// map to only tooltip size because the `DecoupledOverlay` only supports them
324+
let overlaySize: TooltipSize = "large";
325+
switch (step.size) {
326+
case "tiny":
327+
overlaySize = "small";
328+
break;
329+
case "regular":
330+
overlaySize = "medium";
331+
break;
332+
case "xlarge":
333+
case "fullscreen":
334+
overlaySize = "large";
335+
break;
336+
}
337+
343338
return createPortal(
344339
<div className={`${eccgui}-visual-tour`}>
345340
<div className={`${eccgui}-visual-tour__focushelper`} ref={backdropRef} />
346341
<div>
347342
<div className={`${eccgui}-visual-tour__backdrop`} />
348343
</div>
349-
<div
350-
className={
351-
`${eccgui}-visual-tour__overlay` +
352-
` ${eccgui}-visual-tour__overlay--${step.size ?? "large"}` +
353-
` ${BlueprintClasses.POPOVER}`
354-
}
355-
role="tooltip"
356-
ref={tooltipRef}
357-
>
358-
<div
359-
className={`${eccgui}-visual-tour__arrow ${BlueprintClasses.POPOVER_ARROW}`}
360-
data-popper-arrow
361-
aria-hidden
362-
/>
363-
<div className={`${BlueprintClasses.POPOVER_CONTENT} ${eccgui}-visual-tour__overlay__content`}>
364-
<Card isOnlyLayout elevation={-1} whitespaceAmount="small">
365-
<CardHeader>
366-
<CardTitle>{step.title}</CardTitle>
367-
<CardOptions>{titleOption}</CardOptions>
368-
</CardHeader>
369-
<CardContent>
370-
<StepContent step={step} />
371-
</CardContent>
372-
<CardActions inverseDirection>{actionButtons}</CardActions>
373-
</Card>
374-
</div>
375-
</div>
344+
<DecoupledOverlay targetSelectorOrElement={highlightedElement} size={overlaySize} usePortal={false}>
345+
<Card isOnlyLayout elevation={-1} whitespaceAmount="small">
346+
<CardHeader>
347+
<CardTitle>{step.title}</CardTitle>
348+
<CardOptions>{titleOption}</CardOptions>
349+
</CardHeader>
350+
<CardContent>
351+
<StepContent step={step} />
352+
</CardContent>
353+
<CardActions inverseDirection>{actionButtons}</CardActions>
354+
</Card>
355+
</DecoupledOverlay>
376356
</div>,
377357
document.body
378358
);

src/components/VisualTour/visualTour.scss

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,6 @@
3131
opacity: 0;
3232
}
3333

34-
.#{$eccgui}-visual-tour__arrow {
35-
&::before {
36-
background: $card-background-color;
37-
}
38-
39-
.#{$eccgui}-visual-tour__overlay[data-popper-placement="top"] & {
40-
bottom: -0.5 * $eccgui-size-block-whitespace;
41-
}
42-
.#{$eccgui}-visual-tour__overlay[data-popper-placement="right"] & {
43-
left: -0.5 * $eccgui-size-block-whitespace;
44-
}
45-
.#{$eccgui}-visual-tour__overlay[data-popper-placement="bottom"] & {
46-
top: -0.5 * $eccgui-size-block-whitespace;
47-
}
48-
.#{$eccgui}-visual-tour__overlay[data-popper-placement="left"] & {
49-
right: -0.5 * $eccgui-size-block-whitespace;
50-
}
51-
}
52-
53-
.#{$eccgui}-visual-tour__overlay {
54-
z-index: 8002; // 2 over application header
55-
&--small {
56-
@extend .#{$eccgui}-tooltip--small;
57-
}
58-
59-
&--medium {
60-
@extend .#{$eccgui}-tooltip--medium;
61-
}
62-
63-
&--large {
64-
@extend .#{$eccgui}-tooltip--large;
65-
}
66-
}
67-
6834
.#{$eccgui}-card__content {
6935
.#{$eccgui}-visual-tour__overlay__content & {
7036
max-height: 45vh;

0 commit comments

Comments
 (0)