@planningcenter/tapestry-react 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Badge/Badge.js +5 -1
- package/dist/cjs/Card/Card.js +5 -2
- package/dist/cjs/Combobox/Combobox.js +16 -43
- package/dist/cjs/Combobox/ComboboxInput.js +112 -146
- package/dist/cjs/Combobox/ComboboxItem.js +38 -53
- package/dist/cjs/Combobox/ComboboxItems.js +41 -58
- package/dist/cjs/Combobox/index.js +12 -0
- package/dist/cjs/DateField/DateField.js +109 -128
- package/dist/cjs/Field/Field.js +80 -106
- package/dist/cjs/Menu/Item.js +1 -0
- package/dist/cjs/Popover/utils.js +1 -0
- package/dist/cjs/SegmentedControl/SegmentedControl.js +89 -111
- package/dist/cjs/SegmentedTabs/SegmentedTabs.js +54 -84
- package/dist/cjs/Tabs/Tab.js +9 -6
- package/dist/cjs/Tabs/TabList.js +49 -64
- package/dist/cjs/Tabs/TabPanel.js +6 -2
- package/dist/cjs/Tabs/TabPanels.js +14 -27
- package/dist/cjs/Tabs/Tabs.js +72 -106
- package/dist/cjs/Tabs/index.js +12 -0
- package/dist/cjs/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/cjs/Tooltip/Tooltip.js +158 -182
- package/dist/cjs/Wizard/Wizard.js +143 -193
- package/dist/cjs/Wizard/index.js +3 -0
- package/dist/esm/Badge/Badge.js +5 -1
- package/dist/esm/Card/Card.js +5 -2
- package/dist/esm/Combobox/Combobox.js +18 -43
- package/dist/esm/Combobox/ComboboxInput.js +111 -149
- package/dist/esm/Combobox/ComboboxItem.js +38 -52
- package/dist/esm/Combobox/ComboboxItems.js +38 -56
- package/dist/esm/Combobox/index.js +8 -0
- package/dist/esm/DateField/DateField.js +106 -133
- package/dist/esm/Field/Field.js +76 -103
- package/dist/esm/Menu/Item.js +1 -0
- package/dist/esm/Popover/utils.js +1 -0
- package/dist/esm/SegmentedControl/SegmentedControl.js +90 -114
- package/dist/esm/SegmentedTabs/SegmentedTabs.js +51 -83
- package/dist/esm/Tabs/Tab.js +8 -6
- package/dist/esm/Tabs/TabList.js +49 -66
- package/dist/esm/Tabs/TabPanel.js +4 -2
- package/dist/esm/Tabs/TabPanels.js +14 -28
- package/dist/esm/Tabs/Tabs.js +76 -120
- package/dist/esm/Tabs/index.js +8 -0
- package/dist/esm/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/esm/Tooltip/Tooltip.js +154 -195
- package/dist/esm/Wizard/Wizard.js +144 -201
- package/dist/esm/Wizard/index.js +2 -0
- package/dist/types/Popover/utils.d.ts +3 -0
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/Badge/Badge.js +5 -0
- package/src/Card/Card.tsx +22 -1
- package/src/Combobox/Combobox.js +18 -32
- package/src/Combobox/Combobox.mdx +1 -0
- package/src/Combobox/Combobox.test.js +1 -1
- package/src/Combobox/ComboboxInput.js +111 -105
- package/src/Combobox/ComboboxItem.js +27 -27
- package/src/Combobox/ComboboxItems.js +38 -60
- package/src/Combobox/index.js +8 -0
- package/src/DateField/DateField.js +109 -105
- package/src/DateField/DateField.mdx +1 -0
- package/src/Field/Field.js +85 -93
- package/src/Field/Field.mdx +1 -0
- package/src/Menu/Heading.js +5 -1
- package/src/Menu/Heading.mdx +20 -0
- package/src/Menu/Item.js +13 -1
- package/src/Menu/Item.mdx +18 -0
- package/src/Menu/Menu.mdx +1 -0
- package/src/Popover/utils.ts +1 -0
- package/src/SegmentedControl/SegmentedControl.js +88 -92
- package/src/SegmentedControl/SegmentedControl.mdx +1 -0
- package/src/SegmentedTabs/SegmentedTabs.js +51 -71
- package/src/SegmentedTabs/SegmentedTabs.mdx +1 -0
- package/src/Tabs/Tab.js +3 -1
- package/src/Tabs/TabList.js +56 -62
- package/src/Tabs/TabPanel.js +2 -1
- package/src/Tabs/TabPanels.js +14 -15
- package/src/Tabs/Tabs.js +63 -84
- package/src/Tabs/Tabs.mdx +16 -17
- package/src/Tabs/index.js +8 -0
- package/src/ThemeProvider/ThemeProvider.tsx +1 -1
- package/src/Tooltip/Tooltip.js +142 -160
- package/src/Tooltip/Tooltip.mdx +1 -0
- package/src/Wizard/Wizard.js +141 -170
- package/src/Wizard/Wizard.mdx +3 -2
- package/src/Wizard/index.js +2 -0
package/src/Tooltip/Tooltip.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, {
|
|
2
|
+
import React, {
|
|
3
|
+
Children,
|
|
4
|
+
cloneElement,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useState,
|
|
7
|
+
useCallback,
|
|
8
|
+
useImperativeHandle,
|
|
9
|
+
useEffect,
|
|
10
|
+
} from 'react'
|
|
3
11
|
import mitt from 'mitt'
|
|
4
12
|
|
|
5
13
|
import Popover from '../Popover'
|
|
6
14
|
import { composeEvents, pageViewChange } from '../utils'
|
|
15
|
+
import { useThemeProps } from '../system'
|
|
7
16
|
|
|
8
17
|
export type Props = {
|
|
9
18
|
/**
|
|
@@ -96,191 +105,164 @@ function clearGlobalTimeout() {
|
|
|
96
105
|
clearTimeout(globalTimeoutId)
|
|
97
106
|
}
|
|
98
107
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
isMouseDown = false
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
closeTimeoutId = null
|
|
108
|
+
function Tooltip(props: Props, ref) {
|
|
109
|
+
const {
|
|
110
|
+
children,
|
|
111
|
+
openDelay = 500,
|
|
112
|
+
closeDelay = 300,
|
|
113
|
+
defaultOpen = false,
|
|
114
|
+
keepInView = true,
|
|
115
|
+
placement,
|
|
116
|
+
popoverProps,
|
|
117
|
+
renderTo,
|
|
118
|
+
title,
|
|
119
|
+
triggerOnFocus = true,
|
|
120
|
+
triggerOnHover = true,
|
|
121
|
+
...childProps
|
|
122
|
+
} = useThemeProps('tooltip', props)
|
|
123
|
+
|
|
124
|
+
let isPageInView = true
|
|
125
|
+
let isFocused = false
|
|
126
|
+
let isMouseDown = false
|
|
127
|
+
let openTimeoutId = null
|
|
128
|
+
let closeTimeoutId = null
|
|
122
129
|
|
|
123
130
|
// prevents tooltips showing when focused and navigating back to a page after leaving
|
|
124
|
-
cleanupPageViewChange =
|
|
125
|
-
setTimeout(() => (
|
|
131
|
+
const cleanupPageViewChange = useCallback(
|
|
132
|
+
pageViewChange((inView) => setTimeout(() => (isPageInView = inView)))
|
|
126
133
|
)
|
|
134
|
+
const [isPopoverOpen, setIsPopoverOpen] = useState(defaultOpen)
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
emitter.on('CLOSE_OPEN_TOOLTIPS', close)
|
|
138
|
+
return () => {
|
|
139
|
+
emitter.off('CLOSE_OPEN_TOOLTIPS', close)
|
|
140
|
+
clearTimeout(openTimeoutId)
|
|
141
|
+
clearTimeout(closeTimeoutId)
|
|
142
|
+
cleanupPageViewChange()
|
|
143
|
+
}
|
|
144
|
+
}, [])
|
|
127
145
|
|
|
128
|
-
|
|
129
|
-
|
|
146
|
+
const open = () => {
|
|
147
|
+
clearTimeout(closeTimeoutId)
|
|
148
|
+
closeTimeoutId = null
|
|
149
|
+
setIsPopoverOpen(true)
|
|
130
150
|
}
|
|
131
151
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
(lastProps.triggerOnHover !== this.props.triggerOnHover &&
|
|
137
|
-
this.triggerOnHover === false)
|
|
138
|
-
) {
|
|
139
|
-
this.close()
|
|
140
|
-
}
|
|
152
|
+
const close = () => {
|
|
153
|
+
clearTimeout(openTimeoutId)
|
|
154
|
+
openTimeoutId = null
|
|
155
|
+
setIsPopoverOpen(false)
|
|
141
156
|
}
|
|
142
157
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
clearTimeout(this.openTimeoutId)
|
|
146
|
-
clearTimeout(this.closeTimeoutId)
|
|
147
|
-
this.cleanupPageViewChange()
|
|
158
|
+
const toggle = () => {
|
|
159
|
+
setIsPopoverOpen(!isPopoverOpen)
|
|
148
160
|
}
|
|
149
161
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
useImperativeHandle(ref, () => ({
|
|
163
|
+
open,
|
|
164
|
+
close,
|
|
165
|
+
toggle,
|
|
166
|
+
}))
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (triggerOnFocus === false) {
|
|
170
|
+
close()
|
|
153
171
|
}
|
|
154
|
-
}
|
|
172
|
+
}, [triggerOnFocus])
|
|
155
173
|
|
|
156
|
-
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
if (triggerOnHover === false) {
|
|
176
|
+
close()
|
|
177
|
+
}
|
|
178
|
+
}, [triggerOnHover])
|
|
179
|
+
|
|
180
|
+
const createOpenTimeout = useCallback(() => {
|
|
157
181
|
clearGlobalTimeout()
|
|
158
|
-
if (
|
|
159
|
-
clearTimeout(
|
|
160
|
-
|
|
161
|
-
if (
|
|
182
|
+
if (openTimeoutId === null) {
|
|
183
|
+
clearTimeout(closeTimeoutId)
|
|
184
|
+
closeTimeoutId = null
|
|
185
|
+
if (isPopoverOpen === false) {
|
|
162
186
|
emitter.emit('CLOSE_OPEN_TOOLTIPS')
|
|
163
|
-
|
|
164
|
-
() => this.open(),
|
|
165
|
-
instantDelay ? 0 : this.props.openDelay
|
|
166
|
-
)
|
|
187
|
+
openTimeoutId = setTimeout(() => open(), instantDelay ? 0 : openDelay)
|
|
167
188
|
}
|
|
168
189
|
}
|
|
169
|
-
}
|
|
190
|
+
})
|
|
170
191
|
|
|
171
|
-
createCloseTimeout = () => {
|
|
192
|
+
const createCloseTimeout = useCallback(() => {
|
|
172
193
|
startGlobalTimeout()
|
|
173
|
-
if (
|
|
174
|
-
clearTimeout(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
},
|
|
194
|
+
if (closeTimeoutId === null) {
|
|
195
|
+
clearTimeout(openTimeoutId)
|
|
196
|
+
openTimeoutId = null
|
|
197
|
+
closeTimeoutId = setTimeout(() => {
|
|
198
|
+
close()
|
|
199
|
+
}, closeDelay)
|
|
179
200
|
}
|
|
180
|
-
}
|
|
201
|
+
})
|
|
181
202
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
this.setState({ isPopoverOpen: true })
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
close = () => {
|
|
189
|
-
clearTimeout(this.openTimeoutId)
|
|
190
|
-
this.openTimeoutId = null
|
|
191
|
-
this.setState({ isPopoverOpen: false })
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
toggle = () => {
|
|
195
|
-
this.setState((state) => ({ isPopoverOpen: !state.isPopoverOpen }))
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
handleFocus = () => {
|
|
199
|
-
if (this.isPageInView && !this.isMouseDown) {
|
|
200
|
-
this.open()
|
|
203
|
+
const handleFocus = useCallback(() => {
|
|
204
|
+
if (isPageInView && !isMouseDown) {
|
|
205
|
+
open()
|
|
201
206
|
}
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
const handleMouseDown = useCallback(() => {
|
|
210
|
+
isMouseDown = true
|
|
211
|
+
close()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
const handleMouseUp = useCallback(() => {
|
|
215
|
+
isMouseDown = false
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
const child = Children.only(children)
|
|
219
|
+
const {
|
|
220
|
+
onFocus,
|
|
221
|
+
onBlur,
|
|
222
|
+
onMouseEnter,
|
|
223
|
+
onMouseLeave,
|
|
224
|
+
onMouseDown,
|
|
225
|
+
onMouseUp,
|
|
226
|
+
} = child.props
|
|
227
|
+
|
|
228
|
+
if (!title) {
|
|
229
|
+
return cloneElement(child, childProps)
|
|
202
230
|
}
|
|
203
231
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
232
|
+
if (triggerOnFocus) {
|
|
233
|
+
childProps.onFocus = composeEvents(handleFocus, onFocus)
|
|
234
|
+
childProps.onBlur = composeEvents(close, onBlur)
|
|
235
|
+
childProps.onMouseDown = composeEvents(handleMouseDown, onMouseDown)
|
|
236
|
+
childProps.onMouseUp = composeEvents(handleMouseUp, onMouseUp)
|
|
207
237
|
}
|
|
208
238
|
|
|
209
|
-
|
|
210
|
-
|
|
239
|
+
if (triggerOnHover) {
|
|
240
|
+
childProps.onMouseEnter = composeEvents(createOpenTimeout, onMouseEnter)
|
|
241
|
+
childProps.onMouseLeave = composeEvents(createCloseTimeout, onMouseLeave)
|
|
211
242
|
}
|
|
212
243
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
onMouseDown,
|
|
236
|
-
onMouseUp,
|
|
237
|
-
} = child.props
|
|
238
|
-
|
|
239
|
-
if (!title) {
|
|
240
|
-
return cloneElement(child, childProps)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (triggerOnFocus) {
|
|
244
|
-
childProps.onFocus = composeEvents(this.handleFocus, onFocus)
|
|
245
|
-
childProps.onBlur = composeEvents(this.close, onBlur)
|
|
246
|
-
childProps.onMouseDown = composeEvents(this.handleMouseDown, onMouseDown)
|
|
247
|
-
childProps.onMouseUp = composeEvents(this.handleMouseUp, onMouseUp)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (triggerOnHover) {
|
|
251
|
-
childProps.onMouseEnter = composeEvents(
|
|
252
|
-
this.createOpenTimeout,
|
|
253
|
-
onMouseEnter
|
|
254
|
-
)
|
|
255
|
-
childProps.onMouseLeave = composeEvents(
|
|
256
|
-
this.createCloseTimeout,
|
|
257
|
-
onMouseLeave
|
|
258
|
-
)
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return (
|
|
262
|
-
<Popover
|
|
263
|
-
shouldFlip
|
|
264
|
-
paddingHorizontal={0.75}
|
|
265
|
-
paddingVertical={0.25}
|
|
266
|
-
fontSize={5}
|
|
267
|
-
textAlign="center"
|
|
268
|
-
radius={2}
|
|
269
|
-
backgroundColor="grey-9"
|
|
270
|
-
color="rgba(255,255,255,0.94)"
|
|
271
|
-
zIndex={9999}
|
|
272
|
-
{...popoverProps}
|
|
273
|
-
anchorElement={cloneElement(child, childProps)}
|
|
274
|
-
onMouseEnter={this.createOpenTimeout}
|
|
275
|
-
onMouseLeave={this.createCloseTimeout}
|
|
276
|
-
keepInView={keepInView}
|
|
277
|
-
placement={placement}
|
|
278
|
-
renderTo={renderTo}
|
|
279
|
-
children={title}
|
|
280
|
-
open={isPopoverOpen}
|
|
281
|
-
/>
|
|
282
|
-
)
|
|
283
|
-
}
|
|
244
|
+
return (
|
|
245
|
+
<Popover
|
|
246
|
+
shouldFlip
|
|
247
|
+
paddingHorizontal={0.75}
|
|
248
|
+
paddingVertical={0.25}
|
|
249
|
+
fontSize={5}
|
|
250
|
+
textAlign="center"
|
|
251
|
+
radius={2}
|
|
252
|
+
backgroundColor="grey-9"
|
|
253
|
+
color="rgba(255,255,255,0.94)"
|
|
254
|
+
zIndex={9999}
|
|
255
|
+
{...popoverProps}
|
|
256
|
+
anchorElement={cloneElement(child, childProps)}
|
|
257
|
+
onMouseEnter={createOpenTimeout}
|
|
258
|
+
onMouseLeave={createCloseTimeout}
|
|
259
|
+
keepInView={keepInView}
|
|
260
|
+
placement={placement}
|
|
261
|
+
renderTo={renderTo}
|
|
262
|
+
children={title}
|
|
263
|
+
open={isPopoverOpen}
|
|
264
|
+
/>
|
|
265
|
+
)
|
|
284
266
|
}
|
|
285
|
-
|
|
267
|
+
Tooltip = forwardRef(Tooltip)
|
|
286
268
|
export default Tooltip
|
package/src/Tooltip/Tooltip.mdx
CHANGED
package/src/Wizard/Wizard.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, { Children,
|
|
2
|
+
import React, { Children, useCallback, useReducer, useState } from 'react'
|
|
3
3
|
|
|
4
4
|
import Button from '../Button'
|
|
5
5
|
import Card from '../Card'
|
|
@@ -8,8 +8,8 @@ import StackView from '../StackView'
|
|
|
8
8
|
import PagerView from '../PagerView'
|
|
9
9
|
import StepperProgress from '../StepperProgress'
|
|
10
10
|
import Text from '../Text'
|
|
11
|
+
import { useThemeProps } from '../system'
|
|
11
12
|
|
|
12
|
-
import Step from './Step'
|
|
13
13
|
import WizardContext from './WizardContext'
|
|
14
14
|
|
|
15
15
|
export type Props = {
|
|
@@ -73,181 +73,152 @@ export type Props = {
|
|
|
73
73
|
}) => null,
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
function Wizard(props: Props) {
|
|
77
|
+
const {
|
|
78
|
+
autoFocus = true,
|
|
79
|
+
backButtonProps,
|
|
80
|
+
buttonProps,
|
|
81
|
+
cancelButtonProps,
|
|
82
|
+
children,
|
|
83
|
+
footerProps,
|
|
84
|
+
initialPayload = {},
|
|
85
|
+
nextButtonProps,
|
|
86
|
+
nextButtonTitle = ({ activeStepIndex, steps, totalSteps }) =>
|
|
83
87
|
activeStepIndex >= totalSteps - 1 ? 'Finish' : 'Next',
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const nextSteps = getSteps(state.steps)
|
|
109
|
-
return {
|
|
110
|
-
steps: nextSteps,
|
|
111
|
-
totalSteps: nextSteps.length,
|
|
88
|
+
onCancel,
|
|
89
|
+
onSubmit,
|
|
90
|
+
renderProgress,
|
|
91
|
+
...restProps
|
|
92
|
+
} = useThemeProps('wizard', props)
|
|
93
|
+
const [activeStepIndex, setActiveStepIndex] = useState(0)
|
|
94
|
+
const [steps, setSteps] = useState([])
|
|
95
|
+
const [sendingPayload, setSendingPayload] = useState(false)
|
|
96
|
+
const totalSteps = steps.length
|
|
97
|
+
const [payload, setPayload] = useReducer(
|
|
98
|
+
(prevState, updatedProperty) => ({
|
|
99
|
+
...prevState,
|
|
100
|
+
...updatedProperty,
|
|
101
|
+
}),
|
|
102
|
+
initialPayload
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const addStep = useCallback(
|
|
106
|
+
(step) => {
|
|
107
|
+
setSteps((steps) => [...steps, step])
|
|
108
|
+
return () => {
|
|
109
|
+
setSteps((steps) =>
|
|
110
|
+
steps.filter((previousStep) => previousStep.name !== step.name)
|
|
111
|
+
)
|
|
112
112
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (this.props.onSubmit) {
|
|
133
|
-
const complete = () => this.setState({ sendingPayload: false })
|
|
134
|
-
this.setState({ sendingPayload: true })
|
|
135
|
-
this.props.onSubmit(this.state.payload, complete)
|
|
113
|
+
},
|
|
114
|
+
[steps]
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
const isCurrentStepValid = useCallback(
|
|
118
|
+
function () {
|
|
119
|
+
const currentStep = steps[activeStepIndex]
|
|
120
|
+
return currentStep && currentStep.valid
|
|
121
|
+
? currentStep.valid(payload)
|
|
122
|
+
: true
|
|
123
|
+
},
|
|
124
|
+
[activeStepIndex, steps, payload]
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
const handleSubmit = useCallback(() => {
|
|
128
|
+
if (onSubmit) {
|
|
129
|
+
const complete = () => setSendingPayload(false)
|
|
130
|
+
setSendingPayload(true)
|
|
131
|
+
onSubmit(payload, complete)
|
|
136
132
|
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
<StackView
|
|
167
|
-
alignment="center"
|
|
168
|
-
minWidth={48}
|
|
169
|
-
maxWidth={96}
|
|
170
|
-
{...restProps}
|
|
171
|
-
>
|
|
172
|
-
{renderProgress ? (
|
|
173
|
-
renderProgress({ activeStepIndex, steps, totalSteps })
|
|
174
|
-
) : (
|
|
175
|
-
<StepperProgress
|
|
176
|
-
width="80%"
|
|
177
|
-
paddingTop={6}
|
|
178
|
-
paddingBottom={4}
|
|
179
|
-
activeStepIndex={activeStepIndex}
|
|
180
|
-
>
|
|
181
|
-
{steps.map((step, index) => (
|
|
182
|
-
<StepperProgress.Step
|
|
183
|
-
key={index}
|
|
184
|
-
renderEnd={
|
|
185
|
-
<Text align="center" marginTop={2}>
|
|
186
|
-
{step.name}
|
|
187
|
-
</Text>
|
|
188
|
-
}
|
|
189
|
-
/>
|
|
190
|
-
))}
|
|
191
|
-
</StepperProgress>
|
|
192
|
-
)}
|
|
193
|
-
<Card spacing={<Divider />} elevation={1}>
|
|
194
|
-
<PagerView activeViewIndex={activeStepIndex} autoFocus={autoFocus}>
|
|
195
|
-
{Children.map(children, (child, index) => (
|
|
196
|
-
<PagerView.View key={index}>{child}</PagerView.View>
|
|
197
|
-
))}
|
|
198
|
-
</PagerView>
|
|
199
|
-
<StackView
|
|
200
|
-
axis="horizontal"
|
|
201
|
-
distribution={activeStepIndex > 0 ? 'space-between' : 'end'}
|
|
202
|
-
padding={1}
|
|
203
|
-
spacing={1}
|
|
204
|
-
{...footerProps}
|
|
205
|
-
>
|
|
206
|
-
{activeStepIndex === 0 && onCancel && (
|
|
207
|
-
<Button
|
|
208
|
-
disabled={sendingPayload}
|
|
209
|
-
onClick={onCancel}
|
|
210
|
-
size="lg"
|
|
211
|
-
title="Cancel"
|
|
212
|
-
variant="naked"
|
|
213
|
-
{...buttonProps}
|
|
214
|
-
{...cancelButtonProps}
|
|
215
|
-
/>
|
|
216
|
-
)}
|
|
217
|
-
{activeStepIndex > 0 && (
|
|
218
|
-
<Button
|
|
219
|
-
disabled={sendingPayload}
|
|
220
|
-
iconLeft={{ name: 'general.leftChevron', size: 'sm' }}
|
|
221
|
-
onClick={() =>
|
|
222
|
-
this.setState({ activeStepIndex: activeStepIndex - 1 })
|
|
223
|
-
}
|
|
224
|
-
size="lg"
|
|
225
|
-
title="Back"
|
|
226
|
-
variant="naked"
|
|
227
|
-
{...buttonProps}
|
|
228
|
-
{...backButtonProps}
|
|
229
|
-
/>
|
|
230
|
-
)}
|
|
231
|
-
<Button
|
|
232
|
-
disabled={!this.isCurrentStepValid()}
|
|
233
|
-
onClick={() =>
|
|
234
|
-
activeStepIndex >= totalSteps - 1
|
|
235
|
-
? this.handleSubmit()
|
|
236
|
-
: this.setState({ activeStepIndex: activeStepIndex + 1 })
|
|
133
|
+
}, [payload])
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<WizardContext.Provider
|
|
137
|
+
value={{
|
|
138
|
+
activeStepIndex,
|
|
139
|
+
addStep,
|
|
140
|
+
setPayload,
|
|
141
|
+
payload,
|
|
142
|
+
totalSteps,
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
<StackView alignment="center" minWidth={48} maxWidth={96} {...restProps}>
|
|
146
|
+
{renderProgress ? (
|
|
147
|
+
renderProgress({ activeStepIndex, steps, totalSteps })
|
|
148
|
+
) : (
|
|
149
|
+
<StepperProgress
|
|
150
|
+
width="80%"
|
|
151
|
+
paddingTop={6}
|
|
152
|
+
paddingBottom={4}
|
|
153
|
+
activeStepIndex={activeStepIndex}
|
|
154
|
+
>
|
|
155
|
+
{steps.map((step, index) => (
|
|
156
|
+
<StepperProgress.Step
|
|
157
|
+
key={index}
|
|
158
|
+
renderEnd={
|
|
159
|
+
<Text align="center" marginTop={2}>
|
|
160
|
+
{step.name}
|
|
161
|
+
</Text>
|
|
237
162
|
}
|
|
163
|
+
/>
|
|
164
|
+
))}
|
|
165
|
+
</StepperProgress>
|
|
166
|
+
)}
|
|
167
|
+
<Card spacing={<Divider />} elevation={1}>
|
|
168
|
+
<PagerView activeViewIndex={activeStepIndex} autoFocus={autoFocus}>
|
|
169
|
+
{Children.map(children, (child, index) => (
|
|
170
|
+
<PagerView.View key={index}>{child}</PagerView.View>
|
|
171
|
+
))}
|
|
172
|
+
</PagerView>
|
|
173
|
+
<StackView
|
|
174
|
+
axis="horizontal"
|
|
175
|
+
distribution={activeStepIndex > 0 ? 'space-between' : 'end'}
|
|
176
|
+
padding={1}
|
|
177
|
+
spacing={1}
|
|
178
|
+
{...footerProps}
|
|
179
|
+
>
|
|
180
|
+
{activeStepIndex === 0 && onCancel && (
|
|
181
|
+
<Button
|
|
182
|
+
disabled={sendingPayload}
|
|
183
|
+
onClick={onCancel}
|
|
184
|
+
size="lg"
|
|
185
|
+
title="Cancel"
|
|
186
|
+
variant="naked"
|
|
187
|
+
{...buttonProps}
|
|
188
|
+
{...cancelButtonProps}
|
|
189
|
+
/>
|
|
190
|
+
)}
|
|
191
|
+
{activeStepIndex > 0 && (
|
|
192
|
+
<Button
|
|
193
|
+
disabled={sendingPayload}
|
|
194
|
+
iconLeft={{ name: 'general.leftChevron', size: 'sm' }}
|
|
195
|
+
onClick={() => setActiveStepIndex(activeStepIndex - 1)}
|
|
238
196
|
size="lg"
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
title={nextButtonTitle({ activeStepIndex, steps, totalSteps })}
|
|
197
|
+
title="Back"
|
|
198
|
+
variant="naked"
|
|
242
199
|
{...buttonProps}
|
|
243
|
-
{...
|
|
200
|
+
{...backButtonProps}
|
|
244
201
|
/>
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
202
|
+
)}
|
|
203
|
+
<Button
|
|
204
|
+
disabled={!isCurrentStepValid()}
|
|
205
|
+
onClick={() =>
|
|
206
|
+
activeStepIndex >= totalSteps - 1
|
|
207
|
+
? handleSubmit()
|
|
208
|
+
: setActiveStepIndex(activeStepIndex + 1)
|
|
209
|
+
}
|
|
210
|
+
size="lg"
|
|
211
|
+
spinner={sendingPayload}
|
|
212
|
+
theme="primary"
|
|
213
|
+
title={nextButtonTitle({ activeStepIndex, steps, totalSteps })}
|
|
214
|
+
{...buttonProps}
|
|
215
|
+
{...nextButtonProps}
|
|
216
|
+
/>
|
|
217
|
+
</StackView>
|
|
218
|
+
</Card>
|
|
219
|
+
</StackView>
|
|
220
|
+
</WizardContext.Provider>
|
|
221
|
+
)
|
|
251
222
|
}
|
|
252
223
|
|
|
253
224
|
export default Wizard
|