Skip to content

Commit 344f138

Browse files
committed
Update documentation + Add some fixes
1 parent ea3e549 commit 344f138

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ steps: PropTypes.arrayOf(PropTypes.shape({
337337
'stepInteraction': PropTypes.bool,
338338
'navDotAriaLabel': PropTypes.string,
339339
'observe': PropTypes.string,
340+
'highlightedSelectors': PropTypes.array,
341+
'mutationObservables': PropTypes.array,
342+
'resizeObservables': PropTypes.array,
340343
})),
341344
```
342345
@@ -374,6 +377,19 @@ const steps = [
374377
// If a child is added: the highlighted region is redrawn focused on it
375378
// If a child is removed: the highlighted region is redrawn focused on the step selector node
376379
observe: '[data-tour="observable-parent"]',
380+
// Array of selectors, each selected node will be included (by union)
381+
// in the highlighted region of the mask. You don't need to add the
382+
// step selector here as the default highlighted region is focused on it
383+
highlightedSelectors: ['[data-tour="highlighted-element"]'],
384+
// Array of selectors, each selected node DOM addition/removal will triggered a rerender
385+
// of the mask shape. Useful in combinaison with highlightedSelectors when highlighted
386+
// region of mask should be redrawn after a user action
387+
mutationObservables: ['[data-tour="mutable-element"]'],
388+
// Array of selectors, each selected node resize will triggered a rerender of the mask shape.
389+
// Useful in combinaison with highlightedSelectors when highlighted region of mask should
390+
// be redrawn after a user action. You should also add the selector in mutationObservables
391+
// if you want to track DOM addition/removal too
392+
resizeObservables: ['[data-tour="resizable-parent"]'],
377393
},
378394
// ...
379395
]

src/components/MutationObserver.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export default ({ step, refresh }) => {
1717
)
1818

1919
if (found) {
20-
// hack to postpone execution in the event queue
21-
setTimeout(() => refresh(), 0)
20+
refresh()
2221
}
2322
}
2423
}
@@ -43,7 +42,7 @@ export default ({ step, refresh }) => {
4342
return () => {
4443
mutationObserver.disconnect()
4544
}
46-
}, [])
45+
}, [step])
4746

4847
return null
4948
}

src/components/ResizeObserver.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { useEffect, useState } from 'react'
33
export default ({ step, refresh }) => {
44
const [mutationsCounter, setMutationsCounter] = useState(0)
55

6+
// only use to notify main logic below
7+
// that a resizeObservable has been added to DOM (or removed from it)
68
useEffect(() => {
79
if (!step.resizeObservables) {
810
return
@@ -19,8 +21,7 @@ export default ({ step, refresh }) => {
1921
)
2022

2123
if (found) {
22-
// hack to postpone execution in the event queue
23-
setTimeout(() => setMutationsCounter(mutationsCounter + 1), 0)
24+
setMutationsCounter(mutationsCounter + 1)
2425
}
2526
}
2627
}
@@ -45,8 +46,9 @@ export default ({ step, refresh }) => {
4546
return () => {
4647
mutationObserver.disconnect()
4748
}
48-
}, [mutationsCounter])
49+
}, [step, mutationsCounter])
4950

51+
// the main logic is here
5052
useEffect(() => {
5153
if (!step.resizeObservables) {
5254
return
@@ -67,7 +69,7 @@ export default ({ step, refresh }) => {
6769
return () => {
6870
resizeObserver.disconnect()
6971
}
70-
}, [mutationsCounter])
72+
}, [step, mutationsCounter])
7173

7274
return null
7375
}

src/demo/App.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@ function MyCustomHelper({ current, content, totalSteps, gotoStep, close }) {
124124
}
125125

126126
const tourConfig = [
127-
{
128-
selector: '[data-tut="reactour__highlighted"]',
129-
content: 'Hello world',
130-
highlightedSelectors: ['[data-tut="reactour__highlighted-absolute-child"]'],
131-
mutationObservables: ['[data-tut="reactour__highlighted-absolute-child"]'],
132-
resizeObservables: ['[data-tut="reactour__highlighted-absolute-child"]'],
133-
},
134127
{
135128
selector: '[data-tut="reactour__iso"]',
136129
content:
@@ -253,6 +246,14 @@ const tourConfig = [
253246
observe: '[data-tut="reactour__state--observe"]',
254247
action: node => node.focus(),
255248
},
249+
{
250+
selector: '[data-tut="reactour__highlighted"]',
251+
content:
252+
'Moreover you can highlight multiple elements and adjust highlighted region depending on DOM resizes and mutations. Try clicking the "?" tooltip and playing with tabs...',
253+
highlightedSelectors: ['[data-tut="reactour__highlighted-absolute-child"]'],
254+
mutationObservables: ['[data-tut="reactour__highlighted-absolute-child"]'],
255+
resizeObservables: ['[data-tut="reactour__highlighted-absolute-child"]'],
256+
},
256257
]
257258

258259
export default App

0 commit comments

Comments
 (0)