Skip to content

Commit 7b18928

Browse files
component renamed and added main component
1 parent 799fb91 commit 7b18928

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed
File renamed without changes.
Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { i18n } from 'stackable'
1+
import {
2+
i18n,
3+
guidedTourStates, // TODO: This doesn't exist yet. The state should be loaded here from localize values, this should be an object with the tour ID as the key and the state as the value.
4+
} from 'stackable'
25
import classNames from 'classnames'
36

47
import {
@@ -41,6 +44,29 @@ const STEPS = [
4144

4245
const NOOP = () => {}
4346

47+
// The main tour component.
48+
const GuidedModalTour = props => {
49+
const {
50+
steps = STEPS,
51+
tourId = '', // This is the ID of the tour, this will be used to store the tour state in the database.
52+
} = props
53+
54+
// On mount, check if the tour has been completed, if so, don't show it.
55+
const [ isDone, setIsDone ] = useState( guidedTourStates?.[ tourId ] )
56+
57+
if ( isDone ) {
58+
return null
59+
}
60+
61+
return <ModalTour
62+
steps={ steps }
63+
onClose={ () => {
64+
// TODO: Save the tour state to the database that we finished it.
65+
setIsDone( true )
66+
} }
67+
/>
68+
}
69+
4470
const ModalTour = props => {
4571
const {
4672
steps = STEPS,
@@ -56,16 +82,16 @@ const ModalTour = props => {
5682
const {
5783
title,
5884
description,
59-
ctaLabel = null,
60-
ctaOnClick = NOOP,
61-
size = 'small',
85+
ctaLabel = null, // If provided, a button will be shown with this label.
86+
ctaOnClick = NOOP, // This will be called when the button is clicked, we will move to the next step after.
87+
size = 'small', // Size of the modal. Can be 'small', 'medium', 'large'.
6288
anchor = null, // This is a selector for the element to anchor the modal to. Defaults to middle of the screen.
6389
position = 'center', // This is the position to place the modal relative to the anchor. Can be 'left', 'right', 'top', 'bottom', 'center'.
64-
offsetX = 0,
65-
offsetY = 0,
66-
showNext = true,
67-
nextEvent = 'click',
68-
nextEventTarget = null, // This is a selector for the element to trigger the next event if there is one.
90+
offsetX = 0, // This is the X offset of the modal relative to the anchor.
91+
offsetY = 0, // This is the Y offset of the modal relative to the anchor.
92+
showNext = true, // If true, a "Next" button will be shown.
93+
nextEventTarget = null, // If provided, this is a selector for the element to trigger the next event if there is one.
94+
nextEvent = 'click', // This is the event to listen for to trigger the next step.
6995
} = steps[ currentStep ]
7096

7197
// Create a stable function reference for the event listener
@@ -234,8 +260,6 @@ const ModalTour = props => {
234260
)
235261
}
236262

237-
export default ModalTour
238-
239263
const Steps = props => {
240264
const {
241265
numSteps = 3,
@@ -262,3 +286,5 @@ const Steps = props => {
262286
</div>
263287
)
264288
}
289+
290+
export default GuidedModalTour

src/components/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export { default as AdminSelectSetting } from './admin-select-setting'
5656
export { default as TaxonomyControl } from './taxonomy-control'
5757
export { default as Tooltip } from './tooltip'
5858
export { default as BlockStyles } from './block-styles'
59-
export { default as ModalTour } from './modal-tour'
59+
export { default as GuidedModalTour } from './guided-modal-tour'
6060

6161
// V2 only Components, for deprecation
6262
export { default as BlockContainer } from './block-container'

src/components/modal-design-library/modal.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import BlockList from './block-list'
66
import Button from '../button'
77
// import AdvancedToolbarControl from '../advanced-toolbar-control'
88
import DesignLibraryList from '~stackable/components/design-library-list'
9-
import { ModalTour } from '~stackable/components'
9+
import { GuidedModalTour } from '~stackable/components'
1010
import { getDesigns, filterDesigns } from '~stackable/design-library'
1111

1212
/**
@@ -217,8 +217,7 @@ export const ModalDesignLibrary = props => {
217217
>
218218
<div className="ugb-modal-design-library__wrapper">
219219

220-
{ /* DEV NOTE: this is just a test */ }
221-
<ModalTour />
220+
<GuidedModalTour tourId="design-library-welcome" />
222221

223222
<aside className="ugb-modal-design-library__sidebar">
224223
<div className="ugb-modal-design-library__filters">

0 commit comments

Comments
 (0)