Skip to content

Commit 47489ac

Browse files
Remove need of container element for tour
1 parent 9109f5f commit 47489ac

3 files changed

Lines changed: 6 additions & 27 deletions

File tree

src/components/VisualTour/VisualTour.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import { Card, CardActions, CardContent, CardHeader, CardTitle } from "../Card";
77
import { SimpleDialog } from "../Dialog";
88

99
export interface VisualTourProps {
10-
/** The CSS query of the container element that contains the feature that will be given a tour of.
11-
* If element highlighting is enabled, this will grey out every other element in the container element.
12-
* Default: body*/
13-
containerElementQuery?: string;
1410
/** The steps of the tour. */
1511
steps: VisualTourStep[];
1612
/** Called when the tour is cancelled or closed at then end. This should usually remove the component from the outside. */
@@ -36,12 +32,10 @@ export interface VisualTourStep {
3632
/** This should be used for defining steps in a separate object/file. Use with 'satisfies' after the object definition. */
3733
export type VisualTourStepDefinitions = Record<string, Partial<VisualTourStep>>;
3834

39-
const containerHighlightClass = `${eccgui}-visual-tour__container`;
4035
const highlightElementClass = `${eccgui}-visual-tour__highlighted-element`;
4136

4237
/** A visual tour multi-step tour of the current view. */
4338
export const VisualTour = ({
44-
containerElementQuery = "body",
4539
steps,
4640
onClose,
4741
closeLabel = "Close",
@@ -62,16 +56,9 @@ export const VisualTour = ({
6256
const hasNextStep = currentStepIndex + 1 < steps.length;
6357
const hasPreviousStep = currentStepIndex > 0;
6458
// Configure optional highlighting
65-
const element = document.querySelector(containerElementQuery);
66-
let elementToHighlight: Element | null = null;
67-
if (element) {
68-
if (step.highlightElementQuery) {
69-
elementToHighlight = document.querySelector(step.highlightElementQuery);
70-
if (elementToHighlight) {
71-
element.classList.add(containerHighlightClass);
72-
elementToHighlight.classList.add(highlightElementClass);
73-
}
74-
}
59+
const elementToHighlight = !!step.highlightElementQuery && document.querySelector(step.highlightElementQuery);
60+
if (elementToHighlight) {
61+
elementToHighlight.classList.add(highlightElementClass);
7562
}
7663
const titleSuffix = ` ${currentStepIndex + 1} / ${steps.length}`;
7764
const actionButtons = [
@@ -112,7 +99,6 @@ export const VisualTour = ({
11299
}
113100
return () => {
114101
// Remove previous element highlight
115-
document.querySelector(containerElementQuery)?.classList.remove(containerHighlightClass);
116102
document.querySelector(`.${highlightElementClass}`)?.classList.remove(highlightElementClass);
117103
};
118104
}, [currentStepIndex]);

src/components/VisualTour/stories/VisualTour.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const Template: StoryFn<typeof VisualTour> = (args: VisualTourProps) => {
5252
);
5353
};
5454

55+
// Randomly choose between English and German translation
5556
const stepDefinitions = Math.random() < 0.5 ? stepDefinitionsEn : stepDefinitionsDe;
5657

5758
export const Default = Template.bind({});
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
.#{$eccgui}-visual-tour__container {
2-
:not(.#{$eccgui}-visual-tour__highlighted-element) {
3-
z-index: 0;
4-
opacity: $eccgui-opacity-disabled;
5-
filter: grayscale(1);
6-
}
7-
8-
.#{$eccgui}-visual-tour__highlighted-element {
9-
background-color: orange;
10-
}
1+
.#{$eccgui}-visual-tour__highlighted-element {
2+
background-color: orange;
113
}

0 commit comments

Comments
 (0)