@@ -28,11 +28,12 @@ const STEPS = [
2828 anchor : '.ugb-modal-design-library__enable-background' ,
2929 position : 'right' ,
3030 nextEventTarget : '.ugb-modal-design-library__enable-background' ,
31- ctaLabel : __ ( 'Enable Background' , i18n ) ,
32- ctaOnClick : ( ) => {
33- const element = document . querySelector ( '.ugb-modal-design-library__enable-background .components-form-toggle__input' )
34- element ?. click ( )
35- } ,
31+ // ctaLabel: __( 'Enable Background', i18n ),
32+ // ctaOnClick: () => {
33+ // const element = document.querySelector( '.ugb-modal-design-library__enable-background .components-form-toggle__input' )
34+ // element?.click()
35+ // },
36+ glowTarget : '.ugb-modal-design-library__enable-background' ,
3637 // showNext: false,
3738 } ,
3839 {
@@ -96,6 +97,7 @@ const ModalTour = props => {
9697 showNext = true , // If true, a "Next" button will be shown.
9798 nextEventTarget = null , // If provided, this is a selector for the element to trigger the next event if there is one.
9899 nextEvent = 'click' , // This is the event to listen for to trigger the next step.
100+ glowTarget = null , // If provided, this is a selector for the element to glow when the step is active.
99101 } = steps [ currentStep ]
100102
101103 // Create a stable function reference for the event listener
@@ -112,7 +114,7 @@ const ModalTour = props => {
112114 setIsVisible ( true )
113115 setTimeout ( ( ) => {
114116 setIsVisibleDelayed ( true )
115- } , 30 )
117+ } , 50 )
116118 } , 1000 )
117119
118120 return ( ) => clearTimeout ( timer )
@@ -152,16 +154,16 @@ const ModalTour = props => {
152154 switch ( position ) {
153155 case 'left' :
154156 // Left, middle
155- return [ `${ anchorRect . left - modalRect . width - 24 } px` , `${ anchorRect . top + ( anchorRect . height / 2 ) - ( modalRect . height / 2 ) } px` ]
157+ return [ `${ anchorRect . left - modalRect . width - 16 } px` , `${ anchorRect . top + ( anchorRect . height / 2 ) - ( modalRect . height / 2 ) } px` ]
156158 case 'right' :
157159 // Right, middle
158- return [ `${ anchorRect . right + 24 } px` , `${ anchorRect . top + ( anchorRect . height / 2 ) - ( modalRect . height / 2 ) } px` ]
160+ return [ `${ anchorRect . right + 16 } px` , `${ anchorRect . top + ( anchorRect . height / 2 ) - ( modalRect . height / 2 ) } px` ]
159161 case 'top' :
160162 // Center, top
161- return [ `${ anchorRect . left + ( anchorRect . width / 2 ) - ( modalRect . width / 2 ) } px` , `${ anchorRect . top - modalRect . height - 24 } px` ]
163+ return [ `${ anchorRect . left + ( anchorRect . width / 2 ) - ( modalRect . width / 2 ) } px` , `${ anchorRect . top - modalRect . height - 16 } px` ]
162164 case 'bottom' :
163165 // Center, bottom
164- return [ `${ anchorRect . left + ( anchorRect . width / 2 ) - ( modalRect . width / 2 ) } px` , `${ anchorRect . bottom + 24 } px` ]
166+ return [ `${ anchorRect . left + ( anchorRect . width / 2 ) - ( modalRect . width / 2 ) } px` , `${ anchorRect . bottom + 16 } px` ]
165167 case 'center' :
166168 return [
167169 `${ anchorRect . left + ( anchorRect . width / 2 ) - ( modalRect . width / 2 ) } px` ,
@@ -172,6 +174,33 @@ const ModalTour = props => {
172174 }
173175 } , [ anchor , position , modalRef . current , isVisible , isVisibleDelayed , forceRefresh ] )
174176
177+ // If we have a glow target, create a new element in the body, placed on the top of the target, below the modal.
178+ useEffect ( ( ) => {
179+ if ( glowTarget ) {
180+ // Get the top, left, width, and height of the target.
181+ const target = document . querySelector ( glowTarget )
182+ if ( target ) {
183+ const targetRect = target . getBoundingClientRect ( )
184+
185+ // Create the element.
186+ const element = document . createElement ( 'div' )
187+ element . className = 'ugb-tour-modal__glow'
188+ element . style . top = `${ targetRect . top - 8 } px`
189+ element . style . left = `${ targetRect . left - 8 } px`
190+ element . style . width = `${ targetRect . width + 16 } px`
191+ element . style . height = `${ targetRect . height + 16 } px`
192+ document . body . appendChild ( element )
193+ }
194+ }
195+ // Remove the element when the component unmounts or the step changes.
196+ return ( ) => {
197+ if ( glowTarget ) {
198+ const element = document . querySelector ( '.ugb-tour-modal__glow' )
199+ element ?. remove ( )
200+ }
201+ }
202+ } , [ glowTarget , currentStep , isVisible , isVisibleDelayed , forceRefresh ] )
203+
175204 if ( ! isVisible ) {
176205 return null
177206 }
@@ -272,7 +301,7 @@ const ModalTour = props => {
272301 setCurrentStep ( currentStep + 1 )
273302 setTimeout ( ( ) => {
274303 setForceRefresh ( forceRefresh + 1 )
275- } , 50 )
304+ } , 100 )
276305 }
277306 } }
278307 >
@@ -299,6 +328,10 @@ const Steps = props => {
299328 // onClickStep = NOOP,
300329 } = props
301330
331+ if ( numSteps === 1 ) {
332+ return null
333+ }
334+
302335 return (
303336 < div className = "ugb-tour-modal__steps" >
304337 { Array . from ( { length : numSteps } ) . map ( ( _ , index ) => {
0 commit comments