forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWizardStep.tsx
More file actions
72 lines (66 loc) · 2.45 KB
/
WizardStep.tsx
File metadata and controls
72 lines (66 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { useEffect } from 'react';
import { isWizardParentStep, WizardNavItemType } from './types';
import { WizardBodyProps } from './WizardBody';
import { useWizardContext } from './WizardContext';
import { WizardFooterProps } from './WizardFooter';
/**
* The primary child component for Wizard. Step props are used for the list of steps managed in context.
*/
export interface WizardStepProps {
/** Name of the step's navigation item */
name: React.ReactNode;
/** Unique identifier */
id: string | number;
/** Optional for when the step is used as a parent to sub-steps */
children?: React.ReactNode | undefined;
/** Props for WizardBody that wraps content by default. */
body?: Omit<Omit<WizardBodyProps, 'children'>, 'children'>;
/** Optional list of sub-steps */
steps?: React.ReactElement<WizardStepProps>[];
/** Flag to disable the step's navigation item */
isDisabled?: boolean;
/** Flag to determine whether the step is hidden */
isHidden?: boolean;
/** Replaces the step's navigation item or its properties. */
navItem?: WizardNavItemType;
/** Replaces the step's footer. The step's footer takes precedence over the wizard's footer. */
footer?: React.ReactElement<any> | Partial<WizardFooterProps>;
/** Used to determine icon next to the step's navigation item */
status?: 'default' | 'error' | 'success' | 'warning';
/** Flag to determine whether parent steps can expand or not. Defaults to false. */
isExpandable?: boolean;
}
export const WizardStep = ({ children, steps: _subSteps, ...props }: WizardStepProps) => {
const { activeStep, setStep } = useWizardContext();
const { id, name, body, isDisabled, isHidden, navItem, footer, status } = props;
const isParentStep = isWizardParentStep(activeStep);
// Update step in context when props change or when the step is active has yet to be marked as visited.
useEffect(() => {
setStep({
id,
name,
...(body && { body }),
...(isDisabled && { isDisabled }),
...(isHidden && { isHidden }),
...(navItem && { navItem }),
...(footer && { footer }),
...(status && { status }),
...(!isParentStep && id === activeStep?.id && !activeStep?.isVisited && { isVisited: true })
});
}, [
body,
footer,
id,
isDisabled,
isHidden,
name,
navItem,
status,
isParentStep,
setStep,
activeStep?.id,
activeStep?.isVisited
]);
return <>{children}</>;
};
WizardStep.displayName = 'WizardStep';