Debian Codegraph @

node/@patternfly/react-core/src/components/Wizard/WizardFooter.tsx

raw
1 import { css } from '@patternfly/react-styles';
2 import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
3
4 import { Button, ButtonVariant } from '../Button';
5 import { isCustomWizardFooter, WizardFooterButtonProps, WizardStepType } from './types';
6 import { ActionList, ActionListGroup, ActionListItem } from '../ActionList';
7 /**
8 * Hosts the standard structure of a footer with ties to the active step so that text for buttons can vary from step to step.
9 */
10
11 export interface WizardFooterProps extends React.HTMLProps<HTMLElement> {
12 /** The active step */
13 activeStep: WizardStepType;
14 /** Next button callback */
15 onNext: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>;
16 /** Back button callback */
17 onBack: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>;
18 /** Cancel link callback */
19 onClose: (event: React.MouseEvent<HTMLButtonElement>) => void;
20 /** Custom text for the Next button. The current step's nextButtonText takes precedence. */
21 nextButtonText?: React.ReactNode;
22 /** Custom text for the Back button */
23 backButtonText?: React.ReactNode;
24 /** Custom text for the Cancel link */
25 cancelButtonText?: React.ReactNode;
26 /** Flag to disable the next button */
27 isNextDisabled?: boolean;
28 /** Flag to disable the back button */
29 isBackDisabled?: boolean;
30 /** Flag to hide the back button */
31 isBackHidden?: boolean;
32 /** Flag to hide the cancel button */
33 isCancelHidden?: boolean;
34 /** Additional props for the Next button. */
35 nextButtonProps?: Omit<WizardFooterButtonProps, 'isDisabled' | 'type'>;
36 /** Additional props for the Back button. */
37 backButtonProps?: Omit<WizardFooterButtonProps, 'isDisabled'>;
38 /** Additional props for the Cancel button. */
39 cancelButtonProps?: WizardFooterButtonProps;
40 /** Additional classes spread to the wizard footer */
41 className?: string;
42 }
43
44 /**
45 * Applies default wizard footer styling any number of child elements.
46 */
47
48 interface WizardFooterWrapperProps extends React.HTMLProps<HTMLElement> {
49 children: React.ReactNode;
50 className?: string;
51 }
52
53 export const WizardFooterWrapper = ({ children, className, ...props }: WizardFooterWrapperProps) => (
54 <footer className={css(styles.wizardFooter, className)} {...props}>
55 {children}
56 </footer>
57 );
58
59 export const WizardFooter = ({ activeStep, ...internalProps }: WizardFooterProps) => {
60 const activeStepFooter = !isCustomWizardFooter(activeStep?.footer) && activeStep?.footer;
61 return <InternalWizardFooter {...internalProps} {...activeStepFooter} />;
62 };
63
64 const InternalWizardFooter = ({
65 onNext,
66 onBack,
67 onClose,
68 isNextDisabled,
69 isBackDisabled,
70 isBackHidden,
71 isCancelHidden,
72 nextButtonText = 'Next',
73 backButtonText = 'Back',
74 cancelButtonText = 'Cancel',
75 nextButtonProps,
76 backButtonProps,
77 cancelButtonProps,
78 className,
79 ...props
80 }: Omit<WizardFooterProps, 'activeStep'>) => (
81 <WizardFooterWrapper className={className} {...props}>
82 <ActionList>
83 <ActionListGroup>
84 {!isBackHidden && (
85 <ActionListItem>
86 <Button variant={ButtonVariant.secondary} onClick={onBack} isDisabled={isBackDisabled} {...backButtonProps}>
87 {backButtonText}
88 </Button>
89 </ActionListItem>
90 )}
91 <ActionListItem>
92 <Button
93 variant={ButtonVariant.primary}
94 type="submit"
95 onClick={onNext}
96 isDisabled={isNextDisabled}
97 {...nextButtonProps}
98 >
99 {nextButtonText}
100 </Button>
101 </ActionListItem>
102 </ActionListGroup>
103 {!isCancelHidden && (
104 <ActionListGroup>
105 <ActionListItem>
106 <Button variant={ButtonVariant.link} onClick={onClose} {...cancelButtonProps}>
107 {cancelButtonText}
108 </Button>
109 </ActionListItem>
110 </ActionListGroup>
111 )}
112 </ActionList>
113 </WizardFooterWrapper>
114 );
115
116 WizardFooterWrapper.displayName = 'WizardFooterWrapper';
117 WizardFooter.displayName = 'WizardFooter';