| 1 |
import { useRef, useState } from 'react'; |
| 2 |
import { |
| 3 |
Drawer, |
| 4 |
DrawerContent, |
| 5 |
DrawerPanelContent, |
| 6 |
DrawerColorVariant, |
| 7 |
DrawerHead, |
| 8 |
DrawerActions, |
| 9 |
DrawerCloseButton, |
| 10 |
Flex, |
| 11 |
Button, |
| 12 |
useWizardContext, |
| 13 |
Wizard, |
| 14 |
WizardStep |
| 15 |
} from '@patternfly/react-core'; |
| 16 |
import styles from '@patternfly/react-styles/css/components/Wizard/wizard'; |
| 17 |
|
| 18 |
const StepContentWithDrawer: React.FunctionComponent = () => { |
| 19 |
const [isDrawerExpanded, setIsDrawerExpanded] = useState(false); |
| 20 |
const { activeStep } = useWizardContext(); |
| 21 |
const drawerRef = useRef<HTMLSpanElement>(null); |
| 22 |
|
| 23 |
const onWizardExpand = () => drawerRef.current && drawerRef.current.focus(); |
| 24 |
|
| 25 |
return ( |
| 26 |
<Drawer isInline isExpanded={isDrawerExpanded} onExpand={onWizardExpand}> |
| 27 |
<DrawerContent |
| 28 |
panelContent={ |
| 29 |
<DrawerPanelContent widths={{ default: 'width_50' }} colorVariant={DrawerColorVariant.secondary}> |
| 30 |
<DrawerHead> |
| 31 |
<span tabIndex={isDrawerExpanded ? 0 : -1} ref={drawerRef}> |
| 32 |
Drawer content: <strong>{activeStep?.name}</strong> |
| 33 |
</span> |
| 34 |
<DrawerActions> |
| 35 |
<DrawerCloseButton onClick={() => setIsDrawerExpanded(false)} /> |
| 36 |
</DrawerActions> |
| 37 |
</DrawerHead> |
| 38 |
</DrawerPanelContent> |
| 39 |
} |
| 40 |
> |
| 41 |
<Flex |
| 42 |
className={styles.wizardMainBody} |
| 43 |
direction={{ default: 'column' }} |
| 44 |
spaceItems={{ default: 'spaceItemsLg' }} |
| 45 |
height="100%" |
| 46 |
> |
| 47 |
{!isDrawerExpanded && ( |
| 48 |
<Button isInline variant="link" onClick={() => setIsDrawerExpanded((prevExpanded) => !prevExpanded)}> |
| 49 |
Open drawer |
| 50 |
</Button> |
| 51 |
)} |
| 52 |
<div>{activeStep?.name} content</div> |
| 53 |
</Flex> |
| 54 |
</DrawerContent> |
| 55 |
</Drawer> |
| 56 |
); |
| 57 |
}; |
| 58 |
|
| 59 |
export const WizardStepDrawerContent: React.FunctionComponent = () => ( |
| 60 |
<Wizard height={400} title="With drawer wizard"> |
| 61 |
<WizardStep body={{ hasNoPadding: true }} name="Step 1" id="with-drawer-step-1"> |
| 62 |
<StepContentWithDrawer /> |
| 63 |
</WizardStep> |
| 64 |
<WizardStep |
| 65 |
name="Step 2" |
| 66 |
id="with-drawer-step-2" |
| 67 |
steps={[ |
| 68 |
<WizardStep |
| 69 |
body={{ hasNoPadding: true }} |
| 70 |
key="with-drawer-substep-1" |
| 71 |
name="Substep 1" |
| 72 |
id="with-drawer-substep-1" |
| 73 |
> |
| 74 |
<StepContentWithDrawer /> |
| 75 |
</WizardStep>, |
| 76 |
<WizardStep |
| 77 |
body={{ hasNoPadding: true }} |
| 78 |
key="with-drawer-substep-2" |
| 79 |
name="Substep 2" |
| 80 |
id="with-drawer-substep-2" |
| 81 |
> |
| 82 |
<StepContentWithDrawer /> |
| 83 |
</WizardStep> |
| 84 |
]} |
| 85 |
> |
| 86 |
<StepContentWithDrawer /> |
| 87 |
</WizardStep> |
| 88 |
<WizardStep name="Review" id="with-drawer-review-step" footer={{ nextButtonText: 'Finish' }}> |
| 89 |
Review step content |
| 90 |
</WizardStep> |
| 91 |
</Wizard> |
| 92 |
); |