1
1
import React , { Children , isValidElement } from 'react' ;
2
2
3
3
import { Direction } from '@leafygreen-ui/descendants' ;
4
- import { findChild } from '@leafygreen-ui/lib' ;
4
+ import { findChild , findChildren } from '@leafygreen-ui/lib' ;
5
5
6
6
import { useWizardControlledValue } from '../utils/useWizardControlledValue/useWizardControlledValue' ;
7
7
import { WizardContext } from '../WizardContext/WizardContext' ;
@@ -24,14 +24,11 @@ export function Wizard({
24
24
setValue : setActiveStep ,
25
25
} = useWizardControlledValue < number > ( activeStepProp , undefined , 0 ) ;
26
26
27
- const stepChildren = Children . toArray ( children ) . filter ( child => {
28
- if ( isValidElement ( child ) ) {
29
- const displayName = ( child . type as any ) ?. displayName ;
30
- return displayName && displayName . includes ( 'Step' ) ;
31
- }
32
-
33
- return false ;
34
- } ) ;
27
+ const stepChildren = findChildren (
28
+ children ,
29
+ WizardSubComponentProperties . Step ,
30
+ ) ;
31
+ const footerChild = findChild ( children , WizardSubComponentProperties . Footer ) ;
35
32
36
33
const updateStep = ( direction : Direction ) => {
37
34
const getNextStep = ( curr : number ) => {
@@ -50,8 +47,6 @@ export function Wizard({
50
47
onStepChange ?.( getNextStep ( activeStep ) ) ;
51
48
} ;
52
49
53
- const footerChild = findChild ( children , WizardSubComponentProperties . Footer ) ;
54
-
55
50
// Get the current step to render
56
51
const currentStep = stepChildren [ activeStep ] || null ;
57
52
@@ -64,7 +59,6 @@ export function Wizard({
64
59
>
65
60
< div className = { wizardContainerStyles } >
66
61
< div className = { stepContentStyles } > { currentStep } </ div >
67
- { /* Render footer */ }
68
62
{ footerChild }
69
63
</ div >
70
64
</ WizardContext . Provider >
0 commit comments