| 1 |
import { useRef, useState } from 'react'; |
| 2 |
import { |
| 3 |
Button, |
| 4 |
Content, |
| 5 |
Drawer, |
| 6 |
DrawerActions, |
| 7 |
DrawerCloseButton, |
| 8 |
DrawerContent, |
| 9 |
DrawerPanelContent, |
| 10 |
DrawerHead, |
| 11 |
Flex, |
| 12 |
Modal, |
| 13 |
ModalVariant, |
| 14 |
Wizard, |
| 15 |
WizardHeader, |
| 16 |
WizardStep |
| 17 |
} from '@patternfly/react-core'; |
| 18 |
|
| 19 |
export const WizardModalWithDrawerInfoStepDemo: React.FunctionComponent = () => { |
| 20 |
const [isDrawerExpanded, setIsDrawerExpanded] = useState(false); |
| 21 |
const drawerRef = useRef<HTMLSpanElement | null>(null); |
| 22 |
|
| 23 |
const onExpand = () => { |
| 24 |
if (drawerRef.current) { |
| 25 |
drawerRef.current.focus(); |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
const onOpenClick = () => { |
| 30 |
setIsDrawerExpanded(true); |
| 31 |
}; |
| 32 |
|
| 33 |
const onCloseClick = () => { |
| 34 |
setIsDrawerExpanded(false); |
| 35 |
}; |
| 36 |
|
| 37 |
const createStepContentWithDrawer = (stepName: string) => ( |
| 38 |
<Drawer isInline isExpanded={isDrawerExpanded} onExpand={onExpand}> |
| 39 |
<DrawerContent |
| 40 |
panelContent={ |
| 41 |
<DrawerPanelContent widths={{ default: 'width_33' }}> |
| 42 |
<DrawerHead> |
| 43 |
<span tabIndex={isDrawerExpanded ? 0 : -1} ref={drawerRef}> |
| 44 |
Drawer content: {stepName} |
| 45 |
</span> |
| 46 |
<DrawerActions> |
| 47 |
<DrawerCloseButton onClick={onCloseClick} /> |
| 48 |
</DrawerActions> |
| 49 |
</DrawerHead> |
| 50 |
</DrawerPanelContent> |
| 51 |
} |
| 52 |
> |
| 53 |
<Flex |
| 54 |
className="pf-v6-c-wizard__main-body" |
| 55 |
direction={{ default: 'column' }} |
| 56 |
spaceItems={{ default: 'spaceItemsLg' }} |
| 57 |
height="100%" |
| 58 |
> |
| 59 |
<Content> |
| 60 |
<h1>{stepName} content</h1> |
| 61 |
<p> |
| 62 |
Wizard description goes here. If you need more assistance,{' '} |
| 63 |
<Button isInline variant="link" onClick={onOpenClick}> |
| 64 |
see more information |
| 65 |
</Button>{' '} |
| 66 |
in the side drawer.{' '} |
| 67 |
</p> |
| 68 |
</Content> |
| 69 |
</Flex> |
| 70 |
</DrawerContent> |
| 71 |
</Drawer> |
| 72 |
); |
| 73 |
|
| 74 |
return ( |
| 75 |
<Modal |
| 76 |
isOpen |
| 77 |
variant={ModalVariant.large} |
| 78 |
showClose={false} |
| 79 |
hasNoBodyWrapper |
| 80 |
aria-describedby="wiz-modal-demo-description" |
| 81 |
aria-labelledby="wiz-modal-demo-title" |
| 82 |
> |
| 83 |
<Wizard |
| 84 |
header={ |
| 85 |
<WizardHeader |
| 86 |
closeButtonAriaLabel="Close wizard" |
| 87 |
title="Wizard in modal with drawer and info step" |
| 88 |
titleId="wiz-modal-demo-title" |
| 89 |
description="Simple wizard description" |
| 90 |
descriptionId="wiz-modal-demo-description" |
| 91 |
/> |
| 92 |
} |
| 93 |
> |
| 94 |
<WizardStep body={{ hasNoPadding: true }} name="Information" id="wizard-step-1"> |
| 95 |
{createStepContentWithDrawer('Information step')} |
| 96 |
</WizardStep> |
| 97 |
<WizardStep |
| 98 |
name="Configuration" |
| 99 |
id="wizard-step-2" |
| 100 |
steps={[ |
| 101 |
<WizardStep body={{ hasNoPadding: true }} name="Substep A" id="wizard-step-2a" key="wizard-step-2a"> |
| 102 |
{createStepContentWithDrawer('Configuration substep A')} |
| 103 |
</WizardStep>, |
| 104 |
<WizardStep body={{ hasNoPadding: true }} name="Substep B" id="wizard-step-2b" key="wizard-step-2b"> |
| 105 |
{createStepContentWithDrawer('Configuration substep B')} |
| 106 |
</WizardStep> |
| 107 |
]} |
| 108 |
/> |
| 109 |
<WizardStep body={{ hasNoPadding: true }} name="Additional" id="wizard-step-3"> |
| 110 |
{createStepContentWithDrawer('Additional step')} |
| 111 |
</WizardStep> |
| 112 |
<WizardStep |
| 113 |
body={{ hasNoPadding: true }} |
| 114 |
name="Review" |
| 115 |
id="wizard-step-4" |
| 116 |
footer={{ nextButtonText: 'Finish' }} |
| 117 |
> |
| 118 |
{createStepContentWithDrawer('Review step')} |
| 119 |
</WizardStep> |
| 120 |
</Wizard> |
| 121 |
</Modal> |
| 122 |
); |
| 123 |
}; |