@@ -28,11 +28,12 @@ const STEPS = [
28
28
anchor : '.ugb-modal-design-library__enable-background' ,
29
29
position : 'right' ,
30
30
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' ,
36
37
// showNext: false,
37
38
} ,
38
39
{
@@ -96,6 +97,7 @@ const ModalTour = props => {
96
97
showNext = true , // If true, a "Next" button will be shown.
97
98
nextEventTarget = null , // If provided, this is a selector for the element to trigger the next event if there is one.
98
99
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.
99
101
} = steps [ currentStep ]
100
102
101
103
// Create a stable function reference for the event listener
@@ -112,7 +114,7 @@ const ModalTour = props => {
112
114
setIsVisible ( true )
113
115
setTimeout ( ( ) => {
114
116
setIsVisibleDelayed ( true )
115
- } , 30 )
117
+ } , 50 )
116
118
} , 1000 )
117
119
118
120
return ( ) => clearTimeout ( timer )
@@ -152,16 +154,16 @@ const ModalTour = props => {
152
154
switch ( position ) {
153
155
case 'left' :
154
156
// 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` ]
156
158
case 'right' :
157
159
// 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` ]
159
161
case 'top' :
160
162
// 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` ]
162
164
case 'bottom' :
163
165
// 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` ]
165
167
case 'center' :
166
168
return [
167
169
`${ anchorRect . left + ( anchorRect . width / 2 ) - ( modalRect . width / 2 ) } px` ,
@@ -172,6 +174,33 @@ const ModalTour = props => {
172
174
}
173
175
} , [ anchor , position , modalRef . current , isVisible , isVisibleDelayed , forceRefresh ] )
174
176
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
+
175
204
if ( ! isVisible ) {
176
205
return null
177
206
}
@@ -272,7 +301,7 @@ const ModalTour = props => {
272
301
setCurrentStep ( currentStep + 1 )
273
302
setTimeout ( ( ) => {
274
303
setForceRefresh ( forceRefresh + 1 )
275
- } , 50 )
304
+ } , 100 )
276
305
}
277
306
} }
278
307
>
@@ -299,6 +328,10 @@ const Steps = props => {
299
328
// onClickStep = NOOP,
300
329
} = props
301
330
331
+ if ( numSteps === 1 ) {
332
+ return null
333
+ }
334
+
302
335
return (
303
336
< div className = "ugb-tour-modal__steps" >
304
337
{ Array . from ( { length : numSteps } ) . map ( ( _ , index ) => {
0 commit comments