@planningcenter/tapestry-react 2.1.2 → 2.3.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.
Files changed (88) hide show
  1. package/dist/cjs/Badge/Badge.js +5 -1
  2. package/dist/cjs/Button/Button.js +6 -3
  3. package/dist/cjs/Card/Card.js +5 -2
  4. package/dist/cjs/Combobox/Combobox.js +16 -43
  5. package/dist/cjs/Combobox/ComboboxInput.js +112 -146
  6. package/dist/cjs/Combobox/ComboboxItem.js +38 -53
  7. package/dist/cjs/Combobox/ComboboxItems.js +41 -58
  8. package/dist/cjs/Combobox/index.js +12 -0
  9. package/dist/cjs/DateField/DateField.js +109 -128
  10. package/dist/cjs/Field/Field.js +80 -106
  11. package/dist/cjs/Menu/Item.js +1 -0
  12. package/dist/cjs/Popover/utils.js +1 -0
  13. package/dist/cjs/SegmentedControl/SegmentedControl.js +89 -111
  14. package/dist/cjs/SegmentedTabs/SegmentedTabs.js +54 -84
  15. package/dist/cjs/Tabs/Tab.js +9 -6
  16. package/dist/cjs/Tabs/TabList.js +49 -64
  17. package/dist/cjs/Tabs/TabPanel.js +6 -2
  18. package/dist/cjs/Tabs/TabPanels.js +14 -27
  19. package/dist/cjs/Tabs/Tabs.js +72 -106
  20. package/dist/cjs/Tabs/index.js +12 -0
  21. package/dist/cjs/ThemeProvider/ThemeProvider.js +1 -1
  22. package/dist/cjs/Tooltip/Tooltip.js +158 -182
  23. package/dist/cjs/Wizard/Wizard.js +143 -193
  24. package/dist/cjs/Wizard/index.js +3 -0
  25. package/dist/esm/Badge/Badge.js +5 -1
  26. package/dist/esm/Button/Button.js +6 -3
  27. package/dist/esm/Card/Card.js +5 -2
  28. package/dist/esm/Combobox/Combobox.js +18 -43
  29. package/dist/esm/Combobox/ComboboxInput.js +111 -149
  30. package/dist/esm/Combobox/ComboboxItem.js +38 -52
  31. package/dist/esm/Combobox/ComboboxItems.js +38 -56
  32. package/dist/esm/Combobox/index.js +8 -0
  33. package/dist/esm/DateField/DateField.js +106 -133
  34. package/dist/esm/Field/Field.js +76 -103
  35. package/dist/esm/Menu/Item.js +1 -0
  36. package/dist/esm/Popover/utils.js +1 -0
  37. package/dist/esm/SegmentedControl/SegmentedControl.js +90 -114
  38. package/dist/esm/SegmentedTabs/SegmentedTabs.js +51 -83
  39. package/dist/esm/Tabs/Tab.js +8 -6
  40. package/dist/esm/Tabs/TabList.js +49 -66
  41. package/dist/esm/Tabs/TabPanel.js +4 -2
  42. package/dist/esm/Tabs/TabPanels.js +14 -28
  43. package/dist/esm/Tabs/Tabs.js +76 -120
  44. package/dist/esm/Tabs/index.js +8 -0
  45. package/dist/esm/ThemeProvider/ThemeProvider.js +1 -1
  46. package/dist/esm/Tooltip/Tooltip.js +154 -195
  47. package/dist/esm/Wizard/Wizard.js +144 -201
  48. package/dist/esm/Wizard/index.js +2 -0
  49. package/dist/types/Popover/utils.d.ts +3 -0
  50. package/package.json +1 -1
  51. package/src/.DS_Store +0 -0
  52. package/src/Badge/Badge.js +5 -0
  53. package/src/Button/Button.tsx +6 -3
  54. package/src/Card/Card.tsx +22 -1
  55. package/src/Combobox/Combobox.js +18 -32
  56. package/src/Combobox/Combobox.mdx +1 -0
  57. package/src/Combobox/Combobox.test.js +1 -1
  58. package/src/Combobox/ComboboxInput.js +111 -105
  59. package/src/Combobox/ComboboxItem.js +27 -27
  60. package/src/Combobox/ComboboxItems.js +38 -60
  61. package/src/Combobox/index.js +8 -0
  62. package/src/DateField/DateField.js +109 -105
  63. package/src/DateField/DateField.mdx +1 -0
  64. package/src/Field/Field.js +85 -93
  65. package/src/Field/Field.mdx +1 -0
  66. package/src/Menu/Heading.js +5 -1
  67. package/src/Menu/Heading.mdx +20 -0
  68. package/src/Menu/Item.js +13 -1
  69. package/src/Menu/Item.mdx +18 -0
  70. package/src/Menu/Menu.mdx +1 -0
  71. package/src/Popover/utils.ts +1 -0
  72. package/src/SegmentedControl/SegmentedControl.js +88 -92
  73. package/src/SegmentedControl/SegmentedControl.mdx +1 -0
  74. package/src/SegmentedTabs/SegmentedTabs.js +51 -71
  75. package/src/SegmentedTabs/SegmentedTabs.mdx +1 -0
  76. package/src/Tabs/Tab.js +3 -1
  77. package/src/Tabs/TabList.js +56 -62
  78. package/src/Tabs/TabPanel.js +2 -1
  79. package/src/Tabs/TabPanels.js +14 -15
  80. package/src/Tabs/Tabs.js +63 -84
  81. package/src/Tabs/Tabs.mdx +16 -17
  82. package/src/Tabs/index.js +8 -0
  83. package/src/ThemeProvider/ThemeProvider.tsx +1 -1
  84. package/src/Tooltip/Tooltip.js +142 -160
  85. package/src/Tooltip/Tooltip.mdx +1 -0
  86. package/src/Wizard/Wizard.js +141 -170
  87. package/src/Wizard/Wizard.mdx +3 -2
  88. package/src/Wizard/index.js +2 -0
@@ -1,9 +1,18 @@
1
1
  // @flow
2
- import React, { Component, Children, cloneElement } from '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
- class Tooltip extends Component<Props> {
100
- static defaultProps = {
101
- openDelay: 500,
102
- closeDelay: 300,
103
- keepInView: true,
104
- triggerOnFocus: true,
105
- triggerOnHover: true,
106
- defaultOpen: false,
107
- }
108
-
109
- state = {
110
- isPopoverOpen: this.props.defaultOpen,
111
- }
112
-
113
- isPageInView = true
114
-
115
- isFocused = false
116
-
117
- isMouseDown = false
118
-
119
- openTimeoutId = null
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 = pageViewChange((inView) =>
125
- setTimeout(() => (this.isPageInView = inView))
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
- componentDidMount() {
129
- emitter.on('CLOSE_OPEN_TOOLTIPS', this.handleCloseOpenTooltips)
146
+ const open = () => {
147
+ clearTimeout(closeTimeoutId)
148
+ closeTimeoutId = null
149
+ setIsPopoverOpen(true)
130
150
  }
131
151
 
132
- componentDidUpdate(lastProps) {
133
- if (
134
- (lastProps.triggerOnFocus !== this.props.triggerOnFocus &&
135
- this.props.triggerOnFocus === false) ||
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
- componentWillUnmount() {
144
- emitter.off('CLOSE_OPEN_TOOLTIPS', this.handleCloseOpenTooltips)
145
- clearTimeout(this.openTimeoutId)
146
- clearTimeout(this.closeTimeoutId)
147
- this.cleanupPageViewChange()
158
+ const toggle = () => {
159
+ setIsPopoverOpen(!isPopoverOpen)
148
160
  }
149
161
 
150
- handleCloseOpenTooltips = (instance) => {
151
- if (this !== instance) {
152
- this.close()
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
- createOpenTimeout = () => {
174
+ useEffect(() => {
175
+ if (triggerOnHover === false) {
176
+ close()
177
+ }
178
+ }, [triggerOnHover])
179
+
180
+ const createOpenTimeout = useCallback(() => {
157
181
  clearGlobalTimeout()
158
- if (this.openTimeoutId === null) {
159
- clearTimeout(this.closeTimeoutId)
160
- this.closeTimeoutId = null
161
- if (this.state.isPopoverOpen === false) {
182
+ if (openTimeoutId === null) {
183
+ clearTimeout(closeTimeoutId)
184
+ closeTimeoutId = null
185
+ if (isPopoverOpen === false) {
162
186
  emitter.emit('CLOSE_OPEN_TOOLTIPS')
163
- this.openTimeoutId = setTimeout(
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 (this.closeTimeoutId === null) {
174
- clearTimeout(this.openTimeoutId)
175
- this.openTimeoutId = null
176
- this.closeTimeoutId = setTimeout(() => {
177
- this.close()
178
- }, this.props.closeDelay)
194
+ if (closeTimeoutId === null) {
195
+ clearTimeout(openTimeoutId)
196
+ openTimeoutId = null
197
+ closeTimeoutId = setTimeout(() => {
198
+ close()
199
+ }, closeDelay)
179
200
  }
180
- }
201
+ })
181
202
 
182
- open = () => {
183
- clearTimeout(this.closeTimeoutId)
184
- this.closeTimeoutId = null
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
- handleMouseDown = () => {
205
- this.isMouseDown = true
206
- this.close()
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
- handleMouseUp = () => {
210
- this.isMouseDown = false
239
+ if (triggerOnHover) {
240
+ childProps.onMouseEnter = composeEvents(createOpenTimeout, onMouseEnter)
241
+ childProps.onMouseLeave = composeEvents(createCloseTimeout, onMouseLeave)
211
242
  }
212
243
 
213
- render() {
214
- const {
215
- children,
216
- openDelay,
217
- closeDelay,
218
- defaultOpen,
219
- keepInView,
220
- placement,
221
- popoverProps,
222
- renderTo,
223
- title,
224
- triggerOnFocus,
225
- triggerOnHover,
226
- ...childProps
227
- } = this.props
228
- const { isPopoverOpen } = this.state
229
- const child = Children.only(children)
230
- const {
231
- onFocus,
232
- onBlur,
233
- onMouseEnter,
234
- onMouseLeave,
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
@@ -3,6 +3,7 @@ title: Tooltip
3
3
  category: Overlays
4
4
  summary: Used to display a minimal amount of helpful information.
5
5
  propsSummary: Accepts [Popover](/popover) props.
6
+ themeKey: tooltip
6
7
  ---
7
8
 
8
9
  ```jsx live
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import React, { Children, Component } from 'react'
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
- class Wizard extends Component<Props> {
77
- static Step = Step
78
-
79
- static defaultProps = {
80
- autoFocus: true,
81
- initialPayload: {},
82
- nextButtonTitle: ({ activeStepIndex, steps, totalSteps }) =>
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
- state = {
87
- activeStepIndex: 0,
88
- payload: this.props.initialPayload,
89
- steps: [],
90
- totalSteps: -1,
91
- sendingPayload: false,
92
- }
93
-
94
- setPayload = (newPayload, cb) => {
95
- this.setState(
96
- (state) => ({
97
- payload: {
98
- ...state.payload,
99
- ...newPayload,
100
- },
101
- }),
102
- cb
103
- )
104
- }
105
-
106
- setSteps = (getSteps) => {
107
- this.setState((state) => {
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
- addStep = (step) => {
117
- this.setSteps((steps) => [...steps, step])
118
- return () => {
119
- this.setSteps((steps) =>
120
- steps.filter((previousStep) => previousStep.name !== step.name)
121
- )
122
- }
123
- }
124
-
125
- isCurrentStepValid() {
126
- const { activeStepIndex, payload, steps } = this.state
127
- const currentStep = steps[activeStepIndex]
128
- return currentStep && currentStep.valid ? currentStep.valid(payload) : true
129
- }
130
-
131
- handleSubmit = () => {
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
- render() {
140
- const {
141
- autoFocus,
142
- backButtonProps,
143
- buttonProps,
144
- cancelButtonProps,
145
- children,
146
- footerProps,
147
- initialPayload,
148
- nextButtonProps,
149
- nextButtonTitle,
150
- onCancel,
151
- onSubmit,
152
- renderProgress,
153
- ...restProps
154
- } = this.props
155
- const { activeStepIndex, sendingPayload, steps, totalSteps } = this.state
156
- return (
157
- <WizardContext.Provider
158
- value={{
159
- activeStepIndex: this.state.activeStepIndex,
160
- addStep: this.addStep,
161
- setPayload: this.setPayload,
162
- payload: this.state.payload,
163
- totalSteps: this.state.totalSteps,
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
- spinner={sendingPayload}
240
- theme="primary"
241
- title={nextButtonTitle({ activeStepIndex, steps, totalSteps })}
197
+ title="Back"
198
+ variant="naked"
242
199
  {...buttonProps}
243
- {...nextButtonProps}
200
+ {...backButtonProps}
244
201
  />
245
- </StackView>
246
- </Card>
247
- </StackView>
248
- </WizardContext.Provider>
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