11import React from "react" ;
2+ import { createPortal } from "react-dom" ;
23import { createPopper } from "@popperjs/core" ;
34
45import { CLASSPREFIX as eccgui } from "../../configuration/constants" ;
6+ import Badge from "../Badge/Badge" ;
57import Button from "../Button/Button" ;
6- import { Card , CardActions , CardContent , CardHeader , CardOptions , CardTitle } from "../Card" ;
7- import { ModalSize , SimpleDialog } from "../Dialog" ;
8+ import { Card , CardActions , CardContent , CardHeader , CardOptions , CardTitle } from "../Card" ;
9+ import { ModalSize , SimpleDialog } from "../Dialog" ;
810import Spacing from "../Separation/Spacing" ;
9- import { TooltipSize } from "../Tooltip/Tooltip" ;
10- import Badge from "../Badge/Badge" ;
11- import { createPortal } from "react-dom" ;
12- import { Toolbar , ToolbarSection } from "../Toolbar" ;
11+ import { TooltipSize } from "../Tooltip/Tooltip" ;
1312
1413export interface VisualTourProps {
1514 /** The steps of the tour. */
@@ -66,14 +65,17 @@ export const VisualTour = ({
6665 const hasNextStep = currentStepIndex + 1 < steps . length ;
6766 const hasPreviousStep = currentStepIndex > 0 ;
6867 // Configure optional highlighting
69- let elementToHighlight : HTMLElement | null = null
70- if ( step . highlightElementQuery ) {
71- const queries : string [ ] = typeof step . highlightElementQuery === "string" ? [ step . highlightElementQuery ] : step . highlightElementQuery ;
72- queries . forEach ( query => {
73- if ( elementToHighlight == null ) {
74- elementToHighlight = document . querySelector ( query ) ;
75- }
76- } )
68+ let elementToHighlight : HTMLElement | null = null ;
69+ if ( step . highlightElementQuery ) {
70+ const queries : string [ ] =
71+ typeof step . highlightElementQuery === "string"
72+ ? [ step . highlightElementQuery ]
73+ : step . highlightElementQuery ;
74+ queries . forEach ( ( query ) => {
75+ if ( elementToHighlight == null ) {
76+ elementToHighlight = document . querySelector ( query ) ;
77+ }
78+ } ) ;
7779 }
7880 if ( elementToHighlight ) {
7981 // Typescript for some reason incorrectly infers the type of elementToHighlight as never
@@ -82,7 +84,9 @@ export const VisualTour = ({
8284 }
8385 const titleOption = < Badge intent = { "neutral" } > { ` ${ currentStepIndex + 1 } /${ steps . length } ` } </ Badge > ;
8486 const actionButtons = [
85- < Button key = { "close" } onClick = { onClose } > { closeLabel } </ Button > ,
87+ < Button key = { "close" } onClick = { onClose } >
88+ { closeLabel }
89+ </ Button > ,
8690 hasNextStep ? (
8791 < Button
8892 key = { "next" }
@@ -141,8 +145,8 @@ interface StepModalProps {
141145
142146// Main content of a step
143147const StepContent = ( { step } : { step : VisualTourStep } ) => {
144- let width = "600"
145- switch ( step . size ) {
148+ let width = "600" ;
149+ switch ( step . size ) {
146150 case "large" :
147151 width = "800" ;
148152 break ;
@@ -212,31 +216,31 @@ const StepPopover = ({ highlightedElement, step, titleOption, actionButtons }: S
212216 [ highlightedElement ]
213217 ) ;
214218
215- return (
216- createPortal (
217- < div
218- className = { `${ eccgui } -tooltip__content` + ` ${ eccgui } -tooltip-- ${ step . size ?? "large" } ` + ` ${ eccgui } -visual-tour__tooltip` }
219- role = " tooltip"
220- ref = { tooltipRef }
221- >
222- < div id = "arrow" data-popper-arrow >
223- < span className = { ` ${ eccgui } -visual-tour__tooltip__arrow-shape` } />
224- </ div >
225- < Card >
226- < CardHeader >
227- < CardTitle > { step . title } </ CardTitle >
228- < CardOptions > { titleOption } </ CardOptions >
229- </ CardHeader >
230- < CardContent >
231- < StepContent step = { step } / >
232- </ CardContent >
233- < CardActions inverseDirection >
234- { actionButtons }
235- </ CardActions >
236- </ Card >
237- </ div > ,
238- document . body
239- )
219+ return createPortal (
220+ < div
221+ className = {
222+ `${ eccgui } -tooltip__content` +
223+ ` ${ eccgui } - tooltip-- ${ step . size ?? "large" } ` +
224+ ` ${ eccgui } -visual-tour__tooltip`
225+ }
226+ role = "tooltip"
227+ ref = { tooltipRef }
228+ >
229+ < div id = "arrow" data-popper-arrow >
230+ < span className = { ` ${ eccgui } -visual-tour__tooltip__arrow-shape` } / >
231+ </ div >
232+ < Card >
233+ < CardHeader >
234+ < CardTitle > { step . title } </ CardTitle >
235+ < CardOptions > { titleOption } </ CardOptions >
236+ </ CardHeader >
237+ < CardContent >
238+ < StepContent step = { step } />
239+ </ CardContent >
240+ < CardActions inverseDirection > { actionButtons } </ CardActions >
241+ </ Card >
242+ </ div > ,
243+ document . body
240244 ) ;
241245} ;
242246
0 commit comments