Debian Codegraph @

node/@patternfly/react-core/src/components/Compass/Compass.tsx

raw
1 import { Drawer, DrawerContent, DrawerContentBody, DrawerProps } from '../Drawer';
2 import styles from '@patternfly/react-styles/css/components/Compass/compass';
3 import { css } from '@patternfly/react-styles';
4 export interface CompassProps extends React.HTMLProps<HTMLDivElement> {
5 /** Additional classes added to the Compass. */
6 className?: string;
7 /** The horizontal masthead content (e.g. <Masthead />). This masthead will only render when dock content is passed and only at mobile viewports. */
8 masthead?: React.ReactNode;
9 /** Content of the docked navigation area of the layout */
10 dock?: React.ReactNode;
11 /** @beta Flag indicating the docked nav is expanded on mobile. Only applies when dock content is passed. */
12 isDockExpanded?: boolean;
13 /** @beta Flag indicating the docked nav should display text on desktop. Only applies when dock content is passed, and
14 * will handle toggling the visibility of the text in individual isDocked components.
15 */
16 isDockTextExpanded?: boolean;
17 /** Content placed at the top of the compass layout */
18 header?: React.ReactNode;
19 /** Flag indicating if the header is expanded */
20 isHeaderExpanded?: boolean;
21 /** Content placed at the horizontal start of the layout, before the main content */
22 sidebarStart?: React.ReactNode;
23 /** Flag indicating if the start sidebar is expanded */
24 isSidebarStartExpanded?: boolean;
25 /** Content placed at the center of the layout */
26 main?: React.ReactNode;
27 /** Content placed at the horizontal end of the layout, after the main content */
28 sidebarEnd?: React.ReactNode;
29 /** Flag indicating if the end sidebar is expanded */
30 isSidebarEndExpanded?: boolean;
31 /** Content placed at the bottom of the layout */
32 footer?: React.ReactNode;
33 /** Flag indicating if the footer is expanded */
34 isFooterExpanded?: boolean;
35 /** Content rendered in an optional drawer wrapping the layout */
36 drawerContent?: React.ReactNode;
37 /** Additional props passed to the drawer */
38 drawerProps?: DrawerProps;
39 }
40
41 export const Compass: React.FunctionComponent<CompassProps> = ({
42 className,
43 masthead,
44 dock,
45 isDockExpanded,
46 isDockTextExpanded,
47 header,
48 isHeaderExpanded = true,
49 sidebarStart,
50 isSidebarStartExpanded = true,
51 main,
52 sidebarEnd,
53 isSidebarEndExpanded = true,
54 footer,
55 isFooterExpanded = true,
56 drawerContent,
57 drawerProps,
58 ...props
59 }: CompassProps) => {
60 const hasDrawer = drawerContent !== undefined;
61
62 const compassContent = (
63 <div className={css(styles.compassContainer)}>
64 {dock && masthead}
65 {dock && (
66 <div
67 className={css(
68 `${styles.compass}__dock`,
69 isDockExpanded && styles.modifiers.expanded,
70 isDockTextExpanded && styles.modifiers.textExpanded
71 )}
72 >
73 {dock}
74 </div>
75 )}
76 {header && (
77 <div
78 className={css(styles.compassHeader, isHeaderExpanded && 'pf-m-expanded')}
79 {...(!isHeaderExpanded && { inert: 'true' })}
80 >
81 {header}
82 </div>
83 )}
84 {sidebarStart && (
85 <div
86 className={css(styles.compassSidebar, styles.modifiers.start, isSidebarStartExpanded && 'pf-m-expanded')}
87 {...(!isSidebarStartExpanded && { inert: 'true' })}
88 >
89 {sidebarStart}
90 </div>
91 )}
92 {main && <div className={css(styles.compassMain)}>{main}</div>}
93 {sidebarEnd && (
94 <div
95 className={css(styles.compassSidebar, styles.modifiers.end, isSidebarEndExpanded && 'pf-m-expanded')}
96 {...(!isSidebarEndExpanded && { inert: 'true' })}
97 >
98 {sidebarEnd}
99 </div>
100 )}
101 {footer && (
102 <div
103 className={css(styles.compassFooter, isFooterExpanded && 'pf-m-expanded')}
104 {...(!isFooterExpanded && { inert: 'true' })}
105 >
106 {footer}
107 </div>
108 )}
109 </div>
110 );
111
112 return (
113 <div className={css(styles.compass, dock && styles.modifiers.docked, className)} {...props}>
114 {hasDrawer ? (
115 <Drawer isPill {...drawerProps}>
116 <DrawerContent panelContent={drawerContent}>
117 <DrawerContentBody>{compassContent}</DrawerContentBody>
118 </DrawerContent>
119 </Drawer>
120 ) : (
121 compassContent
122 )}
123 </div>
124 );
125 };
126
127 Compass.displayName = 'Compass';