|
| 1 | +import { Drawer, DrawerContent, DrawerProps } from '../Drawer'; |
| 2 | +import { css } from '@patternfly/react-styles'; |
| 3 | + |
| 4 | +export interface CompassProps extends React.HTMLProps<HTMLDivElement> { |
| 5 | + /** Additional classes added to the compass. */ |
| 6 | + className?: string; |
| 7 | + /** Content placed at the top of the layout */ |
| 8 | + header?: React.ReactNode; |
| 9 | + /** Flag indicating if the header is expanded */ |
| 10 | + isHeaderExpanded?: boolean; |
| 11 | + /** Content placed at the start of the layout */ |
| 12 | + panelStart?: React.ReactNode; |
| 13 | + /** Flag indicating if the start panel is expanded */ |
| 14 | + isPanelStartExpanded?: boolean; |
| 15 | + /** Content placed at the center of the layout */ |
| 16 | + main?: React.ReactNode; |
| 17 | + /** Content placed at the end of the layout */ |
| 18 | + panelEnd?: React.ReactNode; |
| 19 | + /** Flag indicating if the end panel is expanded */ |
| 20 | + isPanelEndExpanded?: boolean; |
| 21 | + /** Content placed at the bottom of the layout */ |
| 22 | + footer?: React.ReactNode; |
| 23 | + /** Flag indicating if the footer is expanded */ |
| 24 | + isFooterExpanded?: boolean; |
| 25 | + /** Content rendered in the drawer panel */ |
| 26 | + drawerContent?: React.ReactNode; |
| 27 | + /** Props for the drawer */ |
| 28 | + drawerProps?: DrawerProps; |
| 29 | +} |
| 30 | + |
| 31 | +export const Compass: React.FunctionComponent<CompassProps> = ({ |
| 32 | + className, |
| 33 | + header, |
| 34 | + isHeaderExpanded = true, |
| 35 | + panelStart, |
| 36 | + isPanelStartExpanded = true, |
| 37 | + main, |
| 38 | + panelEnd, |
| 39 | + isPanelEndExpanded = true, |
| 40 | + footer, |
| 41 | + isFooterExpanded = true, |
| 42 | + drawerContent, |
| 43 | + drawerProps, |
| 44 | + ...props |
| 45 | +}) => { |
| 46 | + const hasDrawer = drawerContent !== undefined; |
| 47 | + |
| 48 | + const compassContent = ( |
| 49 | + <div className={css('pf-v6-c-compass', className)} {...props}> |
| 50 | + <div |
| 51 | + className={css('pf-v6-c-compass__header', isHeaderExpanded && 'pf-m-expanded')} |
| 52 | + {...(!isHeaderExpanded && { inert: true })} |
| 53 | + > |
| 54 | + {header} |
| 55 | + </div> |
| 56 | + <div |
| 57 | + className={css('pf-v6-c-compass__panel pf-m-start', isPanelStartExpanded && 'pf-m-expanded')} |
| 58 | + {...(!isPanelStartExpanded && { inert: true })} |
| 59 | + > |
| 60 | + {panelStart} |
| 61 | + </div> |
| 62 | + <div className={css('pf-v6-c-compass__main')}>{main}</div> |
| 63 | + <div |
| 64 | + className={css('pf-v6-c-compass__panel pf-m-end', isPanelEndExpanded && 'pf-m-expanded')} |
| 65 | + {...(!isPanelEndExpanded && { inert: true })} |
| 66 | + > |
| 67 | + {panelEnd} |
| 68 | + </div> |
| 69 | + <div |
| 70 | + className={css('pf-v6-c-compass__footer', isFooterExpanded && 'pf-m-expanded')} |
| 71 | + {...(!isFooterExpanded && { inert: true })} |
| 72 | + > |
| 73 | + {footer} |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + ); |
| 77 | + |
| 78 | + if (hasDrawer) { |
| 79 | + return ( |
| 80 | + <Drawer {...drawerProps}> |
| 81 | + <DrawerContent panelContent={drawerContent}>{compassContent}</DrawerContent> |
| 82 | + </Drawer> |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + return compassContent; |
| 87 | +}; |
| 88 | + |
| 89 | +Compass.displayName = 'Compass'; |
0 commit comments